From 516e4a7a585c4a860d83e069243e118ae8f4f63a Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 25 Nov 2026 11:54:33 +0100 Subject: [PATCH 1/3] fix(opentelemetry): Align GraphQL span operations Map OpenTelemetry spans carrying a GraphQL operation type to the graphql operation and retain their operation-level span name as the description. This aligns OpenTelemetry GraphQL spans with Sentry's GraphQL operation category without treating operation spans as native resolver-level spans. Refs #4547 Co-Authored-By: Claude --- .../SpanDescriptionExtractor.java | 11 +++++ .../kotlin/SpanDescriptionExtractorTest.kt | 43 +++++++++++++++++++ .../GraphqlIntegrationTest.kt | 6 +-- 3 files changed, 57 insertions(+), 3 deletions(-) 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 3af3d8f96f0..ef357b1f519 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 @@ -6,6 +6,7 @@ import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.UrlAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes; import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes; import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes; import io.sentry.SentryOptions; @@ -32,6 +33,12 @@ public final class SpanDescriptionExtractor { } } + final @Nullable String graphqlOperationType = + attributes.get(GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE); + if (graphqlOperationType != null) { + return descriptionForGraphqlOperation(otelSpan); + } + final @Nullable String httpMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD); if (httpMethod != null) { return descriptionForHttpMethod(otelSpan, httpMethod); @@ -49,6 +56,10 @@ public final class SpanDescriptionExtractor { return new OtelSpanInfo(name, description, TransactionNameSource.CUSTOM); } + private OtelSpanInfo descriptionForGraphqlOperation(final @NotNull SpanData otelSpan) { + return new OtelSpanInfo("graphql", otelSpan.getName(), TransactionNameSource.TASK); + } + @SuppressWarnings("deprecation") private OtelSpanInfo descriptionForHttpMethod( final @NotNull SpanData otelSpan, final @NotNull String httpMethod) { 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 4290b0cf7e3..71834f0a1f7 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/SpanDescriptionExtractorTest.kt +++ b/sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/SpanDescriptionExtractorTest.kt @@ -10,6 +10,7 @@ import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.HttpAttributes import io.opentelemetry.semconv.UrlAttributes import io.opentelemetry.semconv.incubating.DbIncubatingAttributes +import io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes import io.sentry.SentryOptions @@ -41,6 +42,48 @@ class SpanDescriptionExtractorTest { private val fixture = Fixture() + @Test + fun `sets op to graphql and preserves query span name as description`() { + givenSpanName("query GreetingQuery") + givenAttributes(mapOf(GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE to "query")) + + val info = whenExtractingSpanInfo() + + assertEquals("graphql", info.op) + assertEquals("query GreetingQuery", info.description) + assertEquals(TransactionNameSource.TASK, info.transactionNameSource) + } + + @Test + fun `sets op to graphql and preserves mutation span name as description`() { + givenSpanName("mutation AddProjectMutation") + givenAttributes(mapOf(GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE to "mutation")) + + val info = whenExtractingSpanInfo() + + assertEquals("graphql", info.op) + assertEquals("mutation AddProjectMutation", info.description) + assertEquals(TransactionNameSource.TASK, info.transactionNameSource) + } + + @Test + fun `graphql mapping wins over http when both attributes present`() { + givenSpanKind(SpanKind.CLIENT) + givenSpanName("query GreetingQuery") + givenAttributes( + mapOf( + GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE to "query", + HttpAttributes.HTTP_REQUEST_METHOD to "POST", + ), + ) + + val info = whenExtractingSpanInfo() + + assertEquals("graphql", info.op) + assertEquals("query GreetingQuery", info.description) + assertEquals(TransactionNameSource.TASK, info.transactionNameSource) + } + @Test fun `sets op to http server for kind SERVER`() { givenSpanKind(SpanKind.SERVER) diff --git a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/GraphqlIntegrationTest.kt b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/GraphqlIntegrationTest.kt index e881a8af4d0..b47a689e4f1 100644 --- a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/GraphqlIntegrationTest.kt +++ b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/GraphqlIntegrationTest.kt @@ -9,8 +9,8 @@ import io.sentry.test.transaction import kotlin.test.Test /** - * The agent traces each GraphQL operation as one span, with the operation's name as its op and - * description, so the queries are named. + * The agent traces each GraphQL operation as one span, using the GraphQL operation name as its + * description. */ class GraphqlIntegrationTest : IntegrationTest() { @@ -97,7 +97,7 @@ class GraphqlIntegrationTest : IntegrationTest() { .transaction()!! private fun SentryTransaction.hasOperationSpan(operation: String): Boolean = - hasSpanWithOpAndDescription(operation, operation) + hasSpanWithOpAndDescription("graphql", operation) /** Finds the error for [exceptionMessage], then the transaction it belongs to by trace ID. */ private fun awaitTransactionOfError(exceptionMessage: String): SentryTransaction { From b47807d4eb1eb3328abd1ec5c46873d1b55063a7 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 25 Nov 2026 12:54:43 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 512b8ff293d..f3be5bbd990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,6 +131,7 @@ ### Fixes +- OpenTelemetry: Group GraphQL operation spans under the `graphql` operation while retaining names such as `query GreetingQuery` as descriptions ([#6764](https://github.com/getsentry/sentry-java/pull/6764)) - Nav3: `sentry-android-navigation3` no longer declares a dependency on `androidx.lifecycle:lifecycle-runtime-compose`. Nav3 apps already depend on it via `navigation3-ui`, so no app changes are necessary ([#6699](https://github.com/getsentry/sentry-java/pull/6699)) - Profiling: No longer crash on API 35+ devices whose framework can't load `ProfilingManager`. Perfetto profiling is turned off on those devices instead ([#6742](https://github.com/getsentry/sentry-java/pull/6742)) - 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)) From 4ba0d43e46039175126bf57ac375327365542059 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 26 Nov 2026 10:01:13 +0100 Subject: [PATCH 3/3] changelog Co-Authored-By: Claude --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cb7ef6ac9a..ed9c2c6f3f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,7 +131,7 @@ ### Fixes -- OpenTelemetry: Group GraphQL operation spans under the `graphql` operation while retaining names such as `query GreetingQuery` as descriptions ([#6764](https://github.com/getsentry/sentry-java/pull/6764)) +- OpenTelemetry: Align GraphQL span operations and descriptions with Sentry instrumentation by grouping operation spans under `graphql` while retaining names such as `query GreetingQuery` as descriptions ([#6764](https://github.com/getsentry/sentry-java/pull/6764)) - 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))