Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix baggage not work in trace demo app. #9418

Merged
merged 11 commits into from
May 5, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- `resourcedetectionprocessor`: Wire docker detector (#9372)
- `kafkametricsreceiver`: The kafkametricsreceiver was changed to connect to kafka during scrape, rather than startup. If kafka is unavailable the receiver will attempt to connect during subsequent scrapes until succcessful (#8817).
- `datadogexporter`: Update Kubernetes example manifest to new executable name. (#9425).
- `examples/demo`: fix baggage not work in trace demo app. (#9418)

## v0.49.0

Expand Down
2 changes: 1 addition & 1 deletion examples/demo/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func initProvider() func() {
)

// set global propagator to tracecontext (the default is no-op).
otel.SetTextMapPropagator(propagation.TraceContext{})
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
otel.SetTracerProvider(tracerProvider)

return func() {
Expand Down
9 changes: 8 additions & 1 deletion examples/demo/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package main

import (
"context"
"fmt"
"go.opentelemetry.io/otel/baggage"
"log"
"math/rand"
"net/http"
Expand Down Expand Up @@ -101,7 +103,7 @@ func initProvider() func() {
)

// set global propagator to tracecontext (the default is no-op).
otel.SetTextMapPropagator(propagation.TraceContext{})
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
otel.SetTracerProvider(tracerProvider)

return func() {
Expand Down Expand Up @@ -156,6 +158,11 @@ func main() {
requestCount.Add(ctx, 1, commonLabels...)
span := trace.SpanFromContext(ctx)
span.SetAttributes(serverAttribute)
bag := baggage.FromContext(ctx)
for i, member := range bag.Members() {
span.AddEvent(fmt.Sprint("baggage member: ", i), trace.WithAttributes(attribute.String(member.Key(), member.Value())))
JaredTan95 marked this conversation as resolved.
Show resolved Hide resolved
}

w.Write([]byte("Hello World"))
})
wrappedHandler := otelhttp.NewHandler(handler, "/hello")
Expand Down