Skip to content

Commit 71925c0

Browse files
committed
Adding detail for sampling propagation in distributed traces
1 parent 24ec67a commit 71925c0

File tree

1 file changed

+29
-0
lines changed
  • docs/platforms/javascript/common/tracing/distributed-tracing

1 file changed

+29
-0
lines changed

docs/platforms/javascript/common/tracing/distributed-tracing/index.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,32 @@ Server-side SDKs handle traces automatically on a per-request basis. This means
6060
</PlatformCategorySection>
6161

6262
If necessary, you can override the default trace duration by [manually starting a new trace](./custom-instrumentation#starting-a-new-trace).
63+
64+
## How Sampling Propagates in Distributed Traces
65+
66+
Sentry uses a "head-based" sampling approach:
67+
68+
- A sampling decision is made in the originating service (the "head")
69+
- This decision is propagated to all downstream services
70+
71+
The two key headers are:
72+
- `sentry-trace`: Contains trace ID, span ID, and sampling decision
73+
- `baggage`: Contains additional trace metadata including sample rate
74+
75+
Sentry automatically attaches these headers to outgoing HTTP requests when using the `browserTracingIntegration`. For other communication channels like WebSockets, you can manually propagate trace information:
76+
77+
```javascript
78+
// Extract trace data from the current scope
79+
const traceData = Sentry.getTraceData();
80+
const sentryTraceHeader = traceData["sentry-trace"];
81+
const sentryBaggageHeader = traceData["baggage"];
82+
83+
// Add to your custom request (example using WebSocket)
84+
webSocket.send(JSON.stringify({
85+
message: "Your data here",
86+
metadata: {
87+
sentryTrace: sentryTraceHeader,
88+
baggage: sentryBaggageHeader
89+
}
90+
}));
91+
```

0 commit comments

Comments
 (0)