You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using both hooks, ensure you flush both of them before the application exits and register exit handlers for fatal logs to avoid losing pending events.
190
190
</Alert>
191
191
192
-
## Correlating Logs With Traces
193
-
194
-
To correlate logs with transactions, you need to pass a `context.Context` that contains transaction information to your logger calls. The `sentryhttp` middleware automatically adds transaction information to the request's context.
195
-
Here's an example of how to use `WithContext` in an HTTP handler to ensure logs are associated with the correct trace.
196
-
197
-
```go
198
-
// Assume logger is initialized and Sentry hooks are added as shown above.
199
-
// var logger *logrus.Logger
200
-
201
-
funcmyAsyncHandler(whttp.ResponseWriter, r *http.Request) {
202
-
// The sentryhttp middleware adds a Hub with transaction information to the request context.
203
-
ctx:= r.Context()
204
-
// By using WithContext, the log entry will be associated with the transaction from the request.
0 commit comments