From 5d5b07fa4d0fa23cdf9d0f9dd0656aeeb93f965b Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Tue, 24 Nov 2026 10:56:08 +0100 Subject: [PATCH 1/3] fix(opentelemetry): Update GraphQL span naming property OpenTelemetry replaced the GraphQL option used to add operation names to span names. The deprecated property is ignored when the v3 semantic conventions preview is enabled, causing named operations such as GreetingQuery to be exported with a generic span name. Set the current property and run the GraphQL agent integration tests under the v3 preview to prevent a regression. Refs #4547 Co-Authored-By: Claude --- ...SentryAutoConfigurationCustomizerProvider.java | 4 ++-- .../boot/otelagentintegrationtest/AgentApp.kt | 8 ++++++-- .../GraphqlIntegrationTest.kt | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java index 42277f53c26..2706f89dc29 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java +++ b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java @@ -61,10 +61,10 @@ private static void ensureSentryOtelStorageIsInitialized() { private void customizeOpenTelemetryDefaults() { try { - if (System.getProperty("otel.instrumentation.graphql.add-operation-name-to-span-name.enabled") + if (System.getProperty("otel.instrumentation.graphql.operation-name-in-span-name.enabled") == null) { System.setProperty( - "otel.instrumentation.graphql.add-operation-name-to-span-name.enabled", "true"); + "otel.instrumentation.graphql.operation-name-in-span-name.enabled", "true"); } } catch (Exception e) { logger.log(Level.WARNING, "Unable to change OpenTelemetry defaults for use with Sentry.", e); diff --git a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/AgentApp.kt b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/AgentApp.kt index 9d63b216e73..0336a66b48b 100644 --- a/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/AgentApp.kt +++ b/sentry-spring-boot/src/integrationTestOtelAgent/kotlin/io/sentry/spring/boot/otelagentintegrationtest/AgentApp.kt @@ -14,14 +14,18 @@ import org.springframework.boot.web.client.RestTemplateBuilder * The test task decides what initializes Sentry: the agent or, with `SENTRY_AUTO_INIT=false`, the * Spring Boot starter. */ -class AgentApp(args: List = emptyList()) : Closeable { +class AgentApp( + args: List = emptyList(), + additionalJvmArgs: List = emptyList(), +) : Closeable { val server = MockSentryServer() private val app = ChildJvmApp.start( mainClass = "io.sentry.spring.boot.agentfixture.AgentFixtureApplicationKt", classpath = requiredTestProperty("sentry.test.appClasspath"), - jvmArgs = listOf("-javaagent:${requiredTestProperty("sentry.test.agentJar")}"), + jvmArgs = + listOf("-javaagent:${requiredTestProperty("sentry.test.agentJar")}") + additionalJvmArgs, // Environment variables, because the agent doesn't read Spring Boot's properties. env = mapOf( 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..9dbf9fad2e3 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 @@ -10,10 +10,14 @@ 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. + * description, so the queries are named. The tests enable the OpenTelemetry v3 preview, where the + * deprecated operation-name configuration property is ignored. */ class GraphqlIntegrationTest : IntegrationTest() { + override val app: AgentApp + get() = v3PreviewApp + @Test fun `query is traced`() { val response = graphql("""query GreetingQuery { greeting(name: "world") }""") @@ -115,4 +119,13 @@ class GraphqlIntegrationTest : IntegrationTest() { .awaitEnvelope { it.transaction()?.contexts?.trace?.traceId == traceId } .transaction()!! } + + companion object { + private val v3PreviewApp: AgentApp by lazy { + AgentApp(additionalJvmArgs = listOf("-Dotel.instrumentation.common.v3-preview=true")).also { + app -> + Runtime.getRuntime().addShutdownHook(Thread { app.close() }) + } + } + } } From e25674d4f4bfdb760d69f24fc45a3216563ea69d Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Tue, 24 Nov 2026 10:58:31 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9851e542b4..3e6d1fb013a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes +- OpenTelemetry: Apply the GraphQL span-naming property rename from OpenTelemetry 2.33.1, so enabling v3 semantic conventions no longer drops operation names from GraphQL span names ([#6750](https://github.com/getsentry/sentry-java/pull/6750)) - 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)) ### Dependencies From de538d934d300a231f89aea43b382f6d51e209cb Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 25 Nov 2026 06:40:32 +0100 Subject: [PATCH 3/3] fix(opentelemetry): Respect GraphQL naming configuration Read the merged OpenTelemetry configuration before applying Sentry's GraphQL span naming default. Preserve the current property when configured and migrate values supplied through the deprecated property instead of overriding customer settings. Keep integration coverage for the default semantic conventions and add equivalent coverage for the v3 preview. Refs #4547 Co-Authored-By: Claude --- CHANGELOG.md | 2 +- .../build.gradle.kts | 2 + ...ryAutoConfigurationCustomizerProvider.java | 33 +++++++-------- ...AutoConfigurationCustomizerProviderTest.kt | 40 +++++++++++++++++++ .../GraphqlIntegrationTest.kt | 14 ++++--- 5 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/test/kotlin/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProviderTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e6d1fb013a..3fb0ad8a4e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Fixes -- OpenTelemetry: Apply the GraphQL span-naming property rename from OpenTelemetry 2.33.1, so enabling v3 semantic conventions no longer drops operation names from GraphQL span names ([#6750](https://github.com/getsentry/sentry-java/pull/6750)) +- OpenTelemetry: Apply the GraphQL span-naming property rename from OpenTelemetry 2.33.1. Enabling v3 semantic conventions no longer drops operation names, and explicit settings using either property name remain honored ([#6750](https://github.com/getsentry/sentry-java/pull/6750)) - 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)) ### Dependencies diff --git a/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/build.gradle.kts b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/build.gradle.kts index 085eb11b41f..24bedc14fbb 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/build.gradle.kts +++ b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/build.gradle.kts @@ -41,8 +41,10 @@ dependencies { testImplementation(projects.sentryTestSupport) testImplementation(kotlin(Config.kotlinStdLib)) testImplementation(libs.awaitility.kotlin) + testImplementation(libs.google.truth) testImplementation(libs.kotlin.test.junit) testImplementation(libs.mockito.kotlin) + testImplementation(libs.otel.extension.autoconfigure.spi) } tasks.withType().configureEach { diff --git a/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java index 2706f89dc29..c503dfe196d 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java +++ b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/main/java/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProvider.java @@ -12,25 +12,25 @@ import io.sentry.internal.ManifestVersionReader; import io.sentry.protocol.SdkVersion; import java.time.Duration; +import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public final class SentryAutoConfigurationCustomizerProvider implements AutoConfigurationCustomizerProvider { - private static final Logger logger = - Logger.getLogger(SentryAutoConfigurationCustomizerProvider.class.getName()); + private static final String GRAPHQL_OPERATION_NAME_PROPERTY = + "otel.instrumentation.graphql.operation-name-in-span-name.enabled"; + private static final String DEPRECATED_GRAPHQL_OPERATION_NAME_PROPERTY = + "otel.instrumentation.graphql.add-operation-name-to-span-name.enabled"; public static volatile boolean skipInit = false; @Override public void customize(AutoConfigurationCustomizer autoConfiguration) { ensureSentryOtelStorageIsInitialized(); - customizeOpenTelemetryDefaults(); final @Nullable ManifestVersionReader.VersionInfoHolder versionInfoHolder = ManifestVersionReader.getInstance().readOpenTelemetryVersion(); @@ -46,8 +46,9 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) { } autoConfiguration - .addTracerProviderCustomizer(this::configureSdkTracerProvider) - .addPropertiesSupplier(this::getDefaultProperties); + .addPropertiesSupplier(this::getDefaultProperties) + .addPropertiesCustomizer(this::customizeOpenTelemetryDefaults) + .addTracerProviderCustomizer(this::configureSdkTracerProvider); } private static void ensureSentryOtelStorageIsInitialized() { @@ -59,16 +60,16 @@ private static void ensureSentryOtelStorageIsInitialized() { Sentry.getGlobalScope(); } - private void customizeOpenTelemetryDefaults() { - try { - if (System.getProperty("otel.instrumentation.graphql.operation-name-in-span-name.enabled") - == null) { - System.setProperty( - "otel.instrumentation.graphql.operation-name-in-span-name.enabled", "true"); - } - } catch (Exception e) { - logger.log(Level.WARNING, "Unable to change OpenTelemetry defaults for use with Sentry.", e); + Map customizeOpenTelemetryDefaults(final @NotNull ConfigProperties config) { + final @Nullable String configuredValue = config.getString(GRAPHQL_OPERATION_NAME_PROPERTY); + if (configuredValue != null) { + return Collections.emptyMap(); } + + final @Nullable String deprecatedValue = + config.getString(DEPRECATED_GRAPHQL_OPERATION_NAME_PROPERTY); + return Collections.singletonMap( + GRAPHQL_OPERATION_NAME_PROPERTY, deprecatedValue != null ? deprecatedValue : "true"); } private boolean isSentryAutoInitEnabled() { diff --git a/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/test/kotlin/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProviderTest.kt b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/test/kotlin/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProviderTest.kt new file mode 100644 index 00000000000..31fcc23a61e --- /dev/null +++ b/sentry-opentelemetry/sentry-opentelemetry-agentcustomization/src/test/kotlin/io/sentry/opentelemetry/SentryAutoConfigurationCustomizerProviderTest.kt @@ -0,0 +1,40 @@ +package io.sentry.opentelemetry + +import com.google.common.truth.Truth.assertThat +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties +import kotlin.test.Test +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever + +class SentryAutoConfigurationCustomizerProviderTest { + private val provider = SentryAutoConfigurationCustomizerProvider() + private val config = mock() + + @Test + fun `current GraphQL operation name property takes precedence`() { + whenever(config.getString(currentProperty)).thenReturn("false") + whenever(config.getString(deprecatedProperty)).thenReturn("true") + + assertThat(provider.customizeOpenTelemetryDefaults(config)).isEmpty() + } + + @Test + fun `migrates deprecated GraphQL operation name property`() { + whenever(config.getString(deprecatedProperty)).thenReturn("false") + + assertThat(provider.customizeOpenTelemetryDefaults(config)) + .containsExactly(currentProperty, "false") + } + + @Test + fun `enables GraphQL operation names by default`() { + assertThat(provider.customizeOpenTelemetryDefaults(config)) + .containsExactly(currentProperty, "true") + } + + private companion object { + const val currentProperty = "otel.instrumentation.graphql.operation-name-in-span-name.enabled" + const val deprecatedProperty = + "otel.instrumentation.graphql.add-operation-name-to-span-name.enabled" + } +} 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 9dbf9fad2e3..41448a8c91f 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 @@ -10,13 +10,9 @@ 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 tests enable the OpenTelemetry v3 preview, where the - * deprecated operation-name configuration property is ignored. + * description, so the queries are named. */ -class GraphqlIntegrationTest : IntegrationTest() { - - override val app: AgentApp - get() = v3PreviewApp +open class GraphqlIntegrationTest : IntegrationTest() { @Test fun `query is traced`() { @@ -119,6 +115,12 @@ class GraphqlIntegrationTest : IntegrationTest() { .awaitEnvelope { it.transaction()?.contexts?.trace?.traceId == traceId } .transaction()!! } +} + +/** Runs the GraphQL agent tests where deprecated OpenTelemetry properties are ignored. */ +class GraphqlV3IntegrationTest : GraphqlIntegrationTest() { + override val app: AgentApp + get() = v3PreviewApp companion object { private val v3PreviewApp: AgentApp by lazy {