Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC - e2e test for distributed tracing #3948

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Extract OpenTelemetry `URL_PATH` span attribute into description ([#3933](https://github.com/getsentry/sentry-java/pull/3933))

### Dependencies

- Bump OpenTelemetry to 1.44.1, OpenTelemetry Java Agent to 2.10.0 and Semantic Conventions to 1.28.0 ([#3935](https://github.com/getsentry/sentry-java/pull/3935))

## 8.0.0-beta.3

### Features
Expand Down
9 changes: 5 additions & 4 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Config {
val kotlinStdLib = "stdlib-jdk8"

val springBootVersion = "2.7.5"
val springBoot3Version = "3.3.2"
val springBoot3Version = "3.4.0"
val kotlinCompatibleLanguageVersion = "1.4"

val composeVersion = "1.5.3"
Expand Down Expand Up @@ -156,11 +156,11 @@ object Config {
val sentryNativeNdk = "io.sentry:sentry-native-ndk:0.7.14"

object OpenTelemetry {
val otelVersion = "1.41.0"
val otelVersion = "1.44.1"
val otelAlphaVersion = "$otelVersion-alpha"
val otelInstrumentationVersion = "2.7.0"
val otelInstrumentationVersion = "2.10.0"
val otelInstrumentationAlphaVersion = "$otelInstrumentationVersion-alpha"
val otelSemanticConvetionsVersion = "1.25.0-alpha" // check https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/dependencyManagement/build.gradle.kts#L49 for release version above to find a compatible version
val otelSemanticConvetionsVersion = "1.28.0-alpha" // check https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/dependencyManagement/build.gradle.kts#L49 for release version above to find a compatible version

val otelSdk = "io.opentelemetry:opentelemetry-sdk:$otelVersion"
val otelSemconv = "io.opentelemetry.semconv:opentelemetry-semconv:$otelSemanticConvetionsVersion"
Expand All @@ -170,6 +170,7 @@ object Config {
val otelJavaAgentTooling = "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:$otelInstrumentationAlphaVersion"
val otelExtensionAutoconfigureSpi = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:$otelVersion"
val otelExtensionAutoconfigure = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:$otelVersion"
val otelInstrumentationBom = "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:$otelInstrumentationVersion"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.sentry.TraceContext
import io.sentry.TracesSamplingDecision
import io.sentry.TransactionContext
import io.sentry.apollo3.SentryApollo3HttpInterceptor.BeforeSpanCallback
import io.sentry.mockServerRequestTimeoutMillis
import io.sentry.protocol.SdkVersion
import io.sentry.protocol.SentryTransaction
import io.sentry.util.Apollo3PlatformTestManipulator
Expand All @@ -40,6 +41,7 @@ import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -192,7 +194,7 @@ class SentryApollo3InterceptorTest {
fixture.options.setTracePropagationTargets(listOf("some-host-that-does-not-exist"))
executeQuery(isSpanActive = false)

val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -201,23 +203,23 @@ class SentryApollo3InterceptorTest {
fun `when there is no active span, does not add sentry trace header to the request`() {
executeQuery(isSpanActive = false)

val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}

@Test
fun `when there is an active span, adds sentry trace headers to the request`() {
executeQuery()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}

@Test
fun `when there is an active span, existing baggage headers are merged with sentry baggage into single header`() {
executeQuery(sut = fixture.getSut(addThirdPartyBaggageHeader = true))
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.sentry.TraceContext
import io.sentry.TracesSamplingDecision
import io.sentry.TransactionContext
import io.sentry.apollo3.SentryApollo3HttpInterceptor.BeforeSpanCallback
import io.sentry.mockServerRequestTimeoutMillis
import io.sentry.protocol.SentryTransaction
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand All @@ -23,6 +24,7 @@ import org.mockito.kotlin.check
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -153,7 +155,7 @@ class SentryApollo3InterceptorWithVariablesTest {
@Test
fun `internal headers are not sent over the wire`() {
executeQuery(fixture.getSut())
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryApollo3HttpInterceptor.SENTRY_APOLLO_3_VARIABLES])
assertNull(recorderRequest.headers[SentryApollo3HttpInterceptor.SENTRY_APOLLO_3_OPERATION_TYPE])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.sentry.SpanStatus
import io.sentry.TraceContext
import io.sentry.TracesSamplingDecision
import io.sentry.TransactionContext
import io.sentry.mockServerRequestTimeoutMillis
import io.sentry.protocol.SdkVersion
import io.sentry.protocol.SentryTransaction
import io.sentry.util.ApolloPlatformTestManipulator
Expand All @@ -33,6 +34,7 @@ import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -154,15 +156,15 @@ class SentryApolloInterceptorTest {
fun `when there is no active span, adds sentry trace header to the request from scope`() {
executeQuery(isSpanActive = false)

val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}

@Test
fun `when there is an active span, adds sentry trace headers to the request`() {
executeQuery()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.sentry.SentryTracer
import io.sentry.SpanDataConvention
import io.sentry.SpanStatus
import io.sentry.TransactionContext
import io.sentry.mockServerRequestTimeoutMillis
import okhttp3.Call
import okhttp3.EventListener
import okhttp3.OkHttpClient
Expand All @@ -25,6 +26,7 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -111,7 +113,7 @@ class SentryOkHttpEventListenerTest {
fun `when there is an active span and the SentryOkHttpInterceptor, adds sentry trace headers to the request`() {
val sut = fixture.getSut(useInterceptor = true)
sut.newCall(getRequest()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -121,7 +123,7 @@ class SentryOkHttpEventListenerTest {
fun `when there is an active span but no SentryOkHttpInterceptor, sentry trace headers are not added to the request`() {
val sut = fixture.getSut()
sut.newCall(getRequest()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.sentry.SpanStatus
import io.sentry.TransactionContext
import io.sentry.TypeCheckHint
import io.sentry.exception.SentryHttpClientException
import io.sentry.mockServerRequestTimeoutMillis
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand All @@ -37,6 +38,7 @@ import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.io.IOException
import java.util.concurrent.TimeUnit
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
Expand Down Expand Up @@ -159,7 +161,7 @@ class SentryOkHttpInterceptorTest {
fun `when there is an active span and server is listed in tracing origins, adds sentry trace headers to the request`() {
val sut = fixture.getSut()
sut.newCall(getRequest()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -170,7 +172,7 @@ class SentryOkHttpInterceptorTest {
val sut = fixture.getSut(keepDefaultTracePropagationTargets = true)

sut.newCall(getRequest()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -180,7 +182,7 @@ class SentryOkHttpInterceptorTest {
fun `when there is an active span and server is not listed in tracing origins, does not add sentry trace headers to the request`() {
val sut = fixture.getSut(includeMockServerInTracePropagationTargets = false)
sut.newCall(Request.Builder().get().url(fixture.server.url("/hello")).build()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -191,7 +193,7 @@ class SentryOkHttpInterceptorTest {
val sut = fixture.getSut()
fixture.options.setTracePropagationTargets(emptyList())
sut.newCall(Request.Builder().get().url(fixture.server.url("/hello")).build()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -200,7 +202,7 @@ class SentryOkHttpInterceptorTest {
fun `when there is no active span, adds sentry trace header to the request from scope`() {
val sut = fixture.getSut(isSpanActive = false)
sut.newCall(getRequest()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -210,7 +212,7 @@ class SentryOkHttpInterceptorTest {
val sut = fixture.getSut(isSpanActive = false)
fixture.options.setTracePropagationTargets(listOf("some-host-that-does-not-exist"))
sut.newCall(getRequest()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -219,7 +221,7 @@ class SentryOkHttpInterceptorTest {
fun `when there is an active span, existing baggage headers are merged with sentry baggage into single header`() {
val sut = fixture.getSut()
sut.newCall(getRequestWithBaggageHeader()).execute()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.sentry.SentryTracer
import io.sentry.SpanDataConvention
import io.sentry.SpanStatus
import io.sentry.TransactionContext
import io.sentry.mockServerRequestTimeoutMillis
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.mockito.kotlin.any
Expand All @@ -25,6 +26,7 @@ import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -93,7 +95,7 @@ class SentryFeignClientTest {
fixture.sentryOptions.dsn = "https://[email protected]/proj"
val sut = fixture.getSut()
sut.getOk()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -106,7 +108,7 @@ class SentryFeignClientTest {

sut.getOkWithBaggageHeader(mapOf("baggage" to listOf("thirdPartyBaggage=someValue", "secondThirdPartyBaggage=secondValue; property;propertyKey=propertyValue,anotherThirdPartyBaggage=anotherValue")))

val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])

Expand All @@ -123,7 +125,7 @@ class SentryFeignClientTest {
fixture.sentryOptions.dsn = "https://[email protected]/proj"
val sut = fixture.getSut(isSpanActive = false)
sut.getOk()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNotNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNotNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -134,7 +136,7 @@ class SentryFeignClientTest {
fixture.sentryOptions.dsn = "https://[email protected]/proj"
val sut = fixture.getSut(isSpanActive = false)
sut.getOk()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand All @@ -146,7 +148,7 @@ class SentryFeignClientTest {
fixture.sentryOptions.dsn = "https://[email protected]/proj"
val sut = fixture.getSut()
sut.getOk()
val recorderRequest = fixture.server.takeRequest()
val recorderRequest = fixture.server.takeRequest(mockServerRequestTimeoutMillis, TimeUnit.MILLISECONDS)!!
assertNull(recorderRequest.headers[SentryTraceHeader.SENTRY_TRACE_HEADER])
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public final class io/sentry/opentelemetry/SentryContextStorage : io/opentelemet
public fun current ()Lio/opentelemetry/context/Context;
}

public final class io/sentry/opentelemetry/SentryContextStorageProvider : io/opentelemetry/context/ContextStorageProvider {
public fun <init> ()V
public fun get ()Lio/opentelemetry/context/ContextStorage;
}

public final class io/sentry/opentelemetry/SentryContextWrapper : io/opentelemetry/context/Context {
public fun get (Lio/opentelemetry/context/ContextKey;)Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static io.sentry.opentelemetry.SentryOtelKeys.SENTRY_SCOPES_KEY;

import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextStorage;
import io.opentelemetry.context.Scope;
import io.sentry.IScopes;
import io.sentry.IScopesStorage;
Expand All @@ -27,8 +26,8 @@ public void init() {
* should try to use OTels StorageProvider mechanism instead.
*/
// ContextStorage.addWrapper((storage) -> new SentryContextStorage(storage));
ContextStorage.addWrapper(
(storage) -> new SentryContextStorage(new SentryOtelThreadLocalStorage()));
// ContextStorage.addWrapper(
// (storage) -> new SentryContextStorage(new SentryOtelThreadLocalStorage()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.sentry.opentelemetry;

import io.opentelemetry.context.ContextStorage;
import io.opentelemetry.context.ContextStorageProvider;

public final class SentryContextStorageProvider implements ContextStorageProvider {
@Override
public ContextStorage get() {
System.out.println("hello from SentryContextStorageProvider");
return new SentryContextStorage(new SentryOtelThreadLocalStorage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.sentry.opentelemetry.SentryContextStorageProvider
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public final class io/sentry/opentelemetry/OtelInternalSpanDetectionUtil {
public final class io/sentry/opentelemetry/OtelSamplingUtil {
public fun <init> ()V
public static fun extractSamplingDecision (Lio/opentelemetry/api/common/Attributes;)Lio/sentry/TracesSamplingDecision;
public static fun extractSamplingDecisionOrDefault (Lio/opentelemetry/api/common/Attributes;)Lio/sentry/TracesSamplingDecision;
}

public final class io/sentry/opentelemetry/OtelSentryPropagator : io/opentelemetry/context/propagation/TextMapPropagator {
Expand Down
Loading
Loading