Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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()

Expand All @@ -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"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class PersonIntegrationTest : IntegrationTest() {
assertThat(transaction.hasSpanWithOp("spanCreatedThroughSentryApi")).isTrue()
assertThat(
transaction.hasSpanWithOpAndDescription(
"db",
"db.query",
"insert into person (firstName, lastName) values (?, ?)",
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class PersonIntegrationTest : IntegrationTest() {
assertThat(transaction.hasSpanWithOp("spanCreatedThroughSentryApi")).isTrue()
assertThat(
transaction.hasSpanWithOpAndDescription(
"db",
"db.query",
"insert into person (firstName, lastName) values (?, ?)",
),
)
Expand Down
Loading