Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/supported-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ These are the supported libraries and frameworks:
| [PowerJob](http://www.powerjob.tech/) | 4.0.0+ | N/A | none |
| [Quarkus Resteasy Reactive](https://quarkus.io/extensions/io.quarkus/quarkus-resteasy-reactive/) | 2.16.7+ | N/A | Provides `http.route` [2] |
| [Quartz](https://www.quartz-scheduler.org/) | 2.0+ | [opentelemetry-quartz-2.0](../instrumentation/quartz-2.0/library) | none |
| [R2DBC](https://r2dbc.io/) | 1.0+ | [opentelemetry-r2dbc-1.0](../instrumentation/r2dbc-1.0/library) | [Database Client Spans], [Database Client Metrics] [6] |
| [R2DBC](https://r2dbc.io/) | 0.9+ | [opentelemetry-r2dbc-1.0](../instrumentation/r2dbc-1.0/library) | [Database Client Spans], [Database Client Metrics] [6] |
Comment thread
trask marked this conversation as resolved.
Outdated
| [RabbitMQ Client](https://github.com/rabbitmq/rabbitmq-java-client) | 2.7+ | N/A | [Messaging Spans] |
| [Ratpack](https://github.com/ratpack/ratpack) | 1.4+ | [opentelemetry-ratpack-1.7](../instrumentation/ratpack/ratpack-1.7/library) | [HTTP Client Spans], [HTTP Client Metrics], [HTTP Server Spans], [HTTP Server Metrics] |
| [Reactor](https://github.com/reactor/reactor-core) | 3.1+ | [opentelemetry-reactor-3.1](../instrumentation/reactor/reactor-3.1/library) | Context propagation |
Expand Down
26 changes: 24 additions & 2 deletions instrumentation/r2dbc-1.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,48 @@ sourceSets {
}

dependencies {
library("io.r2dbc:r2dbc-spi:0.9.0.RELEASE")
library("io.r2dbc:r2dbc-spi:1.0.0.RELEASE")
Comment thread
trask marked this conversation as resolved.
compileOnly(project(path = ":instrumentation:r2dbc-1.0:library-instrumentation-shaded", configuration = "shadow"))

testImplementation(project(":instrumentation:r2dbc-1.0:testing"))
testInstrumentation(project(":instrumentation:reactor:reactor-3.1:javaagent"))
}

testing {
suites {
register<JvmTestSuite>("testSpi09") {
sources {
java {
setSrcDirs(
listOf(
"src/testSpi09/java",
project(":instrumentation:r2dbc-1.0:testing").file("src/testSpi09/java"),
)
)
}
}
dependencies {
implementation("io.r2dbc:r2dbc-h2:0.9.0.RELEASE")
}
}
}
}

tasks {
withType<Test>().configureEach {
named<Test>("test") {
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
}

val testPreviewSemconv = register<Test>("testPreviewSemconv") {
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
jvmArgs("-Dotel.semconv-stability.preview=service.peer")
systemProperty("metadataConfig", "otel.semconv-stability.preview=service.peer")
}

check {
dependsOn(testing.suites)
dependsOn(testPreviewSemconv)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.r2dbc.v1_0;

import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.junit.jupiter.api.extension.RegisterExtension;

class R2dbcSpi09Test extends AbstractR2dbcSpi09Test {

@RegisterExtension
private static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

@Override
protected InstrumentationExtension getTesting() {
return testing;
}

@Override
protected ConnectionFactory createProxyConnectionFactory(ConnectionFactoryOptions options) {
return ConnectionFactories.find(options);
}
}
2 changes: 1 addition & 1 deletion instrumentation/r2dbc-1.0/library/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Library Instrumentation for R2dbc version 1.0 and higher
# Library Instrumentation for R2dbc version 0.9 and higher
Comment thread
trask marked this conversation as resolved.
Outdated

Provides OpenTelemetry instrumentation for [R2dbc](https://r2dbc.io/).

Expand Down
36 changes: 33 additions & 3 deletions instrumentation/r2dbc-1.0/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,46 @@ plugins {
}

dependencies {
library("io.r2dbc:r2dbc-spi:0.9.0.RELEASE")
implementation("io.r2dbc:r2dbc-proxy")
library("io.r2dbc:r2dbc-spi:1.0.0.RELEASE")
implementation("io.r2dbc:r2dbc-proxy") {
exclude(group = "io.r2dbc", module = "r2dbc-spi")
}

testImplementation(project(":instrumentation:r2dbc-1.0:testing"))
testImplementation(project(":instrumentation:reactor:reactor-3.1:library"))
testImplementation("org.testcontainers:testcontainers")
}

testing {
suites {
register<JvmTestSuite>("testSpi09") {
sources {
java {
setSrcDirs(
listOf(
"src/testSpi09/java",
project(":instrumentation:r2dbc-1.0:testing").file("src/testSpi09/java"),
)
)
}
}
dependencies {
implementation(files(sourceSets.main.get().output))
implementation("io.r2dbc:r2dbc-h2:0.9.0.RELEASE")
implementation("io.r2dbc:r2dbc-proxy") {
exclude(group = "io.r2dbc", module = "r2dbc-spi")
}
implementation(project(":instrumentation:reactor:reactor-3.1:library"))
}
}
}
}

tasks {
withType<Test>().configureEach {
named<Test>("test") {
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
}
check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ private FilterAwareResult(

@Override
public Publisher<Long> getRowsUpdated() {
// The Publisher signature is erased; forward SPI 0.9 Integer and SPI 1.0 Long counts
// unchanged.
return delegate.getRowsUpdated();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.r2dbc.v1_0;

import io.opentelemetry.instrumentation.reactor.v3_1.ContextPropagationOperator;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.RegisterExtension;

class R2dbcSpi09Test extends AbstractR2dbcSpi09Test {

@RegisterExtension
private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();

private static final ContextPropagationOperator tracingOperator =
ContextPropagationOperator.create();

@BeforeAll
static void setup() {
tracingOperator.registerOnEachOperator();
}

@AfterAll
static void stop() {
tracingOperator.resetOnEachOperator();
}

@Override
protected InstrumentationExtension getTesting() {
return testing;
}

@Override
protected ConnectionFactory createProxyConnectionFactory(ConnectionFactoryOptions options) {
return R2dbcTelemetry.create(testing.getOpenTelemetry())
.wrapConnectionFactory(ConnectionFactories.find(options), options);
}
}
2 changes: 1 addition & 1 deletion instrumentation/r2dbc-1.0/testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
dependencies {
api("io.opentelemetry.javaagent:opentelemetry-testing-common")

implementation("io.r2dbc:r2dbc-spi:0.9.0.RELEASE")
implementation("io.r2dbc:r2dbc-spi:1.0.0.RELEASE")

implementation(project(":instrumentation-api-incubator"))
implementation("org.testcontainers:testcontainers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,123 @@ void filteredResultConsumptionFinishesQuerySpan() {
.hasParent(trace.getSpan(0))));
}

@Test
void mapFunctionConsumptionFinishesQuerySpan() {
ConnectionFactoryOptions options =
ConnectionFactoryOptions.parse("r2dbc:h2:mem:///map_function_" + UUID.randomUUID());
Connection connection =
Mono.from(createProxyConnectionFactory(options).create()).block(Duration.ofSeconds(10));
try {
getTesting()
.runWithSpan(
"parent",
() ->
assertThat(
Flux.from(
Mono.from(connection.createStatement("SELECT 42").execute())
.flatMapMany(
result ->
result.map(
readable -> readable.get(0, Integer.class))))
.single()
.block(Duration.ofSeconds(10)))
.isEqualTo(42));
} finally {
Mono.from(connection.close()).block(Duration.ofSeconds(10));
}

getTesting()
.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL),
span ->
span.hasName("SELECT")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))));
}

@Test
void plainUpdateResultConsumptionFinishesQuerySpan() {
ConnectionFactoryOptions options =
ConnectionFactoryOptions.parse("r2dbc:h2:mem:///plain_update_" + UUID.randomUUID());
Connection connection =
Mono.from(createProxyConnectionFactory(options).create()).block(Duration.ofSeconds(10));
try {
Flux.from(connection.createStatement("CREATE TABLE test (id INT)").execute())
.flatMap(result -> Flux.from(result.getRowsUpdated()))
.then()
.block(Duration.ofSeconds(10));
getTesting().waitForTraces(1);
getTesting().clearData();

getTesting()
.runWithSpan(
"parent",
() ->
assertThat(
Flux.from(
connection
.createStatement("INSERT INTO test VALUES (1)")
.execute())
.flatMap(result -> Flux.from(result.getRowsUpdated()))
.single()
.block(Duration.ofSeconds(10)))
.isEqualTo(1L));
} finally {
Mono.from(connection.close()).block(Duration.ofSeconds(10));
}

getTesting()
.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL),
span ->
span.hasName("INSERT test")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))));
}

@Test
void filteredUpdateResultConsumptionFinishesQuerySpan() {
Comment thread
trask marked this conversation as resolved.
Outdated
ConnectionFactoryOptions options =
ConnectionFactoryOptions.parse("r2dbc:h2:mem:///filtered_update_" + UUID.randomUUID());
Connection connection =
Mono.from(createProxyConnectionFactory(options).create()).block(Duration.ofSeconds(10));
try {
getTesting()
.runWithSpan(
"parent",
() ->
assertThat(
Flux.from(
connection
.createStatement("CREATE TABLE test (id INT)")
.execute())
.flatMap(
result ->
result
.filter(segment -> segment instanceof Result.UpdateCount)
.getRowsUpdated())
.collectList()
.block(Duration.ofSeconds(10)))
.containsExactly(0L));
} finally {
Mono.from(connection.close()).block(Duration.ofSeconds(10));
}

getTesting()
.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL),
span ->
span.hasName("CREATE TABLE test")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))));
}

private static Stream<Arguments> provideParameters() {
return systems.values().stream()
.flatMap(
Expand Down
Loading
Loading