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 @@ -9,6 +9,7 @@

### Fixes

- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaCompile>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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() {
Expand All @@ -59,16 +60,16 @@ private static void ensureSentryOtelStorageIsInitialized() {
Sentry.getGlobalScope();
}

private void customizeOpenTelemetryDefaults() {
try {
if (System.getProperty("otel.instrumentation.graphql.add-operation-name-to-span-name.enabled")
== null) {
System.setProperty(
"otel.instrumentation.graphql.add-operation-name-to-span-name.enabled", "true");
}
} catch (Exception e) {
logger.log(Level.WARNING, "Unable to change OpenTelemetry defaults for use with Sentry.", e);
Map<String, String> 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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ConfigProperties>()

@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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptyList()) : Closeable {
class AgentApp(
args: List<String> = emptyList(),
additionalJvmArgs: List<String> = 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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.
*/
class GraphqlIntegrationTest : IntegrationTest() {
open class GraphqlIntegrationTest : IntegrationTest() {

@Test
fun `query is traced`() {
Expand Down Expand Up @@ -116,3 +116,18 @@ class GraphqlIntegrationTest : IntegrationTest() {
.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 {
AgentApp(additionalJvmArgs = listOf("-Dotel.instrumentation.common.v3-preview=true")).also {
app ->
Runtime.getRuntime().addShutdownHook(Thread { app.close() })
}
}
}
}
Loading