Skip to content

Commit 697cbeb

Browse files
giortzisgbitsandfoxes
authored andcommitted
fix(go) - correct usage of hub in tracing injection (#13371)
1 parent 5e4b3d1 commit 697cbeb

File tree

1 file changed

+6
-4
lines changed
  • platform-includes/distributed-tracing/custom-instrumentation

1 file changed

+6
-4
lines changed

platform-includes/distributed-tracing/custom-instrumentation/go.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Incoming tracing information has to be extracted and stored in memory for later
1212
Here's an example of how to extract and store incoming tracing information using `sentry.ContinueTrace()`:
1313

1414
```go
15-
hub := sentry.CurrentHub()
15+
ctx := r.Context()
16+
hub := sentry.GetHubFromContext(ctx)
1617
sentry.ContinueTrace(hub, r.Header.Get(sentry.SentryTraceHeader), r.Header.Get(sentry.SentryBaggageHeader)),
1718
```
1819

@@ -27,10 +28,11 @@ For distributed tracing to work, the two headers `sentry-trace` and `baggage`, m
2728
You can generate this tracing information with the Sentry SDK's `hub.GetTraceparent()` and `hub.GetBaggage()` functions. Here's an example using Guzzle:
2829

2930
```go
30-
hub := sentry.CurrentHub()
31+
ctx := r.Context()
32+
hub := sentry.GetHubFromContext(ctx)
3133
req, _ := http.NewRequest("GET", "http://exmaple.com", nil)
32-
req.Header.Add(sentry.SentryTraceHeader, hub.GetTraceparent())
33-
req.Header.Add(sentry.SentryBaggageHeader, hub.GetBaggage())
34+
req.Header.Set(sentry.SentryTraceHeader, hub.GetTraceparent())
35+
req.Header.Set(sentry.SentryBaggageHeader, hub.GetBaggage())
3436
```
3537

3638
In this example, tracing information is propagated to the project running at `https://example.com`. If this project uses a Sentry SDK, it will extract and save the tracing information for later use.

0 commit comments

Comments
 (0)