Skip to content

Commit

Permalink
Add baggage header to RestTemplate (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Aug 16, 2022
1 parent 7dd32c0 commit bf18c0d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

- Send source for transactions ([#2180](https://github.com/getsentry/sentry-java/pull/2180))
- Add profilesSampleRate and profileSampler options for Android sdk ([#2184](https://github.com/getsentry/sentry-java/pull/2184))
- Add baggage header to RestTemplate ([#2206](https://github.com/getsentry/sentry-java/pull/2206))

## 6.3.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class SentrySpanRestTemplateCustomizerTest {
sentryOptions.tracingOrigins.add("other-api")
}

sentryOptions.dsn = "https://key@sentry.io/proj"
sentryOptions.isTraceSampling = true

mockServer.enqueue(
MockResponse()
.setBody("OK")
Expand Down Expand Up @@ -78,6 +81,7 @@ class SentrySpanRestTemplateCustomizerTest {
assertThat(recordedRequest.headers["sentry-trace"]!!).startsWith(fixture.transaction.spanContext.traceId.toString())
.endsWith("-1")
.doesNotContain(fixture.transaction.spanContext.spanId.toString())
assertThat(recordedRequest.headers["baggage"]!!).contains(fixture.transaction.spanContext.traceId.toString())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.sentry.TypeCheckHint.SPRING_REQUEST_INTERCEPTOR_RESPONSE;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.BaggageHeader;
import io.sentry.Breadcrumb;
import io.sentry.Hint;
import io.sentry.IHub;
Expand Down Expand Up @@ -50,6 +51,10 @@ public SentrySpanClientHttpRequestInterceptor(final @NotNull IHub hub) {

if (TracingOrigins.contain(hub.getOptions().getTracingOrigins(), request.getURI())) {
request.getHeaders().add(sentryTraceHeader.getName(), sentryTraceHeader.getValue());
@Nullable BaggageHeader baggage = span.toBaggageHeader();
if (baggage != null) {
request.getHeaders().add(baggage.getName(), baggage.getValue());
}
}

try {
Expand Down

0 comments on commit bf18c0d

Please sign in to comment.