Skip to content

Commit

Permalink
[WIP] Set default propagator to no-op propagator
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>
  • Loading branch information
Hui Kang and Aneurysm9 committed Sep 24, 2020
1 parent 0b348c3 commit a413884
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Renamed `SamplingDecision` values to comply with OpenTelemetry specification change. (#1192)
- Renamed Zipkin attribute names from `ot.status_code & ot.status_description` to `otel.status_code & otel.status_description`. (#1201)
- The default SDK now invokes registered `SpanProcessor`s in the order they were registered with the `TracerProvider`. (#1195)
- The default propagator is no-op propagator. (#1184)

### Removed

Expand Down
12 changes: 4 additions & 8 deletions api/global/internal/state.go
Original file line number Diff line number Diff line change
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,14 +118,12 @@ 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{}
noopPropagator := propagation.NoopPropagator{}
return propagation.New(
propagation.WithExtractors(tcPropagator, bagPropagator),
propagation.WithInjectors(tcPropagator, bagPropagator),
propagation.WithExtractors(noopPropagator),
propagation.WithInjectors(noopPropagator),
)
}

Expand Down
34 changes: 34 additions & 0 deletions api/propagation/noop_propagator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package propagation

import (
"context"
)

type NoopPropagator struct {
}

var _ HTTPPropagator = NoopPropagator{}

func (p NoopPropagator) Extract(ctx context.Context, supplier HTTPSupplier) context.Context {
return ctx
}

func (NoopPropagator) Inject(context.Context, HTTPSupplier) {}

func (NoopPropagator) GetAllKeys() []string {
return nil
}
6 changes: 6 additions & 0 deletions example/basic/main.go
Original file line number Diff line number Diff line change
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,11 @@ func main() {
global.SetTracerProvider(tp)
global.SetMeterProvider(pusher.MeterProvider())

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
Original file line number Diff line number Diff line change
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 a413884

Please sign in to comment.