Skip to content

Commit

Permalink
Merge pull request #452 from Clever/wag-nightly-build
Browse files Browse the repository at this point in the history
Wag nightly build
  • Loading branch information
ChrisScotMartin authored Jan 24, 2023
2 parents edb5211 + 6f22fe2 commit 12d15a4
Show file tree
Hide file tree
Showing 15 changed files with 368 additions and 132 deletions.
2 changes: 2 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v9.0.2

v9.0.2 Separated client and models modules, reduced kv and otel deps.

v8.2.1 Sort attributes list used in v8.2.0 to reduce diffs
Expand Down
50 changes: 38 additions & 12 deletions _hardcoded/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,59 @@ func SetupGlobalTraceProviderAndExporterForTest() (*tracetest.InMemoryExporter,
// Right now we only support logging IDs in the format that Datadog expects.
func MuxServerMiddleware(serviceName string) func(http.Handler) http.Handler {
otlmux := otelmux.Middleware(serviceName, otelmux.WithPropagators(otel.GetTextMapPropagator()))
// fmt.Println("Adding mux server middleware")
return func(h http.Handler) http.Handler {
return otlmux(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
var rid string
// otelmux has extracted the span. now put it into the ctx-specific logger
// var carrier propagation.HeaderCarrier = propagation.HeaderCarrier{}

// otelmux has extracted the span. now put it into the ctx-specific logger
var crid string

s := trace.SpanFromContext(r.Context())
bag := baggage.FromContext(r.Context())

// Prefer to grab values from baggage
crid = bag.Member("clever-request-id").Value()
rid = bag.Member("X-Request-ID").Value()

// If the values aren't set in baggage grab the traceid from otel, and the x-request-id
// from the headers (set by envoy)
if crid == "" {
crid = s.SpanContext().TraceID().String()
}

if rid == "" {
rid = r.Header.Get("X-Request-ID")
if rid == "" {
rid = s.SpanContext().TraceID().String()
}
}

s.SetAttributes(attribute.String("clever-request-id", crid))

cridMember, err := baggage.NewMember("clever-request-id", crid)
if err != nil {
s.RecordError(err)
}

bag, err = bag.SetMember(cridMember)
if err != nil {
s.RecordError(err)
}

logger.FromContext(r.Context()).AddContext("clever-request-id", crid)
rw.Header().Add("clever-request-id", crid)

if rid != "" {
s.SetAttributes(attribute.String("X-Request-ID", rid))
member, err := baggage.NewMember("X-Request-ID", rid)
ridMember, err := baggage.NewMember("X-Request-ID", rid)
if err != nil {
s.RecordError(err)
}
bag, err = bag.SetMember(ridMember)
if err != nil {
s.RecordError(err)
}
bag, err = bag.SetMember(member)
ctx := baggage.ContextWithBaggage(r.Context(), bag)
r = r.WithContext(ctx)

// Envoy logs store this as request_id so lets match it for easier filtering.
logger.FromContext(r.Context()).AddContext("request_id", rid)

rw.Header().Add("X-Request-ID", rid)
logger.FromContext(r.Context()).AddContext("X-Request-ID", rid)
}

if sc := s.SpanContext(); sc.HasTraceID() {
Expand All @@ -156,6 +178,10 @@ func MuxServerMiddleware(serviceName string) func(http.Handler) http.Handler {
fmt.Sprintf("%d", binary.BigEndian.Uint64(spanIDBs)))
}
}

ctx := baggage.ContextWithBaggage(r.Context(), bag)
r = r.WithContext(ctx)

h.ServeHTTP(rw, r)
}))
}
Expand Down
6 changes: 3 additions & 3 deletions hardcoded/hardcoded.go

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions samples/gen-go-basic/server/mock_controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 38 additions & 12 deletions samples/gen-go-basic/servertracing/tracing.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 38 additions & 12 deletions samples/gen-go-blog/servertracing/tracing.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 12d15a4

Please sign in to comment.