Skip to content

Commit

Permalink
broaden the requestTrace attachment accessor (#1297)
Browse files Browse the repository at this point in the history
broaden the requestTrace attachment accessor
  • Loading branch information
carterkozak authored Oct 2, 2024
1 parent ccd201f commit 3540576
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1297.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: broaden the requestTrace attachment accessor
links:
- https://github.com/palantir/tracing-java/pull/1297
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ public final class TracingAttachments {
*/
static final AttachmentKey<DetachedSpan> REQUEST_SPAN = AttachmentKey.create(DetachedSpan.class);

/**
* The {@link Detached} trace state which represents the top-level request being processed. This may
* be used to apply thread state to code executing outside traced handlers, exchange completion
* listeners, for example.
*/
@SuppressWarnings("unchecked")
public static final AttachmentKey<Detached> REQUEST_DETACHED_TRACE =
(AttachmentKey<Detached>) (AttachmentKey<?>) REQUEST_SPAN;

/**
* Gets the {@link Detached} trace state which represents the top-level request being processed. This may
* be used to apply thread state to code executing outside traced handlers, exchange completion
* listeners, for example.
*/
@Nullable
public static Detached requestTrace(HttpServerExchange exchange) {
return exchange.getAttachment(REQUEST_SPAN);
return exchange.getAttachment(REQUEST_DETACHED_TRACE);
}

private TracingAttachments() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public void whenSamplingDecisionHasNotBeenMade_callsSampler() throws Exception {
public void setsDetachedTrace() throws Exception {
handler.handleRequest(exchange);
assertThat(TracingAttachments.requestTrace(exchange)).isNotNull();
assertThat(exchange.getAttachment(TracingAttachments.REQUEST_DETACHED_TRACE))
.isNotNull();
}

@Test
Expand Down

0 comments on commit 3540576

Please sign in to comment.