Skip to content

Commit

Permalink
add noop propagator.
Browse files Browse the repository at this point in the history
  • Loading branch information
rghetia committed Aug 27, 2019
1 parent a271d18 commit 066ce9a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
53 changes: 53 additions & 0 deletions api/propagation/noop_propagator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2019, 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 (
"go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/tag"
)

// NoopTextFormatPropagator implements TextFormatPropagator that does nothing.
type NoopTextFormatPropagator struct{}

var _ TextFormatPropagator = NoopTextFormatPropagator{}

// CarrierExtractor returns NoopExtractor
func (ntp NoopTextFormatPropagator) CarrierExtractor(carrier interface{}) Extractor {
return NoopExtractor{}
}

// CarrierInjector returns NoopInjector
func (ntp NoopTextFormatPropagator) CarrierInjector(carrier interface{}) Injector {
return NoopInjector{}
}

// NoopInjector implements Injector interface that does nothing.
type NoopInjector struct{}

var _ Injector = NoopInjector{}

func (ni NoopInjector) Inject(sc core.SpanContext, tm tag.Map) {
}

// NoopExtractor implements Extractor interface that does nothing.
type NoopExtractor struct{}

var _ Extractor = NoopExtractor{}

// Extract method always returns Invalid SpanContext and empty tag.Map
func (ne NoopExtractor) Extract() (core.SpanContext, tag.Map) {
return core.EmptySpanContext(), tag.NewEmptyMap()
}
20 changes: 10 additions & 10 deletions propagation/http_trace_context_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ var _ apipropagation.TextFormatPropagator = httpTraceContextPropagator{}
// CarrierExtractor implements TextFormatPropagator interface.
//
// It creates CarrierExtractor object and binds carrier to the object. The carrier
// is expected to be *http.Request. If the carrier type is not *http.Request
// then an empty extractor. Extract method on empty extractor does nothing.
// is expected to be *http.Request. If the carrier is nil or its type is not *http.Request
// then a NoopExtractor is returned.
func (hp httpTraceContextPropagator) CarrierExtractor(carrier interface{}) apipropagation.Extractor {
req, ok := carrier.(*http.Request)
if ok {
req, _ := carrier.(*http.Request)
if req != nil {
return traceContextExtractor{req: req}
}
return traceContextExtractor{}
return apipropagation.NoopExtractor{}
}

// CarrierInjector implements TextFormatPropagator interface.
//
// It creates CarrierInjector object and binds carrier to the object. The carrier
// is expected to be of type *http.Request. If the carrier type is not *http.Request
// then an empty injector is returned. Inject method on empty injector does nothing.
// is expected to be of type *http.Request. If the carrier is nil or its type is not *http.Request
// then a NoopInjector is returned.
func (hp httpTraceContextPropagator) CarrierInjector(carrier interface{}) apipropagation.Injector {
req, ok := carrier.(*http.Request)
if ok {
req, _ := carrier.(*http.Request)
if req != nil {
return traceContextInjector{req: req}
}
return traceContextInjector{}
return apipropagation.NoopInjector{}
}

// HttpTraceContextPropagator creates a new text format propagator that propagates SpanContext
Expand Down

0 comments on commit 066ce9a

Please sign in to comment.