diff --git a/CHANGELOG.md b/CHANGELOG.md index 6753c06d4bd..639e2cfdf2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,6 +131,7 @@ ### Fixes +- OpenTelemetry: Align database span operations and descriptions with JDBC instrumentation by mapping query spans to `db.query`, preferring `db.query.text`, and recognizing `db.system.name` ([#6791](https://github.com/getsentry/sentry-java/pull/6791)) - Set Apollo 3, 4, and 5 HTTP spans to `CANCELLED` instead of `INTERNAL_ERROR` when the request is cancelled ([#6284](https://github.com/getsentry/sentry-java/pull/6284)) - Preserve independent Netty read and write timeout events when exception singletons are reused. These exceptions now bypass event deduplication by default, so applications with multiple capture integrations may report the same timeout more than once. Use `SentryOptions.setIgnoredErrorsForDeduplication(...)` or `ignored-errors-for-deduplication` to customize or clear the default exclusions. ([#6465](https://github.com/getsentry/sentry-java/pull/6465)) - Prevent changes to reused tracing options from affecting spans and transactions after creation ([#6417](https://github.com/getsentry/sentry-java/pull/6417)) diff --git a/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SpanDescriptionExtractor.java b/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SpanDescriptionExtractor.java index 6326dd2848a..e2fd3d58f93 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SpanDescriptionExtractor.java +++ b/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SpanDescriptionExtractor.java @@ -3,6 +3,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.semconv.DbAttributes; import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.UrlAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; @@ -33,8 +34,9 @@ public final class SpanDescriptionExtractor { return descriptionForHttpMethod(otelSpan, httpMethod); } - final @Nullable String dbSystem = attributes.get(DbIncubatingAttributes.DB_SYSTEM); - if (dbSystem != null) { + final @Nullable String dbSystemName = attributes.get(DbAttributes.DB_SYSTEM_NAME); + final @Nullable String legacyDbSystem = attributes.get(DbIncubatingAttributes.DB_SYSTEM); + if (dbSystemName != null || legacyDbSystem != null) { return descriptionForDbSystem(otelSpan); } @@ -149,13 +151,13 @@ private OtelSpanInfo descriptionForMessagingSystem(final @NotNull SpanData otelS @SuppressWarnings("deprecation") private OtelSpanInfo descriptionForDbSystem(final @NotNull SpanData otelSpan) { final @NotNull Attributes attributes = otelSpan.getAttributes(); - @Nullable String dbStatement = attributes.get(DbIncubatingAttributes.DB_STATEMENT); - if (dbStatement != null) { - return new OtelSpanInfo("db", dbStatement, TransactionNameSource.TASK); - } - @Nullable String dbQueryText = attributes.get(DbIncubatingAttributes.DB_QUERY_TEXT); + final @Nullable String dbQueryText = attributes.get(DbAttributes.DB_QUERY_TEXT); if (dbQueryText != null) { - return new OtelSpanInfo("db", dbQueryText, TransactionNameSource.TASK); + return new OtelSpanInfo("db.query", dbQueryText, TransactionNameSource.TASK); + } + final @Nullable String dbStatement = attributes.get(DbIncubatingAttributes.DB_STATEMENT); + if (dbStatement != null) { + return new OtelSpanInfo("db.query", dbStatement, TransactionNameSource.TASK); } return new OtelSpanInfo("db", otelSpan.getName(), TransactionNameSource.TASK); diff --git a/sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/SpanDescriptionExtractorTest.kt b/sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/SpanDescriptionExtractorTest.kt index db9a2d517c5..d3b8fb192ef 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/SpanDescriptionExtractorTest.kt +++ b/sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/SpanDescriptionExtractorTest.kt @@ -7,6 +7,7 @@ import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.TraceFlags import io.opentelemetry.api.trace.TraceState import io.opentelemetry.sdk.trace.data.SpanData +import io.opentelemetry.semconv.DbAttributes import io.opentelemetry.semconv.HttpAttributes import io.opentelemetry.semconv.UrlAttributes import io.opentelemetry.semconv.incubating.DbIncubatingAttributes @@ -176,23 +177,23 @@ class SpanDescriptionExtractorTest { } @Test - fun `sets op to db for span with db system and query text`() { + fun `sets op to db query for span with stable db attributes`() { givenAttributes( mapOf( - DbIncubatingAttributes.DB_SYSTEM to "some", - DbIncubatingAttributes.DB_QUERY_TEXT to "SELECT * FROM tbl", + DbAttributes.DB_SYSTEM_NAME to "some", + DbAttributes.DB_QUERY_TEXT to "SELECT * FROM tbl", ), ) val info = whenExtractingSpanInfo() - assertEquals("db", info.op) + assertEquals("db.query", info.op) assertEquals("SELECT * FROM tbl", info.description) assertEquals(TransactionNameSource.TASK, info.transactionNameSource) } @Test - fun `sets op to db for span with db system and statement`() { + fun `sets op to db query for span with legacy db attributes`() { givenAttributes( mapOf( DbIncubatingAttributes.DB_SYSTEM to "some", @@ -202,14 +203,31 @@ class SpanDescriptionExtractorTest { val info = whenExtractingSpanInfo() - assertEquals("db", info.op) + assertEquals("db.query", info.op) assertEquals("SELECT * FROM tbl", info.description) assertEquals(TransactionNameSource.TASK, info.transactionNameSource) } @Test - fun `sets op to db for span with db system`() { - givenAttributes(mapOf(DbIncubatingAttributes.DB_SYSTEM to "some")) + fun `prefers query text over legacy statement`() { + givenAttributes( + mapOf( + DbAttributes.DB_SYSTEM_NAME to "some", + DbAttributes.DB_QUERY_TEXT to "SELECT * FROM stable_table", + DbIncubatingAttributes.DB_STATEMENT to "SELECT * FROM legacy_table", + ), + ) + + val info = whenExtractingSpanInfo() + + assertEquals("db.query", info.op) + assertEquals("SELECT * FROM stable_table", info.description) + assertEquals(TransactionNameSource.TASK, info.transactionNameSource) + } + + @Test + fun `sets op to db for span with stable db system name`() { + givenAttributes(mapOf(DbAttributes.DB_SYSTEM_NAME to "some")) val info = whenExtractingSpanInfo() @@ -219,7 +237,7 @@ class SpanDescriptionExtractorTest { } @Test - fun `sets op to db for span with db system fallback to span name as description`() { + fun `sets op to db for span with legacy db system fallback to span name as description`() { givenSpanName("span name") givenAttributes(mapOf(DbIncubatingAttributes.DB_SYSTEM to "some")) diff --git a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt index dae928e4a9f..5dbbbe04ba3 100644 --- a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/PersonIntegrationTest.kt @@ -137,7 +137,7 @@ class PersonIntegrationTest : IntegrationTest() { assertThat(transaction.hasSpanWithOp("spanCreatedThroughSentryApi")).isTrue() assertThat( transaction.hasSpanWithOpAndDescription( - "db", + "db.query", "insert into person (firstName, lastName) values (?, ?)", ), ) diff --git a/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt b/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt index 2758ef86103..24995fcd9a3 100644 --- a/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTestOtelNoAgent/kotlin/io/sentry/spring/boot/otelnoagentintegrationtest/PersonIntegrationTest.kt @@ -136,7 +136,7 @@ class PersonIntegrationTest : IntegrationTest() { assertThat(transaction.hasSpanWithOp("spanCreatedThroughSentryApi")).isTrue() assertThat( transaction.hasSpanWithOpAndDescription( - "db", + "db.query", "insert into person (firstName, lastName) values (?, ?)", ), )