Skip to content

Commit

Permalink
Added datadog logging context for trace correlation (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
timetinytim authored Sep 18, 2024
1 parent 84857b0 commit 0819c19
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions webpush-fcm-relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ var (
)

func main() {
tracer.Start(
tracer.WithService("webpush-fcm-relay"),
)
tracer.Start()
defer tracer.Stop()

mux := httptrace.NewServeMux()
Expand Down Expand Up @@ -76,11 +74,11 @@ func nextRequestID() string {
}

func handler(writer http.ResponseWriter, request *http.Request) {
span := tracer.StartSpan("web.request", tracer.ResourceName(request.RequestURI))
span, sctx := tracer.StartSpanFromContext(ctx, "web.request", tracer.ResourceName(request.RequestURI))
defer span.Finish()

requestID := nextRequestID()
requestLog := log.WithFields(log.Fields{"request-id": requestID})
requestLog := log.WithFields(log.Fields{"request-id": requestID}).WithContext(sctx)

writer.Header().Set("X-Request-Id", requestID)

Expand Down

0 comments on commit 0819c19

Please sign in to comment.