Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Added `Environment` to the `Scope`, allowing you to overwrite the `Environment` set on the options ([#5772](https://github.com/getsentry/sentry-java/pull/5772))
- The scope `Environment` is also applied to the trace envelope header (DSC), logs, metrics and profiles, so all telemetry of a trace reports the same environment
- Add an `attachTracingHeaders` flag to `SentryApolloInterceptor` to stop attaching `sentry-trace` and `baggage` headers to Apollo v2 requests ([#6414](https://github.com/getsentry/sentry-java/pull/6414))
- Apollo v2 has no request URL in the interceptor, so these headers are attached without checking `tracePropagationTargets`. Pass `attachTracingHeaders = false` to opt out.

### Fixes

Expand Down
2 changes: 2 additions & 0 deletions sentry-apollo/api/sentry-apollo.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public final class io/sentry/apollo/SentryApolloInterceptor : com/apollographql/
public fun <init> (Lio/sentry/IScopes;)V
public fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo/SentryApolloInterceptor$BeforeSpanCallback;)V
public synthetic fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo/SentryApolloInterceptor$BeforeSpanCallback;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo/SentryApolloInterceptor$BeforeSpanCallback;Z)V
public synthetic fun <init> (Lio/sentry/IScopes;Lio/sentry/apollo/SentryApolloInterceptor$BeforeSpanCallback;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lio/sentry/apollo/SentryApolloInterceptor$BeforeSpanCallback;)V
public fun dispose ()V
public fun interceptAsync (Lcom/apollographql/apollo/interceptor/ApolloInterceptor$InterceptorRequest;Lcom/apollographql/apollo/interceptor/ApolloInterceptorChain;Ljava/util/concurrent/Executor;Lcom/apollographql/apollo/interceptor/ApolloInterceptor$CallBack;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ class SentryApolloInterceptor(
}
}

private var attachTracingHeaders: Boolean = true

constructor(scopes: IScopes) : this(scopes, null)

constructor(
scopes: IScopes = ScopesAdapter.getInstance(),
beforeSpan: BeforeSpanCallback? = null,
attachTracingHeaders: Boolean,
) : this(scopes, beforeSpan) {
this.attachTracingHeaders = attachTracingHeaders
}

constructor(beforeSpan: BeforeSpanCallback) : this(ScopesAdapter.getInstance(), beforeSpan)

init {
Expand Down Expand Up @@ -134,7 +144,7 @@ class SentryApolloInterceptor(
private fun addTracingHeaders(request: InterceptorRequest, span: ISpan?): RequestHeaders {
val requestHeaderBuilder = request.requestHeaders.toBuilder()

if (scopes.options.isTraceSampling && !isIgnored()) {
if (attachTracingHeaders && scopes.options.isTraceSampling && !isIgnored()) {
// we have no access to URI, no way to verify tracing origins
TracingUtils.trace(
scopes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class SentryApolloInterceptorTest {
}
}""",
socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN,
attachTracingHeaders: Boolean = true,
beforeSpan: SentryApolloInterceptor.BeforeSpanCallback? = null,
): ApolloClient {
server.enqueue(
Expand All @@ -97,8 +98,8 @@ class SentryApolloInterceptorTest {
.setResponseCode(httpStatusCode)
)

if (beforeSpan != null) {
interceptor = SentryApolloInterceptor(scopes, beforeSpan)
if (beforeSpan != null || !attachTracingHeaders) {
interceptor = SentryApolloInterceptor(scopes, beforeSpan, attachTracingHeaders)
}
return ApolloClient.builder()
.serverUrl(server.url("/"))
Expand Down Expand Up @@ -206,6 +207,16 @@ class SentryApolloInterceptorTest {
assertNull(recorderRequest.headers[BaggageHeader.BAGGAGE_HEADER])
}

@Test
fun `does not add sentry-trace header when attaching tracing headers is disabled`() {
executeQuery(fixture.getSut(attachTracingHeaders = false))

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

@Test
fun `when there is an active span, adds sentry trace headers to the request`() {
executeQuery()
Expand Down
Loading