You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-17 01:12:45 +02:00
Merge propagation and api/propagation into api/propagators (#362)
* Merge propagation Rename and merge propagation and api/propagation to api/propagators. Drop propagator suffix in general such that TextFormatPropagator becomes TextFormat since usage is propagators.TextFormat fixes #311 * Rebase and godoc updates * Revert go mod changes * Replace carrier with supplier in godoc
This commit is contained in:
@ -12,18 +12,16 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation
|
package propagators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
||||||
apipropagation "go.opentelemetry.io/otel/api/propagation"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -35,8 +33,7 @@ const (
|
|||||||
B3ParentSpanIDHeader = "X-B3-ParentSpanId"
|
B3ParentSpanIDHeader = "X-B3-ParentSpanId"
|
||||||
)
|
)
|
||||||
|
|
||||||
// B3Propagator that facilitates core.SpanContext
|
// B3 propagator serializes core.SpanContext to/from B3 Headers.
|
||||||
// propagation using B3 Headers.
|
|
||||||
// This propagator supports both version of B3 headers,
|
// This propagator supports both version of B3 headers,
|
||||||
// 1. Single Header :
|
// 1. Single Header :
|
||||||
// X-B3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
// 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,
|
// 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.
|
// separate headers are used to inject and extract.
|
||||||
type B3Propagator struct {
|
type B3 struct {
|
||||||
SingleHeader bool
|
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()
|
sc := trace.CurrentSpan(ctx).SpanContext()
|
||||||
if sc.IsValid() {
|
if sc.IsValid() {
|
||||||
if b3.SingleHeader {
|
if b3.SingleHeader {
|
||||||
@ -79,21 +76,21 @@ func (b3 B3Propagator) Inject(ctx context.Context, supplier apipropagation.Suppl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract retrieves B3 Headers from the supplier
|
// 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 {
|
if b3.SingleHeader {
|
||||||
return b3.extractSingleHeader(supplier), dctx.NewEmptyMap()
|
return b3.extractSingleHeader(supplier), dctx.NewEmptyMap()
|
||||||
}
|
}
|
||||||
return b3.extract(supplier), dctx.NewEmptyMap()
|
return b3.extract(supplier), dctx.NewEmptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b3 B3Propagator) GetAllKeys() []string {
|
func (b3 B3) GetAllKeys() []string {
|
||||||
if b3.SingleHeader {
|
if b3.SingleHeader {
|
||||||
return []string{B3SingleHeader}
|
return []string{B3SingleHeader}
|
||||||
}
|
}
|
||||||
return []string{B3TraceIDHeader, B3SpanIDHeader, B3SampledHeader}
|
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))
|
tid, err := core.TraceIDFromHex(supplier.Get(B3TraceIDHeader))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return core.EmptySpanContext()
|
return core.EmptySpanContext()
|
||||||
@ -128,7 +125,7 @@ func (b3 B3Propagator) extract(supplier apipropagation.Supplier) core.SpanContex
|
|||||||
return sc
|
return sc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b3 B3Propagator) extractSingleHeader(supplier apipropagation.Supplier) core.SpanContext {
|
func (b3 B3) extractSingleHeader(supplier Supplier) core.SpanContext {
|
||||||
h := supplier.Get(B3SingleHeader)
|
h := supplier.Get(B3SingleHeader)
|
||||||
if h == "" || h == "0" {
|
if h == "" || h == "0" {
|
||||||
core.EmptySpanContext()
|
core.EmptySpanContext()
|
||||||
@ -177,7 +174,7 @@ func (b3 B3Propagator) extractSingleHeader(supplier apipropagation.Supplier) cor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// extractSampledState parses the value of the X-B3-Sampled b3Header.
|
// 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 {
|
switch sampled {
|
||||||
case "", "0":
|
case "", "0":
|
||||||
return 0, true
|
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.
|
// 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 {
|
switch debug {
|
||||||
case "", "0":
|
case "", "0":
|
||||||
return 0, true
|
return 0, true
|
@ -12,16 +12,16 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation_test
|
package propagators_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkExtractB3(b *testing.B) {
|
func BenchmarkExtractB3(b *testing.B) {
|
||||||
@ -53,7 +53,7 @@ func BenchmarkExtractB3(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
propagator := propagators.B3{tg.singleHeader}
|
||||||
for _, tt := range tg.tests {
|
for _, tt := range tg.tests {
|
||||||
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -97,7 +97,7 @@ func BenchmarkInjectB3(b *testing.B) {
|
|||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
id = 0
|
id = 0
|
||||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
propagator := propagators.B3{tg.singleHeader}
|
||||||
for _, tt := range tg.tests {
|
for _, tt := range tg.tests {
|
||||||
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
||||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
@ -12,11 +12,11 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation_test
|
package propagators_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
)
|
)
|
||||||
|
|
||||||
type extractTest struct {
|
type extractTest struct {
|
||||||
@ -29,8 +29,8 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state defer",
|
name: "sampling state defer",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -40,9 +40,9 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state deny",
|
name: "sampling state deny",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3SampledHeader: "0",
|
propagators.B3SampledHeader: "0",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -52,9 +52,9 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state accept",
|
name: "sampling state accept",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -65,9 +65,9 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state as a boolean",
|
name: "sampling state as a boolean",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3SampledHeader: "true",
|
propagators.B3SampledHeader: "true",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -78,9 +78,9 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "debug flag set",
|
name: "debug flag set",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3DebugFlagHeader: "1",
|
propagators.B3DebugFlagHeader: "1",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -94,10 +94,10 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
// takes precedence. Hence, it is sampled.
|
// takes precedence. Hence, it is sampled.
|
||||||
name: "debug flag set and sampling state is deny",
|
name: "debug flag set and sampling state is deny",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3SampledHeader: "0",
|
propagators.B3SampledHeader: "0",
|
||||||
propagation.B3DebugFlagHeader: "1",
|
propagators.B3DebugFlagHeader: "1",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -108,10 +108,10 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "with parent span id",
|
name: "with parent span id",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
propagation.B3ParentSpanIDHeader: "00f067aa0ba90200",
|
propagators.B3ParentSpanIDHeader: "00f067aa0ba90200",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -122,7 +122,7 @@ var extractMultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "with only sampled state header",
|
name: "with only sampled state header",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SampledHeader: "0",
|
propagators.B3SampledHeader: "0",
|
||||||
},
|
},
|
||||||
wantSc: core.EmptySpanContext(),
|
wantSc: core.EmptySpanContext(),
|
||||||
},
|
},
|
||||||
@ -132,7 +132,7 @@ var extractSingleHeader = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state defer",
|
name: "sampling state defer",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -142,7 +142,7 @@ var extractSingleHeader = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state deny",
|
name: "sampling state deny",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -152,7 +152,7 @@ var extractSingleHeader = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state accept",
|
name: "sampling state accept",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -163,7 +163,7 @@ var extractSingleHeader = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "sampling state debug",
|
name: "sampling state debug",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -174,7 +174,7 @@ var extractSingleHeader = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "with parent span id",
|
name: "with parent span id",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd",
|
||||||
},
|
},
|
||||||
wantSc: core.SpanContext{
|
wantSc: core.SpanContext{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
@ -185,7 +185,7 @@ var extractSingleHeader = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "with only sampling state deny",
|
name: "with only sampling state deny",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "0",
|
propagators.B3SingleHeader: "0",
|
||||||
},
|
},
|
||||||
wantSc: core.EmptySpanContext(),
|
wantSc: core.EmptySpanContext(),
|
||||||
},
|
},
|
||||||
@ -195,143 +195,143 @@ var extractInvalidB3MultipleHeaders = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "trace ID length > 32",
|
name: "trace ID length > 32",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab00000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab00000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "trace ID length >16 and <32",
|
name: "trace ID length >16 and <32",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab0000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab0000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "trace ID length <16",
|
name: "trace ID length <16",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab0000000000",
|
propagators.B3TraceIDHeader: "ab0000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong span ID length",
|
name: "wrong span ID length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd0000000000000000",
|
propagators.B3SpanIDHeader: "cd0000000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong sampled flag length",
|
name: "wrong sampled flag length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "10",
|
propagators.B3SampledHeader: "10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus trace ID",
|
name: "bogus trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "qw000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "qw000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus span ID",
|
name: "bogus span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "qw00000000000000",
|
propagators.B3SpanIDHeader: "qw00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus sampled flag",
|
name: "bogus sampled flag",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "d",
|
propagators.B3SampledHeader: "d",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus debug flag (string)",
|
name: "bogus debug flag (string)",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
propagation.B3DebugFlagHeader: "d",
|
propagators.B3DebugFlagHeader: "d",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus debug flag (number)",
|
name: "bogus debug flag (number)",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
propagation.B3DebugFlagHeader: "10",
|
propagators.B3DebugFlagHeader: "10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case trace ID",
|
name: "upper case trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "AB000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "AB000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case span ID",
|
name: "upper case span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "CD00000000000000",
|
propagators.B3SpanIDHeader: "CD00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero trace ID",
|
name: "zero trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "00000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "00000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero span ID",
|
name: "zero span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SpanIDHeader: "0000000000000000",
|
propagators.B3SpanIDHeader: "0000000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing span ID",
|
name: "missing span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "ab000000000000000000000000000000",
|
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing trace ID",
|
name: "missing trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing trace ID with valid single header",
|
name: "missing trace ID with valid single header",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
|
||||||
propagation.B3SpanIDHeader: "cd00000000000000",
|
propagators.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "sampled header set to 1 but trace ID and span ID are missing",
|
name: "sampled header set to 1 but trace ID and span ID are missing",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -340,96 +340,96 @@ var extractInvalidB3SingleHeader = []extractTest{
|
|||||||
{
|
{
|
||||||
name: "wrong trace ID length",
|
name: "wrong trace ID length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab00000000000000000000000000000000-cd00000000000000-1",
|
propagators.B3SingleHeader: "ab00000000000000000000000000000000-cd00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong span ID length",
|
name: "wrong span ID length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-cd0000000000000000-1",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd0000000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong sampled state length",
|
name: "wrong sampled state length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "00-ab000000000000000000000000000000-cd00000000000000-01",
|
propagators.B3SingleHeader: "00-ab000000000000000000000000000000-cd00000000000000-01",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong parent span ID length",
|
name: "wrong parent span ID length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-cd0000000000000000",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-cd0000000000000000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus trace ID",
|
name: "bogus trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "qw000000000000000000000000000000-cd00000000000000-1",
|
propagators.B3SingleHeader: "qw000000000000000000000000000000-cd00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus span ID",
|
name: "bogus span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-qw00000000000000-1",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-qw00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus sampled flag",
|
name: "bogus sampled flag",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-q",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-q",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus parent span ID",
|
name: "bogus parent span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-qw00000000000000",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-qw00000000000000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case trace ID",
|
name: "upper case trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "AB000000000000000000000000000000-cd00000000000000-1",
|
propagators.B3SingleHeader: "AB000000000000000000000000000000-cd00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case span ID",
|
name: "upper case span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case parent span ID",
|
name: "upper case parent span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-EF00000000000000",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-EF00000000000000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero trace ID and span ID",
|
name: "zero trace ID and span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "00000000000000000000000000000000-0000000000000000-1",
|
propagators.B3SingleHeader: "00000000000000000000000000000000-0000000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing single header with valid separate headers",
|
name: "missing single header with valid separate headers",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case span ID with valid separate headers",
|
name: "upper case span ID with valid separate headers",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "00f067aa0ba902b7",
|
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with sampling set to true",
|
name: "with sampling set to true",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagation.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-true",
|
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-true",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -450,12 +450,12 @@ var injectB3MultipleHeader = []injectTest{
|
|||||||
TraceFlags: core.TraceFlagsSampled,
|
TraceFlags: core.TraceFlagsSampled,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "0000000000000001",
|
propagators.B3SpanIDHeader: "0000000000000001",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagation.B3ParentSpanIDHeader,
|
propagators.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -465,12 +465,12 @@ var injectB3MultipleHeader = []injectTest{
|
|||||||
SpanID: spanID,
|
SpanID: spanID,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "0000000000000002",
|
propagators.B3SpanIDHeader: "0000000000000002",
|
||||||
propagation.B3SampledHeader: "0",
|
propagators.B3SampledHeader: "0",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagation.B3ParentSpanIDHeader,
|
propagators.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -481,12 +481,12 @@ var injectB3MultipleHeader = []injectTest{
|
|||||||
TraceFlags: 0xff,
|
TraceFlags: 0xff,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagation.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagation.B3SpanIDHeader: "0000000000000003",
|
propagators.B3SpanIDHeader: "0000000000000003",
|
||||||
propagation.B3SampledHeader: "1",
|
propagators.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagation.B3ParentSpanIDHeader,
|
propagators.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -500,13 +500,13 @@ var injectB3SingleleHeader = []injectTest{
|
|||||||
TraceFlags: core.TraceFlagsSampled,
|
TraceFlags: core.TraceFlagsSampled,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagation.B3TraceIDHeader,
|
propagators.B3TraceIDHeader,
|
||||||
propagation.B3SpanIDHeader,
|
propagators.B3SpanIDHeader,
|
||||||
propagation.B3SampledHeader,
|
propagators.B3SampledHeader,
|
||||||
propagation.B3ParentSpanIDHeader,
|
propagators.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -516,13 +516,13 @@ var injectB3SingleleHeader = []injectTest{
|
|||||||
SpanID: spanID,
|
SpanID: spanID,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-0",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-0",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagation.B3TraceIDHeader,
|
propagators.B3TraceIDHeader,
|
||||||
propagation.B3SpanIDHeader,
|
propagators.B3SpanIDHeader,
|
||||||
propagation.B3SampledHeader,
|
propagators.B3SampledHeader,
|
||||||
propagation.B3ParentSpanIDHeader,
|
propagators.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -533,13 +533,13 @@ var injectB3SingleleHeader = []injectTest{
|
|||||||
TraceFlags: 0xff,
|
TraceFlags: 0xff,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagation.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000003-1",
|
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000003-1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagation.B3TraceIDHeader,
|
propagators.B3TraceIDHeader,
|
||||||
propagation.B3SpanIDHeader,
|
propagators.B3SpanIDHeader,
|
||||||
propagation.B3SampledHeader,
|
propagators.B3SampledHeader,
|
||||||
propagation.B3ParentSpanIDHeader,
|
propagators.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation_test
|
package propagators_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -21,9 +21,9 @@ import (
|
|||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExtractB3(t *testing.T) {
|
func TestExtractB3(t *testing.T) {
|
||||||
@ -55,7 +55,7 @@ func TestExtractB3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
propagator := propagators.B3{tg.singleHeader}
|
||||||
for _, tt := range tg.tests {
|
for _, tt := range tg.tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||||
@ -99,7 +99,7 @@ func TestInjectB3(t *testing.T) {
|
|||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
id = 0
|
id = 0
|
||||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
propagator := propagators.B3{tg.singleHeader}
|
||||||
for _, tt := range tg.tests {
|
for _, tt := range tg.tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||||
@ -131,11 +131,11 @@ func TestInjectB3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestB3Propagator_GetAllKeys(t *testing.T) {
|
func TestB3Propagator_GetAllKeys(t *testing.T) {
|
||||||
propagator := propagation.B3Propagator{false}
|
propagator := propagators.B3{false}
|
||||||
want := []string{
|
want := []string{
|
||||||
propagation.B3TraceIDHeader,
|
propagators.B3TraceIDHeader,
|
||||||
propagation.B3SpanIDHeader,
|
propagators.B3SpanIDHeader,
|
||||||
propagation.B3SampledHeader,
|
propagators.B3SampledHeader,
|
||||||
}
|
}
|
||||||
got := propagator.GetAllKeys()
|
got := propagator.GetAllKeys()
|
||||||
if diff := cmp.Diff(got, want); diff != "" {
|
if diff := cmp.Diff(got, want); diff != "" {
|
||||||
@ -144,9 +144,9 @@ func TestB3Propagator_GetAllKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestB3PropagatorWithSingleHeader_GetAllKeys(t *testing.T) {
|
func TestB3PropagatorWithSingleHeader_GetAllKeys(t *testing.T) {
|
||||||
propagator := propagation.B3Propagator{true}
|
propagator := propagators.B3{true}
|
||||||
want := []string{
|
want := []string{
|
||||||
propagation.B3SingleHeader,
|
propagators.B3SingleHeader,
|
||||||
}
|
}
|
||||||
got := propagator.GetAllKeys()
|
got := propagator.GetAllKeys()
|
||||||
if diff := cmp.Diff(got, want); diff != "" {
|
if diff := cmp.Diff(got, want); diff != "" {
|
@ -12,26 +12,35 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation
|
package propagators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"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
|
||||||
// BinaryPropagator creates a new propagator. The propagator implements
|
|
||||||
// ToBytes and FromBytes method to transform SpanContext to/from byte array.
|
|
||||||
func BinaryPropagator() apipropagation.BinaryFormatPropagator {
|
|
||||||
return binaryPropagator{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToBytes implements ToBytes method of propagation.BinaryFormatPropagator.
|
var _ BinaryFormat = binary{}
|
||||||
|
|
||||||
|
type binary struct{}
|
||||||
|
|
||||||
|
// Binary creates a new propagator. The propagator implements
|
||||||
|
// ToBytes and FromBytes method to transform SpanContext to/from byte array.
|
||||||
|
func Binary() BinaryFormat {
|
||||||
|
return binary{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToBytes implements ToBytes method of propagators.BinaryFormat.
|
||||||
// It serializes core.SpanContext into a byte array.
|
// 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() {
|
if sc == core.EmptySpanContext() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -44,9 +53,9 @@ func (bp binaryPropagator) ToBytes(sc core.SpanContext) []byte {
|
|||||||
return b[:]
|
return b[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromBytes implements FromBytes method of propagation.BinaryFormatPropagator.
|
// FromBytes implements FromBytes method of propagators.BinaryFormat.
|
||||||
// It de-serializes bytes into core.SpanContext.
|
// 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 {
|
if len(b) == 0 {
|
||||||
return core.EmptySpanContext()
|
return core.EmptySpanContext()
|
||||||
}
|
}
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation_test
|
package propagators_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -20,14 +20,14 @@ import (
|
|||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExtractSpanContextFromBytes(t *testing.T) {
|
func TestExtractSpanContextFromBytes(t *testing.T) {
|
||||||
traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
||||||
spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7")
|
spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7")
|
||||||
|
|
||||||
propagator := propagation.BinaryPropagator()
|
propagator := propagators.Binary()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
bytes []byte
|
bytes []byte
|
||||||
@ -123,7 +123,7 @@ func TestConvertSpanContextToBytes(t *testing.T) {
|
|||||||
traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
||||||
spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7")
|
spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7")
|
||||||
|
|
||||||
propagator := propagation.BinaryPropagator()
|
propagator := propagators.Binary()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
sc core.SpanContext
|
sc core.SpanContext
|
@ -12,5 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Package propagation contains interface definition for Binary and TextFormat propagators.
|
// Package propagators contains interface definition for BinaryFormat and
|
||||||
package propagation // import "go.opentelemetry.io/otel/api/propagation"
|
// TextFormat propagators and implementation of propagators for different
|
||||||
|
// format and suppliers.
|
||||||
|
package propagators // import "go.opentelemetry.io/otel/api/propagators"
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation
|
package propagators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -21,21 +21,21 @@ import (
|
|||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NoopTextFormatPropagator implements TextFormatPropagator that does nothing.
|
// NoopTextFormat implements TextFormat that does nothing.
|
||||||
type NoopTextFormatPropagator struct{}
|
type NoopTextFormat struct{}
|
||||||
|
|
||||||
var _ TextFormatPropagator = NoopTextFormatPropagator{}
|
var _ TextFormat = NoopTextFormat{}
|
||||||
|
|
||||||
// Inject does nothing.
|
// 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
|
// 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()
|
return core.EmptySpanContext(), dctx.NewEmptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllKeys returns empty list of strings.
|
// GetAllKeys returns empty list of strings.
|
||||||
func (np NoopTextFormatPropagator) GetAllKeys() []string {
|
func (np NoopTextFormat) GetAllKeys() []string {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation
|
package propagators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -21,11 +21,11 @@ import (
|
|||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
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.
|
// and distributed context into/from a carrier using Supplier interface.
|
||||||
// For example, HTTP Trace Context propagator would encode SpanContext into W3C Trace
|
// For example, HTTP Trace Context propagator would encode SpanContext into W3C Trace
|
||||||
// Context Header and set the header into HttpRequest.
|
// 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
|
// 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
|
// 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
|
// associated with the supplier. It also takes a correlationCtx whose values will be
|
||||||
@ -53,13 +53,3 @@ type Supplier interface {
|
|||||||
Get(key string) string
|
Get(key string) string
|
||||||
Set(key string, value 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
|
|
||||||
}
|
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation
|
package propagators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -25,7 +25,6 @@ import (
|
|||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
apipropagation "go.opentelemetry.io/otel/api/propagation"
|
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,13 +35,13 @@ const (
|
|||||||
CorrelationContextHeader = "Correlation-Context"
|
CorrelationContextHeader = "Correlation-Context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TraceContextPropagator propagates SpanContext in W3C TraceContext format.
|
// TraceContext propagates SpanContext in W3C TraceContext format.
|
||||||
type TraceContextPropagator struct{}
|
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}-?")
|
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()
|
sc := trace.CurrentSpan(ctx).SpanContext()
|
||||||
if sc.IsValid() {
|
if sc.IsValid() {
|
||||||
h := fmt.Sprintf("%.2x-%s-%.16x-%.2x",
|
h := fmt.Sprintf("%.2x-%s-%.16x-%.2x",
|
||||||
@ -72,14 +71,14 @@ func (hp TraceContextPropagator) Inject(ctx context.Context, supplier apipropaga
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hp TraceContextPropagator) Extract(
|
func (hp TraceContext) Extract(
|
||||||
ctx context.Context, supplier apipropagation.Supplier,
|
ctx context.Context, supplier Supplier,
|
||||||
) (core.SpanContext, dctx.Map) {
|
) (core.SpanContext, dctx.Map) {
|
||||||
return hp.extractSpanContext(ctx, supplier), hp.extractCorrelationCtx(ctx, supplier)
|
return hp.extractSpanContext(ctx, supplier), hp.extractCorrelationCtx(ctx, supplier)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hp TraceContextPropagator) extractSpanContext(
|
func (hp TraceContext) extractSpanContext(
|
||||||
ctx context.Context, supplier apipropagation.Supplier,
|
ctx context.Context, supplier Supplier,
|
||||||
) core.SpanContext {
|
) core.SpanContext {
|
||||||
h := supplier.Get(TraceparentHeader)
|
h := supplier.Get(TraceparentHeader)
|
||||||
if h == "" {
|
if h == "" {
|
||||||
@ -147,7 +146,7 @@ func (hp TraceContextPropagator) extractSpanContext(
|
|||||||
return sc
|
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)
|
correlationContext := supplier.Get(CorrelationContextHeader)
|
||||||
if correlationContext == "" {
|
if correlationContext == "" {
|
||||||
return dctx.NewEmptyMap()
|
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}
|
return []string{TraceparentHeader, CorrelationContextHeader}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package propagation
|
package propagators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkInject(b *testing.B) {
|
func BenchmarkInject(b *testing.B) {
|
||||||
var t TraceContextPropagator
|
var t TraceContext
|
||||||
|
|
||||||
injectSubBenchmarks(b, func(ctx context.Context, b *testing.B) {
|
injectSubBenchmarks(b, func(ctx context.Context, b *testing.B) {
|
||||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
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) {
|
func BenchmarkExtract(b *testing.B) {
|
||||||
extractSubBenchmarks(b, func(b *testing.B, req *http.Request) {
|
extractSubBenchmarks(b, func(b *testing.B, req *http.Request) {
|
||||||
var propagator TraceContextPropagator
|
var propagator TraceContext
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package propagation_test
|
package propagators_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -25,9 +25,9 @@ import (
|
|||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -46,7 +46,7 @@ func mustSpanIDFromHex(s string) (t core.SpanID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
||||||
var propagator propagation.TraceContextPropagator
|
var propagator propagators.TraceContext
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
@ -139,7 +139,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
|
func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
|
||||||
var propagator propagation.TraceContextPropagator
|
var propagator propagators.TraceContext
|
||||||
wantSc := core.EmptySpanContext()
|
wantSc := core.EmptySpanContext()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -231,7 +231,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
|
|||||||
Sampled: false,
|
Sampled: false,
|
||||||
StartSpanID: &id,
|
StartSpanID: &id,
|
||||||
}
|
}
|
||||||
var propagator propagation.TraceContextPropagator
|
var propagator propagators.TraceContext
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
sc core.SpanContext
|
sc core.SpanContext
|
||||||
@ -287,7 +287,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
||||||
propagator := propagation.TraceContextPropagator{}
|
propagator := propagators.TraceContext{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
@ -375,7 +375,7 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
||||||
propagator := propagation.TraceContextPropagator{}
|
propagator := propagators.TraceContext{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
@ -401,7 +401,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
||||||
propagator := propagation.TraceContextPropagator{}
|
propagator := propagators.TraceContext{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
kvs []core.KeyValue
|
kvs []core.KeyValue
|
||||||
@ -475,7 +475,7 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTraceContextPropagator_GetAllKeys(t *testing.T) {
|
func TestTraceContextPropagator_GetAllKeys(t *testing.T) {
|
||||||
var propagator propagation.TraceContextPropagator
|
var propagator propagators.TraceContext
|
||||||
want := []string{"Traceparent", "Correlation-Context"}
|
want := []string{"Traceparent", "Correlation-Context"}
|
||||||
got := propagator.GetAllKeys()
|
got := propagator.GetAllKeys()
|
||||||
if diff := cmp.Diff(got, want); diff != "" {
|
if diff := cmp.Diff(got, want); diff != "" {
|
@ -21,7 +21,7 @@ import (
|
|||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -30,7 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
propagator = propagation.TraceContextPropagator{}
|
propagator = propagators.TraceContext{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type metadataSupplier struct {
|
type metadataSupplier struct {
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -31,7 +31,7 @@ var (
|
|||||||
HostKey = key.New("http.host")
|
HostKey = key.New("http.host")
|
||||||
URLKey = key.New("http.url")
|
URLKey = key.New("http.url")
|
||||||
|
|
||||||
propagator = propagation.TraceContextPropagator{}
|
propagator = propagators.TraceContext{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.
|
// Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.
|
||||||
|
@ -20,9 +20,8 @@ import (
|
|||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/propagation"
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
prop "go.opentelemetry.io/otel/propagation"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ http.Handler = &Handler{}
|
var _ http.Handler = &Handler{}
|
||||||
@ -51,7 +50,7 @@ type Handler struct {
|
|||||||
handler http.Handler
|
handler http.Handler
|
||||||
|
|
||||||
tracer trace.Tracer
|
tracer trace.Tracer
|
||||||
prop propagation.TextFormatPropagator
|
prop propagators.TextFormat
|
||||||
spanOptions []trace.SpanOption
|
spanOptions []trace.SpanOption
|
||||||
public bool
|
public bool
|
||||||
readEvent bool
|
readEvent bool
|
||||||
@ -80,8 +79,8 @@ func WithPublicEndpoint() Option {
|
|||||||
|
|
||||||
// WithPropagator configures the Handler with a specific propagator. If this
|
// WithPropagator configures the Handler with a specific propagator. If this
|
||||||
// option isn't specificed then
|
// option isn't specificed then
|
||||||
// go.opentelemetry.io/otel/propagation.TraceContextPropagator is used.
|
// go.opentelemetry.io/otel/api/propagators.TraceContext is used.
|
||||||
func WithPropagator(p propagation.TextFormatPropagator) Option {
|
func WithPropagator(p propagators.TextFormat) Option {
|
||||||
return func(h *Handler) {
|
return func(h *Handler) {
|
||||||
h.prop = p
|
h.prop = p
|
||||||
}
|
}
|
||||||
@ -131,7 +130,7 @@ func NewHandler(handler http.Handler, operation string, opts ...Option) http.Han
|
|||||||
h := Handler{handler: handler, operation: operation}
|
h := Handler{handler: handler, operation: operation}
|
||||||
defaultOpts := []Option{
|
defaultOpts := []Option{
|
||||||
WithTracer(global.TraceProvider().Tracer("go.opentelemetry.io/plugin/othttp")),
|
WithTracer(global.TraceProvider().Tracer("go.opentelemetry.io/plugin/othttp")),
|
||||||
WithPropagator(prop.TraceContextPropagator{}),
|
WithPropagator(propagators.TraceContext{}),
|
||||||
WithSpanOptions(trace.WithSpanKind(trace.SpanKindServer)),
|
WithSpanOptions(trace.WithSpanKind(trace.SpanKindServer)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
|
|
||||||
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
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 {
|
if got, expected := rr.Result().StatusCode, http.StatusOK; got != expected {
|
||||||
t.Fatalf("got %d, expected %d", 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")
|
t.Fatal("expected non empty trace header")
|
||||||
}
|
}
|
||||||
if got, expected := id, uint64(1); got != expected {
|
if got, expected := id, uint64(1); got != expected {
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/propagation"
|
"go.opentelemetry.io/otel/api/propagators"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ io.ReadCloser = &bodyWrapper{}
|
var _ io.ReadCloser = &bodyWrapper{}
|
||||||
@ -50,7 +50,7 @@ func (w *bodyWrapper) Close() error {
|
|||||||
var _ http.ResponseWriter = &respWriterWrapper{}
|
var _ http.ResponseWriter = &respWriterWrapper{}
|
||||||
|
|
||||||
type injector interface {
|
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
|
// respWriterWrapper wraps a http.ResponseWriter in order to track the number of
|
||||||
|
@ -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"
|
|
Reference in New Issue
Block a user