You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-13 01:00:22 +02:00
Add Baggage API and move Baggage propagator (#1217)
* Move api/baggage to the propagators package * Create Baggage API to match specification * Update CHANGELOG.md * Baggage API unit tests * Rename and add unit test * Update unit test value checking * Update TODO with issue tracking work.
This commit is contained in:
@ -18,12 +18,13 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"go.opentelemetry.io/otel/api/baggage"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/api/global"
|
||||
"go.opentelemetry.io/otel/api/metric"
|
||||
"go.opentelemetry.io/otel/api/trace"
|
||||
"go.opentelemetry.io/otel/exporters/stdout"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/propagators"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/push"
|
||||
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
||||
@ -62,7 +63,7 @@ func main() {
|
||||
global.SetMeterProvider(pusher.MeterProvider())
|
||||
|
||||
// set global propagator to baggage (the default is no-op).
|
||||
global.SetTextMapPropagator(baggage.Baggage{})
|
||||
global.SetTextMapPropagator(propagators.Baggage{})
|
||||
tracer := global.Tracer("ex.com/basic")
|
||||
meter := global.Meter("ex.com/basic")
|
||||
|
||||
@ -78,11 +79,7 @@ func main() {
|
||||
valuerecorderTwo := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
ctx = baggage.NewContext(ctx,
|
||||
fooKey.String("foo1"),
|
||||
barKey.String("bar1"),
|
||||
)
|
||||
ctx = otel.ContextWithBaggageValues(ctx, fooKey.String("foo1"), barKey.String("bar1"))
|
||||
|
||||
valuerecorder := valuerecorderTwo.Bind(commonLabels...)
|
||||
defer valuerecorder.Unbind()
|
||||
@ -97,7 +94,7 @@ func main() {
|
||||
|
||||
meter.RecordBatch(
|
||||
// Note: call-site variables added as context Entries:
|
||||
baggage.NewContext(ctx, anotherKey.String("xyz")),
|
||||
otel.ContextWithBaggageValues(ctx, anotherKey.String("xyz")),
|
||||
commonLabels,
|
||||
|
||||
valuerecorderTwo.Measurement(2.0),
|
||||
|
Reference in New Issue
Block a user