Skip to content

Commit

Permalink
Set default propagator to no-op propagator (#1204)
Browse files Browse the repository at this point in the history
- add set propagator to examples

Signed-off-by: Hui Kang <kangh@us.ibm.com>
Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>

Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
  • Loading branch information
huikang and Aneurysm9 committed Sep 29, 2020
1 parent 04297f4 commit 423c891
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- OTLP Metric exporter supports Histogram aggregation. (#1209)

### Changed

- Set default propagator to no-op propagator. (#1184)

## [0.12.0] - 2020-09-24

### Added
Expand Down
12 changes: 2 additions & 10 deletions api/global/internal/state.go
Expand Up @@ -18,11 +18,9 @@ import (
"sync"
"sync/atomic"

"go.opentelemetry.io/otel/api/baggage"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/propagators"
)

type (
Expand Down Expand Up @@ -120,15 +118,9 @@ func defaultPropagatorsValue() *atomic.Value {
return v
}

// getDefaultPropagators returns a default Propagators, configured
// with W3C trace and baggage propagation.
// getDefaultPropagators returns a default noop Propagators
func getDefaultPropagators() propagation.Propagators {
tcPropagator := propagators.TraceContext{}
bagPropagator := baggage.Baggage{}
return propagation.New(
propagation.WithExtractors(tcPropagator, bagPropagator),
propagation.WithInjectors(tcPropagator, bagPropagator),
)
return propagation.New()
}

// ResetForTest restores the initial global state, for testing purposes.
Expand Down
7 changes: 7 additions & 0 deletions example/basic/main.go
Expand Up @@ -21,6 +21,7 @@ import (
"go.opentelemetry.io/otel/api/baggage"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/label"
Expand Down Expand Up @@ -61,6 +62,12 @@ func main() {
global.SetTracerProvider(tp)
global.SetMeterProvider(pusher.MeterProvider())

// set propagator to baggage since the default is no-op
bagPropagator := baggage.DefaultHTTPPropagator()
props := propagation.New(propagation.WithExtractors(bagPropagator),
propagation.WithInjectors(bagPropagator))

global.SetPropagators(props)
tracer := global.Tracer("ex.com/basic")
meter := global.Meter("ex.com/basic")

Expand Down
6 changes: 6 additions & 0 deletions example/otel-collector/main.go
Expand Up @@ -27,9 +27,11 @@ import (

"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/propagation"
apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/otlp"
"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"
Expand Down Expand Up @@ -73,6 +75,10 @@ func initProvider() func() {
push.WithPeriod(2*time.Second),
)

tcPropagator := propagators.TraceContext{}
props := propagation.New(propagation.WithExtractors(tcPropagator),
propagation.WithInjectors(tcPropagator))
global.SetPropagators(props)
global.SetTracerProvider(tracerProvider)
global.SetMeterProvider(pusher.MeterProvider())
pusher.Start()
Expand Down

0 comments on commit 423c891

Please sign in to comment.