diff --git a/propagation/b3_propagator.go b/api/propagators/b3_propagator.go similarity index 84% rename from propagation/b3_propagator.go rename to api/propagators/b3_propagator.go index 35274ac7732..4753603fbfb 100644 --- a/propagation/b3_propagator.go +++ b/api/propagators/b3_propagator.go @@ -12,18 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation +package propagators import ( "context" "fmt" "strings" - "go.opentelemetry.io/otel/api/trace" - "go.opentelemetry.io/otel/api/core" dctx "go.opentelemetry.io/otel/api/distributedcontext" - apipropagation "go.opentelemetry.io/otel/api/propagation" + "go.opentelemetry.io/otel/api/trace" ) const ( @@ -35,8 +33,7 @@ const ( B3ParentSpanIDHeader = "X-B3-ParentSpanId" ) -// B3Propagator that facilitates core.SpanContext -// propagation using B3 Headers. +// B3 propagator serializes core.SpanContext to/from B3 Headers. // This propagator supports both version of B3 headers, // 1. Single Header : // X-B3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId} @@ -49,13 +46,13 @@ const ( // // If SingleHeader is set to true then X-B3 header is used to inject and extract. Otherwise, // separate headers are used to inject and extract. -type B3Propagator struct { +type B3 struct { SingleHeader bool } -var _ apipropagation.TextFormatPropagator = B3Propagator{} +var _ TextFormat = B3{} -func (b3 B3Propagator) Inject(ctx context.Context, supplier apipropagation.Supplier) { +func (b3 B3) Inject(ctx context.Context, supplier Supplier) { sc := trace.CurrentSpan(ctx).SpanContext() if sc.IsValid() { if b3.SingleHeader { @@ -79,21 +76,21 @@ func (b3 B3Propagator) Inject(ctx context.Context, supplier apipropagation.Suppl } // Extract retrieves B3 Headers from the supplier -func (b3 B3Propagator) Extract(ctx context.Context, supplier apipropagation.Supplier) (core.SpanContext, dctx.Map) { +func (b3 B3) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map) { if b3.SingleHeader { return b3.extractSingleHeader(supplier), dctx.NewEmptyMap() } return b3.extract(supplier), dctx.NewEmptyMap() } -func (b3 B3Propagator) GetAllKeys() []string { +func (b3 B3) GetAllKeys() []string { if b3.SingleHeader { return []string{B3SingleHeader} } return []string{B3TraceIDHeader, B3SpanIDHeader, B3SampledHeader} } -func (b3 B3Propagator) extract(supplier apipropagation.Supplier) core.SpanContext { +func (b3 B3) extract(supplier Supplier) core.SpanContext { tid, err := core.TraceIDFromHex(supplier.Get(B3TraceIDHeader)) if err != nil { return core.EmptySpanContext() @@ -128,7 +125,7 @@ func (b3 B3Propagator) extract(supplier apipropagation.Supplier) core.SpanContex return sc } -func (b3 B3Propagator) extractSingleHeader(supplier apipropagation.Supplier) core.SpanContext { +func (b3 B3) extractSingleHeader(supplier Supplier) core.SpanContext { h := supplier.Get(B3SingleHeader) if h == "" || h == "0" { core.EmptySpanContext() @@ -177,7 +174,7 @@ func (b3 B3Propagator) extractSingleHeader(supplier apipropagation.Supplier) cor } // extractSampledState parses the value of the X-B3-Sampled b3Header. -func (b3 B3Propagator) extractSampledState(sampled string) (flag byte, ok bool) { +func (b3 B3) extractSampledState(sampled string) (flag byte, ok bool) { switch sampled { case "", "0": return 0, true @@ -196,7 +193,7 @@ func (b3 B3Propagator) extractSampledState(sampled string) (flag byte, ok bool) } // extracDebugFlag parses the value of the X-B3-Sampled b3Header. -func (b3 B3Propagator) extracDebugFlag(debug string) (flag byte, ok bool) { +func (b3 B3) extracDebugFlag(debug string) (flag byte, ok bool) { switch debug { case "", "0": return 0, true diff --git a/propagation/b3_propagator_benchmark_test.go b/api/propagators/b3_propagator_benchmark_test.go similarity index 94% rename from propagation/b3_propagator_benchmark_test.go rename to api/propagators/b3_propagator_benchmark_test.go index a6414f9660c..54a36b5613c 100644 --- a/propagation/b3_propagator_benchmark_test.go +++ b/api/propagators/b3_propagator_benchmark_test.go @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation_test +package propagators_test import ( "context" "net/http" "testing" + "go.opentelemetry.io/otel/api/propagators" "go.opentelemetry.io/otel/api/trace" mocktrace "go.opentelemetry.io/otel/internal/trace" - "go.opentelemetry.io/otel/propagation" ) func BenchmarkExtractB3(b *testing.B) { @@ -53,7 +53,7 @@ func BenchmarkExtractB3(b *testing.B) { } for _, tg := range testGroup { - propagator := propagation.B3Propagator{tg.singleHeader} + propagator := propagators.B3{tg.singleHeader} for _, tt := range tg.tests { traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) { ctx := context.Background() @@ -97,7 +97,7 @@ func BenchmarkInjectB3(b *testing.B) { for _, tg := range testGroup { id = 0 - propagator := propagation.B3Propagator{tg.singleHeader} + propagator := propagators.B3{tg.singleHeader} for _, tt := range tg.tests { traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) { req, _ := http.NewRequest("GET", "http://example.com", nil) diff --git a/propagation/b3_propagator_data_test.go b/api/propagators/b3_propagator_data_test.go similarity index 56% rename from propagation/b3_propagator_data_test.go rename to api/propagators/b3_propagator_data_test.go index bab850f460f..73389d47916 100644 --- a/propagation/b3_propagator_data_test.go +++ b/api/propagators/b3_propagator_data_test.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation_test +package propagators_test import ( "go.opentelemetry.io/otel/api/core" - "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/api/propagators" ) type extractTest struct { @@ -29,8 +29,8 @@ var extractMultipleHeaders = []extractTest{ { name: "sampling state defer", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -40,9 +40,9 @@ var extractMultipleHeaders = []extractTest{ { name: "sampling state deny", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3SampledHeader: "0", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3SampledHeader: "0", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -52,9 +52,9 @@ var extractMultipleHeaders = []extractTest{ { name: "sampling state accept", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3SampledHeader: "1", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -65,9 +65,9 @@ var extractMultipleHeaders = []extractTest{ { name: "sampling state as a boolean", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3SampledHeader: "true", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3SampledHeader: "true", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -78,9 +78,9 @@ var extractMultipleHeaders = []extractTest{ { name: "debug flag set", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3DebugFlagHeader: "1", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3DebugFlagHeader: "1", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -94,10 +94,10 @@ var extractMultipleHeaders = []extractTest{ // takes precedence. Hence, it is sampled. name: "debug flag set and sampling state is deny", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3SampledHeader: "0", - propagation.B3DebugFlagHeader: "1", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3SampledHeader: "0", + propagators.B3DebugFlagHeader: "1", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -108,10 +108,10 @@ var extractMultipleHeaders = []extractTest{ { name: "with parent span id", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3SampledHeader: "1", - propagation.B3ParentSpanIDHeader: "00f067aa0ba90200", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3SampledHeader: "1", + propagators.B3ParentSpanIDHeader: "00f067aa0ba90200", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -122,7 +122,7 @@ var extractMultipleHeaders = []extractTest{ { name: "with only sampled state header", headers: map[string]string{ - propagation.B3SampledHeader: "0", + propagators.B3SampledHeader: "0", }, wantSc: core.EmptySpanContext(), }, @@ -132,7 +132,7 @@ var extractSingleHeader = []extractTest{ { name: "sampling state defer", headers: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -142,7 +142,7 @@ var extractSingleHeader = []extractTest{ { name: "sampling state deny", headers: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -152,7 +152,7 @@ var extractSingleHeader = []extractTest{ { name: "sampling state accept", headers: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -163,7 +163,7 @@ var extractSingleHeader = []extractTest{ { name: "sampling state debug", headers: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -174,7 +174,7 @@ var extractSingleHeader = []extractTest{ { name: "with parent span id", headers: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd", }, wantSc: core.SpanContext{ TraceID: traceID, @@ -185,7 +185,7 @@ var extractSingleHeader = []extractTest{ { name: "with only sampling state deny", headers: map[string]string{ - propagation.B3SingleHeader: "0", + propagators.B3SingleHeader: "0", }, wantSc: core.EmptySpanContext(), }, @@ -195,143 +195,143 @@ var extractInvalidB3MultipleHeaders = []extractTest{ { name: "trace ID length > 32", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab00000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab00000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "trace ID length >16 and <32", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab0000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab0000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "trace ID length <16", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab0000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab0000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "wrong span ID length", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd0000000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd0000000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "wrong sampled flag length", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "10", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "10", }, }, { name: "bogus trace ID", headers: map[string]string{ - propagation.B3TraceIDHeader: "qw000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "qw000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "bogus span ID", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "qw00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "qw00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "bogus sampled flag", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "d", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "d", }, }, { name: "bogus debug flag (string)", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", - propagation.B3DebugFlagHeader: "d", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", + propagators.B3DebugFlagHeader: "d", }, }, { name: "bogus debug flag (number)", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", - propagation.B3DebugFlagHeader: "10", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", + propagators.B3DebugFlagHeader: "10", }, }, { name: "upper case trace ID", headers: map[string]string{ - propagation.B3TraceIDHeader: "AB000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "AB000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "upper case span ID", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "CD00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "CD00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "zero trace ID", headers: map[string]string{ - propagation.B3TraceIDHeader: "00000000000000000000000000000000", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "00000000000000000000000000000000", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "zero span ID", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SpanIDHeader: "0000000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SpanIDHeader: "0000000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "missing span ID", headers: map[string]string{ - propagation.B3TraceIDHeader: "ab000000000000000000000000000000", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "ab000000000000000000000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "missing trace ID", headers: map[string]string{ - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "missing trace ID with valid single header", headers: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1", - propagation.B3SpanIDHeader: "cd00000000000000", - propagation.B3SampledHeader: "1", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1", + propagators.B3SpanIDHeader: "cd00000000000000", + propagators.B3SampledHeader: "1", }, }, { name: "sampled header set to 1 but trace ID and span ID are missing", headers: map[string]string{ - propagation.B3SampledHeader: "1", + propagators.B3SampledHeader: "1", }, }, } @@ -340,96 +340,96 @@ var extractInvalidB3SingleHeader = []extractTest{ { name: "wrong trace ID length", headers: map[string]string{ - propagation.B3SingleHeader: "ab00000000000000000000000000000000-cd00000000000000-1", + propagators.B3SingleHeader: "ab00000000000000000000000000000000-cd00000000000000-1", }, }, { name: "wrong span ID length", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-cd0000000000000000-1", + propagators.B3SingleHeader: "ab000000000000000000000000000000-cd0000000000000000-1", }, }, { name: "wrong sampled state length", headers: map[string]string{ - propagation.B3SingleHeader: "00-ab000000000000000000000000000000-cd00000000000000-01", + propagators.B3SingleHeader: "00-ab000000000000000000000000000000-cd00000000000000-01", }, }, { name: "wrong parent span ID length", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-cd0000000000000000", + propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-cd0000000000000000", }, }, { name: "bogus trace ID", headers: map[string]string{ - propagation.B3SingleHeader: "qw000000000000000000000000000000-cd00000000000000-1", + propagators.B3SingleHeader: "qw000000000000000000000000000000-cd00000000000000-1", }, }, { name: "bogus span ID", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-qw00000000000000-1", + propagators.B3SingleHeader: "ab000000000000000000000000000000-qw00000000000000-1", }, }, { name: "bogus sampled flag", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-q", + propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-q", }, }, { name: "bogus parent span ID", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-qw00000000000000", + propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-qw00000000000000", }, }, { name: "upper case trace ID", headers: map[string]string{ - propagation.B3SingleHeader: "AB000000000000000000000000000000-cd00000000000000-1", + propagators.B3SingleHeader: "AB000000000000000000000000000000-cd00000000000000-1", }, }, { name: "upper case span ID", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1", + propagators.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1", }, }, { name: "upper case parent span ID", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-EF00000000000000", + propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-EF00000000000000", }, }, { name: "zero trace ID and span ID", headers: map[string]string{ - propagation.B3SingleHeader: "00000000000000000000000000000000-0000000000000000-1", + propagators.B3SingleHeader: "00000000000000000000000000000000-0000000000000000-1", }, }, { name: "missing single header with valid separate headers", headers: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3SampledHeader: "1", }, }, { name: "upper case span ID with valid separate headers", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1", - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "00f067aa0ba902b7", - propagation.B3SampledHeader: "1", + propagators.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "00f067aa0ba902b7", + propagators.B3SampledHeader: "1", }, }, { name: "with sampling set to true", headers: map[string]string{ - propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-true", + propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-true", }, }, } @@ -450,12 +450,12 @@ var injectB3MultipleHeader = []injectTest{ TraceFlags: core.TraceFlagsSampled, }, wantHeaders: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "0000000000000001", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "0000000000000001", + propagators.B3SampledHeader: "1", }, doNotWantHeaders: []string{ - propagation.B3ParentSpanIDHeader, + propagators.B3ParentSpanIDHeader, }, }, { @@ -465,12 +465,12 @@ var injectB3MultipleHeader = []injectTest{ SpanID: spanID, }, wantHeaders: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "0000000000000002", - propagation.B3SampledHeader: "0", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "0000000000000002", + propagators.B3SampledHeader: "0", }, doNotWantHeaders: []string{ - propagation.B3ParentSpanIDHeader, + propagators.B3ParentSpanIDHeader, }, }, { @@ -481,12 +481,12 @@ var injectB3MultipleHeader = []injectTest{ TraceFlags: 0xff, }, wantHeaders: map[string]string{ - propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", - propagation.B3SpanIDHeader: "0000000000000003", - propagation.B3SampledHeader: "1", + propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", + propagators.B3SpanIDHeader: "0000000000000003", + propagators.B3SampledHeader: "1", }, doNotWantHeaders: []string{ - propagation.B3ParentSpanIDHeader, + propagators.B3ParentSpanIDHeader, }, }, } @@ -500,13 +500,13 @@ var injectB3SingleleHeader = []injectTest{ TraceFlags: core.TraceFlagsSampled, }, wantHeaders: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1", }, doNotWantHeaders: []string{ - propagation.B3TraceIDHeader, - propagation.B3SpanIDHeader, - propagation.B3SampledHeader, - propagation.B3ParentSpanIDHeader, + propagators.B3TraceIDHeader, + propagators.B3SpanIDHeader, + propagators.B3SampledHeader, + propagators.B3ParentSpanIDHeader, }, }, { @@ -516,13 +516,13 @@ var injectB3SingleleHeader = []injectTest{ SpanID: spanID, }, wantHeaders: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-0", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-0", }, doNotWantHeaders: []string{ - propagation.B3TraceIDHeader, - propagation.B3SpanIDHeader, - propagation.B3SampledHeader, - propagation.B3ParentSpanIDHeader, + propagators.B3TraceIDHeader, + propagators.B3SpanIDHeader, + propagators.B3SampledHeader, + propagators.B3ParentSpanIDHeader, }, }, { @@ -533,13 +533,13 @@ var injectB3SingleleHeader = []injectTest{ TraceFlags: 0xff, }, wantHeaders: map[string]string{ - propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000003-1", + propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000003-1", }, doNotWantHeaders: []string{ - propagation.B3TraceIDHeader, - propagation.B3SpanIDHeader, - propagation.B3SampledHeader, - propagation.B3ParentSpanIDHeader, + propagators.B3TraceIDHeader, + propagators.B3SpanIDHeader, + propagators.B3SampledHeader, + propagators.B3ParentSpanIDHeader, }, }, } diff --git a/propagation/b3_propagator_test.go b/api/propagators/b3_propagator_test.go similarity index 90% rename from propagation/b3_propagator_test.go rename to api/propagators/b3_propagator_test.go index df72cc60ae7..de17708324c 100644 --- a/propagation/b3_propagator_test.go +++ b/api/propagators/b3_propagator_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation_test +package propagators_test import ( "context" @@ -21,9 +21,9 @@ import ( "github.com/google/go-cmp/cmp" + "go.opentelemetry.io/otel/api/propagators" "go.opentelemetry.io/otel/api/trace" mocktrace "go.opentelemetry.io/otel/internal/trace" - "go.opentelemetry.io/otel/propagation" ) func TestExtractB3(t *testing.T) { @@ -55,7 +55,7 @@ func TestExtractB3(t *testing.T) { } for _, tg := range testGroup { - propagator := propagation.B3Propagator{tg.singleHeader} + propagator := propagators.B3{tg.singleHeader} for _, tt := range tg.tests { t.Run(tt.name, func(t *testing.T) { req, _ := http.NewRequest("GET", "http://example.com", nil) @@ -99,7 +99,7 @@ func TestInjectB3(t *testing.T) { for _, tg := range testGroup { id = 0 - propagator := propagation.B3Propagator{tg.singleHeader} + propagator := propagators.B3{tg.singleHeader} for _, tt := range tg.tests { t.Run(tt.name, func(t *testing.T) { req, _ := http.NewRequest("GET", "http://example.com", nil) @@ -131,11 +131,11 @@ func TestInjectB3(t *testing.T) { } func TestB3Propagator_GetAllKeys(t *testing.T) { - propagator := propagation.B3Propagator{false} + propagator := propagators.B3{false} want := []string{ - propagation.B3TraceIDHeader, - propagation.B3SpanIDHeader, - propagation.B3SampledHeader, + propagators.B3TraceIDHeader, + propagators.B3SpanIDHeader, + propagators.B3SampledHeader, } got := propagator.GetAllKeys() if diff := cmp.Diff(got, want); diff != "" { @@ -144,9 +144,9 @@ func TestB3Propagator_GetAllKeys(t *testing.T) { } func TestB3PropagatorWithSingleHeader_GetAllKeys(t *testing.T) { - propagator := propagation.B3Propagator{true} + propagator := propagators.B3{true} want := []string{ - propagation.B3SingleHeader, + propagators.B3SingleHeader, } got := propagator.GetAllKeys() if diff := cmp.Diff(got, want); diff != "" { diff --git a/propagation/binary_propagator.go b/api/propagators/binary_propagator.go similarity index 63% rename from propagation/binary_propagator.go rename to api/propagators/binary_propagator.go index e6108b26692..9a73c054b15 100644 --- a/propagation/binary_propagator.go +++ b/api/propagators/binary_propagator.go @@ -12,26 +12,35 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation +package propagators import ( "go.opentelemetry.io/otel/api/core" - apipropagation "go.opentelemetry.io/otel/api/propagation" ) -type binaryPropagator struct{} +// BinaryFormat is an interface that specifies methods to convert SpanContext +// to/from byte array. +type BinaryFormat interface { + // ToBytes serializes span context into a byte array and returns the array. + ToBytes(sc core.SpanContext) []byte -var _ apipropagation.BinaryFormatPropagator = binaryPropagator{} + // FromBytes de-serializes byte array into span context and returns the span context. + FromBytes([]byte) core.SpanContext +} + +var _ BinaryFormat = binary{} + +type binary struct{} -// BinaryPropagator creates a new propagator. The propagator implements +// Binary creates a new propagator. The propagator implements // ToBytes and FromBytes method to transform SpanContext to/from byte array. -func BinaryPropagator() apipropagation.BinaryFormatPropagator { - return binaryPropagator{} +func Binary() BinaryFormat { + return binary{} } -// ToBytes implements ToBytes method of propagation.BinaryFormatPropagator. +// ToBytes implements ToBytes method of propagators.BinaryFormat. // It serializes core.SpanContext into a byte array. -func (bp binaryPropagator) ToBytes(sc core.SpanContext) []byte { +func (bp binary) ToBytes(sc core.SpanContext) []byte { if sc == core.EmptySpanContext() { return nil } @@ -44,9 +53,9 @@ func (bp binaryPropagator) ToBytes(sc core.SpanContext) []byte { return b[:] } -// FromBytes implements FromBytes method of propagation.BinaryFormatPropagator. +// FromBytes implements FromBytes method of propagators.BinaryFormat. // It de-serializes bytes into core.SpanContext. -func (bp binaryPropagator) FromBytes(b []byte) (sc core.SpanContext) { +func (bp binary) FromBytes(b []byte) (sc core.SpanContext) { if len(b) == 0 { return core.EmptySpanContext() } diff --git a/propagation/binary_propagator_test.go b/api/propagators/binary_propagator_test.go similarity index 96% rename from propagation/binary_propagator_test.go rename to api/propagators/binary_propagator_test.go index 94f5e21ee8e..8f5d090b45a 100644 --- a/propagation/binary_propagator_test.go +++ b/api/propagators/binary_propagator_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation_test +package propagators_test import ( "testing" @@ -20,14 +20,14 @@ import ( "github.com/google/go-cmp/cmp" "go.opentelemetry.io/otel/api/core" - "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/api/propagators" ) func TestExtractSpanContextFromBytes(t *testing.T) { traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") - propagator := propagation.BinaryPropagator() + propagator := propagators.Binary() tests := []struct { name string bytes []byte @@ -123,7 +123,7 @@ func TestConvertSpanContextToBytes(t *testing.T) { traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") - propagator := propagation.BinaryPropagator() + propagator := propagators.Binary() tests := []struct { name string sc core.SpanContext diff --git a/api/propagation/doc.go b/api/propagators/doc.go similarity index 70% rename from api/propagation/doc.go rename to api/propagators/doc.go index 460d7fe97b3..5c7c9816941 100644 --- a/api/propagation/doc.go +++ b/api/propagators/doc.go @@ -12,5 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package propagation contains interface definition for Binary and TextFormat propagators. -package propagation // import "go.opentelemetry.io/otel/api/propagation" +// Package propagators contains interface definition for BinaryFormat and +// TextFormat propagators and implementation of propagators for different +// format and suppliers. +package propagators // import "go.opentelemetry.io/otel/api/propagators" diff --git a/api/propagation/noop_propagator.go b/api/propagators/text_noop_propagator.go similarity index 67% rename from api/propagation/noop_propagator.go rename to api/propagators/text_noop_propagator.go index 77576b2cfa6..85429712118 100644 --- a/api/propagation/noop_propagator.go +++ b/api/propagators/text_noop_propagator.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation +package propagators import ( "context" @@ -21,21 +21,21 @@ import ( dctx "go.opentelemetry.io/otel/api/distributedcontext" ) -// NoopTextFormatPropagator implements TextFormatPropagator that does nothing. -type NoopTextFormatPropagator struct{} +// NoopTextFormat implements TextFormat that does nothing. +type NoopTextFormat struct{} -var _ TextFormatPropagator = NoopTextFormatPropagator{} +var _ TextFormat = NoopTextFormat{} // Inject does nothing. -func (np NoopTextFormatPropagator) Inject(ctx context.Context, supplier Supplier) { +func (np NoopTextFormat) Inject(ctx context.Context, supplier Supplier) { } // Extract does nothing and returns an empty SpanContext -func (np NoopTextFormatPropagator) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map) { +func (np NoopTextFormat) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map) { return core.EmptySpanContext(), dctx.NewEmptyMap() } // GetAllKeys returns empty list of strings. -func (np NoopTextFormatPropagator) GetAllKeys() []string { +func (np NoopTextFormat) GetAllKeys() []string { return []string{} } diff --git a/api/propagation/propagator.go b/api/propagators/text_propagator.go similarity index 80% rename from api/propagation/propagator.go rename to api/propagators/text_propagator.go index ddefe1f8b05..c39c835c595 100644 --- a/api/propagation/propagator.go +++ b/api/propagators/text_propagator.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation +package propagators import ( "context" @@ -21,11 +21,11 @@ import ( dctx "go.opentelemetry.io/otel/api/distributedcontext" ) -// TextFormatPropagator is an interface that specifies methods to inject and extract SpanContext +// TextFormat is an interface that specifies methods to inject and extract SpanContext // and distributed context into/from a carrier using Supplier interface. // For example, HTTP Trace Context propagator would encode SpanContext into W3C Trace // Context Header and set the header into HttpRequest. -type TextFormatPropagator interface { +type TextFormat interface { // Inject method retrieves current SpanContext from the ctx, encodes it into propagator // specific format and then injects the encoded SpanContext using supplier into a carrier // associated with the supplier. It also takes a correlationCtx whose values will be @@ -53,13 +53,3 @@ type Supplier interface { Get(key string) string Set(key string, value string) } - -// BinaryFormatPropagator is an interface that specifies methods to convert SpanContext -// to/from byte array. -type BinaryFormatPropagator interface { - // ToBytes serializes span context into a byte array and returns the array. - ToBytes(sc core.SpanContext) []byte - - // FromBytes de-serializes byte array into span context and returns the span context. - FromBytes([]byte) core.SpanContext -} diff --git a/propagation/trace_context_propagator.go b/api/propagators/trace_context_propagator.go similarity index 86% rename from propagation/trace_context_propagator.go rename to api/propagators/trace_context_propagator.go index e09b318be11..91440bccc02 100644 --- a/propagation/trace_context_propagator.go +++ b/api/propagators/trace_context_propagator.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation +package propagators import ( "context" @@ -25,7 +25,6 @@ import ( "go.opentelemetry.io/otel/api/core" dctx "go.opentelemetry.io/otel/api/distributedcontext" "go.opentelemetry.io/otel/api/key" - apipropagation "go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/trace" ) @@ -36,13 +35,13 @@ const ( CorrelationContextHeader = "Correlation-Context" ) -// TraceContextPropagator propagates SpanContext in W3C TraceContext format. -type TraceContextPropagator struct{} +// TraceContext propagates SpanContext in W3C TraceContext format. +type TraceContext struct{} -var _ apipropagation.TextFormatPropagator = TraceContextPropagator{} +var _ TextFormat = TraceContext{} var traceCtxRegExp = regexp.MustCompile("^[0-9a-f]{2}-[a-f0-9]{32}-[a-f0-9]{16}-[a-f0-9]{2}-?") -func (hp TraceContextPropagator) Inject(ctx context.Context, supplier apipropagation.Supplier) { +func (hp TraceContext) Inject(ctx context.Context, supplier Supplier) { sc := trace.CurrentSpan(ctx).SpanContext() if sc.IsValid() { h := fmt.Sprintf("%.2x-%s-%.16x-%.2x", @@ -72,14 +71,14 @@ func (hp TraceContextPropagator) Inject(ctx context.Context, supplier apipropaga } } -func (hp TraceContextPropagator) Extract( - ctx context.Context, supplier apipropagation.Supplier, +func (hp TraceContext) Extract( + ctx context.Context, supplier Supplier, ) (core.SpanContext, dctx.Map) { return hp.extractSpanContext(ctx, supplier), hp.extractCorrelationCtx(ctx, supplier) } -func (hp TraceContextPropagator) extractSpanContext( - ctx context.Context, supplier apipropagation.Supplier, +func (hp TraceContext) extractSpanContext( + ctx context.Context, supplier Supplier, ) core.SpanContext { h := supplier.Get(TraceparentHeader) if h == "" { @@ -147,7 +146,7 @@ func (hp TraceContextPropagator) extractSpanContext( return sc } -func (hp TraceContextPropagator) extractCorrelationCtx(ctx context.Context, supplier apipropagation.Supplier) dctx.Map { +func (hp TraceContext) extractCorrelationCtx(ctx context.Context, supplier Supplier) dctx.Map { correlationContext := supplier.Get(CorrelationContextHeader) if correlationContext == "" { return dctx.NewEmptyMap() @@ -191,6 +190,6 @@ func (hp TraceContextPropagator) extractCorrelationCtx(ctx context.Context, supp }) } -func (hp TraceContextPropagator) GetAllKeys() []string { +func (hp TraceContext) GetAllKeys() []string { return []string{TraceparentHeader, CorrelationContextHeader} } diff --git a/propagation/trace_context_propagator_benchmark_test.go b/api/propagators/trace_context_propagator_benchmark_test.go similarity index 96% rename from propagation/trace_context_propagator_benchmark_test.go rename to api/propagators/trace_context_propagator_benchmark_test.go index aeb577a0d62..7086b281072 100644 --- a/propagation/trace_context_propagator_benchmark_test.go +++ b/api/propagators/trace_context_propagator_benchmark_test.go @@ -1,4 +1,4 @@ -package propagation +package propagators import ( "context" @@ -11,7 +11,7 @@ import ( ) func BenchmarkInject(b *testing.B) { - var t TraceContextPropagator + var t TraceContext injectSubBenchmarks(b, func(ctx context.Context, b *testing.B) { req, _ := http.NewRequest("GET", "http://example.com", nil) @@ -52,7 +52,7 @@ func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) { func BenchmarkExtract(b *testing.B) { extractSubBenchmarks(b, func(b *testing.B, req *http.Request) { - var propagator TraceContextPropagator + var propagator TraceContext ctx := context.Background() b.ResetTimer() for i := 0; i < b.N; i++ { diff --git a/propagation/trace_context_propagator_test.go b/api/propagators/trace_context_propagator_test.go similarity index 96% rename from propagation/trace_context_propagator_test.go rename to api/propagators/trace_context_propagator_test.go index 34fa4874151..e9ffcd6aeb1 100644 --- a/propagation/trace_context_propagator_test.go +++ b/api/propagators/trace_context_propagator_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package propagation_test +package propagators_test import ( "context" @@ -25,9 +25,9 @@ import ( "go.opentelemetry.io/otel/api/core" dctx "go.opentelemetry.io/otel/api/distributedcontext" "go.opentelemetry.io/otel/api/key" + "go.opentelemetry.io/otel/api/propagators" "go.opentelemetry.io/otel/api/trace" mocktrace "go.opentelemetry.io/otel/internal/trace" - "go.opentelemetry.io/otel/propagation" ) var ( @@ -46,7 +46,7 @@ func mustSpanIDFromHex(s string) (t core.SpanID) { } func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { - var propagator propagation.TraceContextPropagator + var propagator propagators.TraceContext tests := []struct { name string header string @@ -139,7 +139,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { } func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) { - var propagator propagation.TraceContextPropagator + var propagator propagators.TraceContext wantSc := core.EmptySpanContext() tests := []struct { name string @@ -231,7 +231,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { Sampled: false, StartSpanID: &id, } - var propagator propagation.TraceContextPropagator + var propagator propagators.TraceContext tests := []struct { name string sc core.SpanContext @@ -287,7 +287,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { } func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) { - propagator := propagation.TraceContextPropagator{} + propagator := propagators.TraceContext{} tests := []struct { name string header string @@ -375,7 +375,7 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) { } func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { - propagator := propagation.TraceContextPropagator{} + propagator := propagators.TraceContext{} tests := []struct { name string header string @@ -401,7 +401,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) { } func TestInjectCorrelationContextToHTTPReq(t *testing.T) { - propagator := propagation.TraceContextPropagator{} + propagator := propagators.TraceContext{} tests := []struct { name string kvs []core.KeyValue @@ -475,7 +475,7 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) { } func TestTraceContextPropagator_GetAllKeys(t *testing.T) { - var propagator propagation.TraceContextPropagator + var propagator propagators.TraceContext want := []string{"Traceparent", "Correlation-Context"} got := propagator.GetAllKeys() if diff := cmp.Diff(got, want); diff != "" { diff --git a/plugin/grpctrace/grpctrace.go b/plugin/grpctrace/grpctrace.go index 29ed46abd6c..0f87b1bf2b7 100644 --- a/plugin/grpctrace/grpctrace.go +++ b/plugin/grpctrace/grpctrace.go @@ -21,7 +21,7 @@ import ( "google.golang.org/grpc/metadata" "go.opentelemetry.io/otel/api/core" - "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/api/propagators" ) const ( @@ -30,7 +30,7 @@ const ( ) var ( - propagator = propagation.TraceContextPropagator{} + propagator = propagators.TraceContext{} ) type metadataSupplier struct { diff --git a/plugin/httptrace/httptrace.go b/plugin/httptrace/httptrace.go index 3cff96eebcc..398b25e87ff 100644 --- a/plugin/httptrace/httptrace.go +++ b/plugin/httptrace/httptrace.go @@ -20,7 +20,7 @@ import ( "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/key" - "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/api/propagators" ) const ( @@ -31,7 +31,7 @@ var ( HostKey = key.New("http.host") URLKey = key.New("http.url") - propagator = propagation.TraceContextPropagator{} + propagator = propagators.TraceContext{} ) // Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject. diff --git a/plugin/othttp/handler.go b/plugin/othttp/handler.go index 5dbba8ec78e..11d1454d123 100644 --- a/plugin/othttp/handler.go +++ b/plugin/othttp/handler.go @@ -20,9 +20,8 @@ import ( "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/global" - "go.opentelemetry.io/otel/api/propagation" + "go.opentelemetry.io/otel/api/propagators" "go.opentelemetry.io/otel/api/trace" - prop "go.opentelemetry.io/otel/propagation" ) var _ http.Handler = &Handler{} @@ -51,7 +50,7 @@ type Handler struct { handler http.Handler tracer trace.Tracer - prop propagation.TextFormatPropagator + prop propagators.TextFormat spanOptions []trace.SpanOption public bool readEvent bool @@ -80,8 +79,8 @@ func WithPublicEndpoint() Option { // WithPropagator configures the Handler with a specific propagator. If this // option isn't specificed then -// go.opentelemetry.io/otel/propagation.TraceContextPropagator is used. -func WithPropagator(p propagation.TextFormatPropagator) Option { +// go.opentelemetry.io/otel/api/propagators.TraceContext is used. +func WithPropagator(p propagators.TextFormat) Option { return func(h *Handler) { h.prop = p } @@ -131,7 +130,7 @@ func NewHandler(handler http.Handler, operation string, opts ...Option) http.Han h := Handler{handler: handler, operation: operation} defaultOpts := []Option{ WithTracer(global.TraceProvider().Tracer("go.opentelemetry.io/plugin/othttp")), - WithPropagator(prop.TraceContextPropagator{}), + WithPropagator(propagators.TraceContext{}), WithSpanOptions(trace.WithSpanKind(trace.SpanKindServer)), } diff --git a/plugin/othttp/handler_test.go b/plugin/othttp/handler_test.go index cf902133a0e..4bc645d10f3 100644 --- a/plugin/othttp/handler_test.go +++ b/plugin/othttp/handler_test.go @@ -20,7 +20,7 @@ import ( "net/http/httptest" "testing" - "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/api/propagators" mocktrace "go.opentelemetry.io/otel/internal/trace" ) @@ -47,7 +47,7 @@ func TestBasics(t *testing.T) { if got, expected := rr.Result().StatusCode, http.StatusOK; got != expected { t.Fatalf("got %d, expected %d", got, expected) } - if got := rr.Header().Get(propagation.TraceparentHeader); got == "" { + if got := rr.Header().Get(propagators.TraceparentHeader); got == "" { t.Fatal("expected non empty trace header") } if got, expected := id, uint64(1); got != expected { diff --git a/plugin/othttp/wrap.go b/plugin/othttp/wrap.go index 171eb2afddc..95b3ec6bfe4 100644 --- a/plugin/othttp/wrap.go +++ b/plugin/othttp/wrap.go @@ -19,7 +19,7 @@ import ( "io" "net/http" - "go.opentelemetry.io/otel/api/propagation" + "go.opentelemetry.io/otel/api/propagators" ) var _ io.ReadCloser = &bodyWrapper{} @@ -50,7 +50,7 @@ func (w *bodyWrapper) Close() error { var _ http.ResponseWriter = &respWriterWrapper{} type injector interface { - Inject(context.Context, propagation.Supplier) + Inject(context.Context, propagators.Supplier) } // respWriterWrapper wraps a http.ResponseWriter in order to track the number of diff --git a/propagation/doc.go b/propagation/doc.go deleted file mode 100644 index 78315a8b40f..00000000000 --- a/propagation/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// 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 contains propagators for different format and carriers. -package propagation // import "go.opentelemetry.io/otel/propagation"