You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Reorganize propagation code (shrink PR 381) (#444)
* Rename distributedcontext package to correlation Correlation is the name we agreed upon. * Move trace propagators to api/trace The trace propagators tests had to be moved to a testtrace subpackage to avoid import cycles between api/trace and internal/trace. Needed to shut up golint about stutter in trace.TraceContext - TraceContext is a name of a W3C spec, so this stutter is expected. It's certainly still better than golint's suggestion of having trace.Context. * Rename api/propagators to api/propagation This package will not contain any propagators in the long run, just the interface definitions. Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
This commit is contained in:
committed by
Rahul Patel
parent
437d9af9ab
commit
6b4acf47b8
31
api/correlation/context.go
Normal file
31
api/correlation/context.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package correlation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/api/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
type correlationsType struct{}
|
||||||
|
|
||||||
|
var correlationsKey = &correlationsType{}
|
||||||
|
|
||||||
|
// WithMap enters a Map into a new Context.
|
||||||
|
func WithMap(ctx context.Context, m Map) context.Context {
|
||||||
|
return context.WithValue(ctx, correlationsKey, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMap enters a key:value set into a new Context.
|
||||||
|
func NewContext(ctx context.Context, keyvalues ...core.KeyValue) context.Context {
|
||||||
|
return WithMap(ctx, FromContext(ctx).Apply(MapUpdate{
|
||||||
|
MultiKV: keyvalues,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromContext gets the current Map from a Context.
|
||||||
|
func FromContext(ctx context.Context) Map {
|
||||||
|
if m, ok := ctx.Value(correlationsKey).(Map); ok {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
return NewEmptyMap()
|
||||||
|
}
|
||||||
@@ -12,12 +12,14 @@
|
|||||||
// 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 distributedcontext
|
package correlation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO Comments needed! This was formerly known as distributedcontext.Map
|
||||||
|
|
||||||
type entry struct {
|
type entry struct {
|
||||||
value core.Value
|
value core.Value
|
||||||
}
|
}
|
||||||
@@ -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 distributedcontext
|
package correlation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,56 +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 distributedcontext
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"runtime/pprof"
|
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ctxEntriesType struct{}
|
|
||||||
|
|
||||||
var (
|
|
||||||
ctxEntriesKey = &ctxEntriesType{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func WithMap(ctx context.Context, m Map) context.Context {
|
|
||||||
return context.WithValue(ctx, ctxEntriesKey, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewContext(ctx context.Context, keyvalues ...core.KeyValue) context.Context {
|
|
||||||
return WithMap(ctx, FromContext(ctx).Apply(MapUpdate{
|
|
||||||
MultiKV: keyvalues,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FromContext(ctx context.Context) Map {
|
|
||||||
if m, ok := ctx.Value(ctxEntriesKey).(Map); ok {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
return NewEmptyMap()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: the golang pprof.Do API forces this memory allocation, we
|
|
||||||
// should file an issue about that. (There's a TODO in the source.)
|
|
||||||
func Do(ctx context.Context, f func(ctx context.Context)) {
|
|
||||||
m := FromContext(ctx)
|
|
||||||
keyvals := make([]string, 0, 2*len(m.m))
|
|
||||||
for k, v := range m.m {
|
|
||||||
keyvals = append(keyvals, string(k), v.value.Emit())
|
|
||||||
}
|
|
||||||
pprof.Do(ctx, pprof.Labels(keyvals...), f)
|
|
||||||
}
|
|
||||||
@@ -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 propagators
|
package propagation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
@@ -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 propagators_test
|
package propagation_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/api/propagators"
|
"go.opentelemetry.io/otel/api/propagation"
|
||||||
)
|
)
|
||||||
|
|
||||||
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 := propagators.Binary()
|
propagator := propagation.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 := propagators.Binary()
|
propagator := propagation.Binary()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
sc core.SpanContext
|
sc core.SpanContext
|
||||||
@@ -12,4 +12,6 @@
|
|||||||
// 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 distributedcontext // import "go.opentelemetry.io/otel/api/distributedcontext"
|
// Package propagation contains interface definition for BinaryFormat and
|
||||||
|
// TextFormat propagators.
|
||||||
|
package propagation // import "go.opentelemetry.io/otel/api/propagation"
|
||||||
@@ -12,13 +12,13 @@
|
|||||||
// 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 propagators
|
package propagation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NoopTextFormat implements TextFormat that does nothing.
|
// NoopTextFormat implements TextFormat that does nothing.
|
||||||
@@ -31,8 +31,8 @@ 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 NoopTextFormat) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map) {
|
func (np NoopTextFormat) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, correlation.Map) {
|
||||||
return core.EmptySpanContext(), dctx.NewEmptyMap()
|
return core.EmptySpanContext(), correlation.NewEmptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllKeys returns empty list of strings.
|
// GetAllKeys returns empty list of strings.
|
||||||
@@ -12,13 +12,13 @@
|
|||||||
// 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 propagators
|
package propagation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TextFormat is an interface that specifies methods to inject and extract SpanContext
|
// TextFormat is an interface that specifies methods to inject and extract SpanContext
|
||||||
@@ -33,10 +33,10 @@ type TextFormat interface {
|
|||||||
Inject(ctx context.Context, supplier Supplier)
|
Inject(ctx context.Context, supplier Supplier)
|
||||||
|
|
||||||
// Extract method retrieves encoded SpanContext using supplier from the associated carrier.
|
// Extract method retrieves encoded SpanContext using supplier from the associated carrier.
|
||||||
// It decodes the SpanContext and returns it and a dctx of correlated context.
|
// It decodes the SpanContext and returns it and a baggage of correlated context.
|
||||||
// If no SpanContext was retrieved OR if the retrieved SpanContext is invalid then
|
// If no SpanContext was retrieved OR if the retrieved SpanContext is invalid then
|
||||||
// an empty SpanContext is returned.
|
// an empty SpanContext is returned.
|
||||||
Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map)
|
Extract(ctx context.Context, supplier Supplier) (core.SpanContext, correlation.Map)
|
||||||
|
|
||||||
// GetAllKeys returns all the keys that this propagator injects/extracts into/from a
|
// GetAllKeys returns all the keys that this propagator injects/extracts into/from a
|
||||||
// carrier. The use cases for this are
|
// carrier. The use cases for this are
|
||||||
@@ -1,18 +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 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"
|
|
||||||
@@ -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 propagators
|
package trace
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -20,8 +20,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/propagation"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -50,10 +50,10 @@ type B3 struct {
|
|||||||
SingleHeader bool
|
SingleHeader bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ TextFormat = B3{}
|
var _ propagation.TextFormat = B3{}
|
||||||
|
|
||||||
func (b3 B3) Inject(ctx context.Context, supplier Supplier) {
|
func (b3 B3) Inject(ctx context.Context, supplier propagation.Supplier) {
|
||||||
sc := trace.SpanFromContext(ctx).SpanContext()
|
sc := SpanFromContext(ctx).SpanContext()
|
||||||
if sc.IsValid() {
|
if sc.IsValid() {
|
||||||
if b3.SingleHeader {
|
if b3.SingleHeader {
|
||||||
sampled := sc.TraceFlags & core.TraceFlagsSampled
|
sampled := sc.TraceFlags & core.TraceFlagsSampled
|
||||||
@@ -76,11 +76,11 @@ func (b3 B3) Inject(ctx context.Context, supplier Supplier) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract retrieves B3 Headers from the supplier
|
// Extract retrieves B3 Headers from the supplier
|
||||||
func (b3 B3) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map) {
|
func (b3 B3) Extract(ctx context.Context, supplier propagation.Supplier) (core.SpanContext, correlation.Map) {
|
||||||
if b3.SingleHeader {
|
if b3.SingleHeader {
|
||||||
return b3.extractSingleHeader(supplier), dctx.NewEmptyMap()
|
return b3.extractSingleHeader(supplier), correlation.NewEmptyMap()
|
||||||
}
|
}
|
||||||
return b3.extract(supplier), dctx.NewEmptyMap()
|
return b3.extract(supplier), correlation.NewEmptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b3 B3) GetAllKeys() []string {
|
func (b3 B3) GetAllKeys() []string {
|
||||||
@@ -90,7 +90,7 @@ func (b3 B3) GetAllKeys() []string {
|
|||||||
return []string{B3TraceIDHeader, B3SpanIDHeader, B3SampledHeader}
|
return []string{B3TraceIDHeader, B3SpanIDHeader, B3SampledHeader}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b3 B3) extract(supplier Supplier) core.SpanContext {
|
func (b3 B3) extract(supplier propagation.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()
|
||||||
@@ -125,7 +125,7 @@ func (b3 B3) extract(supplier Supplier) core.SpanContext {
|
|||||||
return sc
|
return sc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b3 B3) extractSingleHeader(supplier Supplier) core.SpanContext {
|
func (b3 B3) extractSingleHeader(supplier propagation.Supplier) core.SpanContext {
|
||||||
h := supplier.Get(B3SingleHeader)
|
h := supplier.Get(B3SingleHeader)
|
||||||
if h == "" || h == "0" {
|
if h == "" || h == "0" {
|
||||||
core.EmptySpanContext()
|
core.EmptySpanContext()
|
||||||
@@ -12,14 +12,13 @@
|
|||||||
// 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 propagators_test
|
package testtrace_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"
|
||||||
)
|
)
|
||||||
@@ -53,7 +52,7 @@ func BenchmarkExtractB3(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
propagator := propagators.B3{SingleHeader: tg.singleHeader}
|
propagator := trace.B3{SingleHeader: 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 +96,7 @@ func BenchmarkInjectB3(b *testing.B) {
|
|||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
id = 0
|
id = 0
|
||||||
propagator := propagators.B3{SingleHeader: tg.singleHeader}
|
propagator := trace.B3{SingleHeader: 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 propagators_test
|
package testtrace_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
"go.opentelemetry.io/otel/api/propagators"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3SampledHeader: "0",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3SampledHeader: "true",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3DebugFlagHeader: "1",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3SampledHeader: "0",
|
trace.B3SampledHeader: "0",
|
||||||
propagators.B3DebugFlagHeader: "1",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
propagators.B3ParentSpanIDHeader: "00f067aa0ba90200",
|
trace.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{
|
||||||
propagators.B3SampledHeader: "0",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "0",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "ab00000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab00000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "trace ID length >16 and <32",
|
name: "trace ID length >16 and <32",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab0000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab0000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "trace ID length <16",
|
name: "trace ID length <16",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab0000000000",
|
trace.B3TraceIDHeader: "ab0000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong span ID length",
|
name: "wrong span ID length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd0000000000000000",
|
trace.B3SpanIDHeader: "cd0000000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong sampled flag length",
|
name: "wrong sampled flag length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "10",
|
trace.B3SampledHeader: "10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus trace ID",
|
name: "bogus trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "qw000000000000000000000000000000",
|
trace.B3TraceIDHeader: "qw000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus span ID",
|
name: "bogus span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "qw00000000000000",
|
trace.B3SpanIDHeader: "qw00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus sampled flag",
|
name: "bogus sampled flag",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "d",
|
trace.B3SampledHeader: "d",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus debug flag (string)",
|
name: "bogus debug flag (string)",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
propagators.B3DebugFlagHeader: "d",
|
trace.B3DebugFlagHeader: "d",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus debug flag (number)",
|
name: "bogus debug flag (number)",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
propagators.B3DebugFlagHeader: "10",
|
trace.B3DebugFlagHeader: "10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case trace ID",
|
name: "upper case trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "AB000000000000000000000000000000",
|
trace.B3TraceIDHeader: "AB000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case span ID",
|
name: "upper case span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "CD00000000000000",
|
trace.B3SpanIDHeader: "CD00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero trace ID",
|
name: "zero trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "00000000000000000000000000000000",
|
trace.B3TraceIDHeader: "00000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero span ID",
|
name: "zero span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SpanIDHeader: "0000000000000000",
|
trace.B3SpanIDHeader: "0000000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing span ID",
|
name: "missing span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "ab000000000000000000000000000000",
|
trace.B3TraceIDHeader: "ab000000000000000000000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing trace ID",
|
name: "missing trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
|
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
|
||||||
propagators.B3SpanIDHeader: "cd00000000000000",
|
trace.B3SpanIDHeader: "cd00000000000000",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.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{
|
||||||
propagators.B3SampledHeader: "1",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "ab00000000000000000000000000000000-cd00000000000000-1",
|
trace.B3SingleHeader: "ab00000000000000000000000000000000-cd00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong span ID length",
|
name: "wrong span ID length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd0000000000000000-1",
|
trace.B3SingleHeader: "ab000000000000000000000000000000-cd0000000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong sampled state length",
|
name: "wrong sampled state length",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "00-ab000000000000000000000000000000-cd00000000000000-01",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-cd0000000000000000",
|
trace.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-cd0000000000000000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus trace ID",
|
name: "bogus trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "qw000000000000000000000000000000-cd00000000000000-1",
|
trace.B3SingleHeader: "qw000000000000000000000000000000-cd00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus span ID",
|
name: "bogus span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-qw00000000000000-1",
|
trace.B3SingleHeader: "ab000000000000000000000000000000-qw00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus sampled flag",
|
name: "bogus sampled flag",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-q",
|
trace.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-q",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus parent span ID",
|
name: "bogus parent span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-qw00000000000000",
|
trace.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-qw00000000000000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case trace ID",
|
name: "upper case trace ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "AB000000000000000000000000000000-cd00000000000000-1",
|
trace.B3SingleHeader: "AB000000000000000000000000000000-cd00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case span ID",
|
name: "upper case span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
trace.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upper case parent span ID",
|
name: "upper case parent span ID",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-1-EF00000000000000",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "00000000000000000000000000000000-0000000000000000-1",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.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{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
trace.B3SingleHeader: "ab000000000000000000000000000000-CD00000000000000-1",
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "00f067aa0ba902b7",
|
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with sampling set to true",
|
name: "with sampling set to true",
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
propagators.B3SingleHeader: "ab000000000000000000000000000000-cd00000000000000-true",
|
trace.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{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "0000000000000001",
|
trace.B3SpanIDHeader: "0000000000000001",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagators.B3ParentSpanIDHeader,
|
trace.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -465,12 +465,12 @@ var injectB3MultipleHeader = []injectTest{
|
|||||||
SpanID: spanID,
|
SpanID: spanID,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "0000000000000002",
|
trace.B3SpanIDHeader: "0000000000000002",
|
||||||
propagators.B3SampledHeader: "0",
|
trace.B3SampledHeader: "0",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagators.B3ParentSpanIDHeader,
|
trace.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -481,12 +481,12 @@ var injectB3MultipleHeader = []injectTest{
|
|||||||
TraceFlags: 0xff,
|
TraceFlags: 0xff,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagators.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
|
||||||
propagators.B3SpanIDHeader: "0000000000000003",
|
trace.B3SpanIDHeader: "0000000000000003",
|
||||||
propagators.B3SampledHeader: "1",
|
trace.B3SampledHeader: "1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagators.B3ParentSpanIDHeader,
|
trace.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -500,13 +500,13 @@ var injectB3SingleleHeader = []injectTest{
|
|||||||
TraceFlags: core.TraceFlagsSampled,
|
TraceFlags: core.TraceFlagsSampled,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1",
|
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagators.B3TraceIDHeader,
|
trace.B3TraceIDHeader,
|
||||||
propagators.B3SpanIDHeader,
|
trace.B3SpanIDHeader,
|
||||||
propagators.B3SampledHeader,
|
trace.B3SampledHeader,
|
||||||
propagators.B3ParentSpanIDHeader,
|
trace.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -516,13 +516,13 @@ var injectB3SingleleHeader = []injectTest{
|
|||||||
SpanID: spanID,
|
SpanID: spanID,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-0",
|
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-0",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagators.B3TraceIDHeader,
|
trace.B3TraceIDHeader,
|
||||||
propagators.B3SpanIDHeader,
|
trace.B3SpanIDHeader,
|
||||||
propagators.B3SampledHeader,
|
trace.B3SampledHeader,
|
||||||
propagators.B3ParentSpanIDHeader,
|
trace.B3ParentSpanIDHeader,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -533,13 +533,13 @@ var injectB3SingleleHeader = []injectTest{
|
|||||||
TraceFlags: 0xff,
|
TraceFlags: 0xff,
|
||||||
},
|
},
|
||||||
wantHeaders: map[string]string{
|
wantHeaders: map[string]string{
|
||||||
propagators.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000003-1",
|
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000003-1",
|
||||||
},
|
},
|
||||||
doNotWantHeaders: []string{
|
doNotWantHeaders: []string{
|
||||||
propagators.B3TraceIDHeader,
|
trace.B3TraceIDHeader,
|
||||||
propagators.B3SpanIDHeader,
|
trace.B3SpanIDHeader,
|
||||||
propagators.B3SampledHeader,
|
trace.B3SampledHeader,
|
||||||
propagators.B3ParentSpanIDHeader,
|
trace.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 propagators_test
|
package testtrace_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -21,7 +21,6 @@ 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"
|
||||||
)
|
)
|
||||||
@@ -55,7 +54,7 @@ func TestExtractB3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
propagator := propagators.B3{SingleHeader: tg.singleHeader}
|
propagator := trace.B3{SingleHeader: 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 +98,7 @@ func TestInjectB3(t *testing.T) {
|
|||||||
|
|
||||||
for _, tg := range testGroup {
|
for _, tg := range testGroup {
|
||||||
id = 0
|
id = 0
|
||||||
propagator := propagators.B3{SingleHeader: tg.singleHeader}
|
propagator := trace.B3{SingleHeader: 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)
|
||||||
@@ -129,11 +128,11 @@ func TestInjectB3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestB3Propagator_GetAllKeys(t *testing.T) {
|
func TestB3Propagator_GetAllKeys(t *testing.T) {
|
||||||
propagator := propagators.B3{SingleHeader: false}
|
propagator := trace.B3{SingleHeader: false}
|
||||||
want := []string{
|
want := []string{
|
||||||
propagators.B3TraceIDHeader,
|
trace.B3TraceIDHeader,
|
||||||
propagators.B3SpanIDHeader,
|
trace.B3SpanIDHeader,
|
||||||
propagators.B3SampledHeader,
|
trace.B3SampledHeader,
|
||||||
}
|
}
|
||||||
got := propagator.GetAllKeys()
|
got := propagator.GetAllKeys()
|
||||||
if diff := cmp.Diff(got, want); diff != "" {
|
if diff := cmp.Diff(got, want); diff != "" {
|
||||||
@@ -142,9 +141,9 @@ func TestB3Propagator_GetAllKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestB3PropagatorWithSingleHeader_GetAllKeys(t *testing.T) {
|
func TestB3PropagatorWithSingleHeader_GetAllKeys(t *testing.T) {
|
||||||
propagator := propagators.B3{SingleHeader: true}
|
propagator := trace.B3{SingleHeader: true}
|
||||||
want := []string{
|
want := []string{
|
||||||
propagators.B3SingleHeader,
|
trace.B3SingleHeader,
|
||||||
}
|
}
|
||||||
got := propagator.GetAllKeys()
|
got := propagator.GetAllKeys()
|
||||||
if diff := cmp.Diff(got, want); diff != "" {
|
if diff := cmp.Diff(got, want); diff != "" {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package propagators
|
package testtrace_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkInject(b *testing.B) {
|
func BenchmarkInject(b *testing.B) {
|
||||||
var t TraceContext
|
var t trace.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 TraceContext
|
var propagator trace.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 propagators_test
|
package testtrace_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -23,9 +23,8 @@ 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"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
@@ -46,7 +45,7 @@ func mustSpanIDFromHex(s string) (t core.SpanID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
||||||
var propagator propagators.TraceContext
|
var propagator trace.TraceContext
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
@@ -139,7 +138,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
|
func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
|
||||||
var propagator propagators.TraceContext
|
var propagator trace.TraceContext
|
||||||
wantSc := core.EmptySpanContext()
|
wantSc := core.EmptySpanContext()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -231,7 +230,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
|
|||||||
Sampled: false,
|
Sampled: false,
|
||||||
StartSpanID: &id,
|
StartSpanID: &id,
|
||||||
}
|
}
|
||||||
var propagator propagators.TraceContext
|
var propagator trace.TraceContext
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
sc core.SpanContext
|
sc core.SpanContext
|
||||||
@@ -287,7 +286,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
||||||
propagator := propagators.TraceContext{}
|
propagator := trace.TraceContext{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
@@ -350,7 +349,7 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, gotCorCtx := propagator.Extract(ctx, req.Header)
|
_, gotCorCtx := propagator.Extract(ctx, req.Header)
|
||||||
wantCorCtx := dctx.NewMap(dctx.MapUpdate{MultiKV: tt.wantKVs})
|
wantCorCtx := correlation.NewMap(correlation.MapUpdate{MultiKV: tt.wantKVs})
|
||||||
if gotCorCtx.Len() != wantCorCtx.Len() {
|
if gotCorCtx.Len() != wantCorCtx.Len() {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"Got and Want CorCtx are not the same size %d != %d",
|
"Got and Want CorCtx are not the same size %d != %d",
|
||||||
@@ -375,7 +374,7 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
||||||
propagator := propagators.TraceContext{}
|
propagator := trace.TraceContext{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
header string
|
header string
|
||||||
@@ -401,7 +400,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
||||||
propagator := propagators.TraceContext{}
|
propagator := trace.TraceContext{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
kvs []core.KeyValue
|
kvs []core.KeyValue
|
||||||
@@ -453,7 +452,7 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range 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)
|
||||||
ctx := dctx.WithMap(context.Background(), dctx.NewMap(dctx.MapUpdate{MultiKV: tt.kvs}))
|
ctx := correlation.WithMap(context.Background(), correlation.NewMap(correlation.MapUpdate{MultiKV: tt.kvs}))
|
||||||
propagator.Inject(ctx, req.Header)
|
propagator.Inject(ctx, req.Header)
|
||||||
|
|
||||||
gotHeader := req.Header.Get("Correlation-Context")
|
gotHeader := req.Header.Get("Correlation-Context")
|
||||||
@@ -475,7 +474,7 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTraceContextPropagator_GetAllKeys(t *testing.T) {
|
func TestTraceContextPropagator_GetAllKeys(t *testing.T) {
|
||||||
var propagator propagators.TraceContext
|
var propagator trace.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 != "" {
|
||||||
@@ -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 propagators
|
package trace
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -23,9 +23,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
dctx "go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/propagation"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -36,13 +36,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// TraceContext propagates SpanContext in W3C TraceContext format.
|
// TraceContext propagates SpanContext in W3C TraceContext format.
|
||||||
|
//nolint:golint
|
||||||
type TraceContext struct{}
|
type TraceContext struct{}
|
||||||
|
|
||||||
var _ TextFormat = TraceContext{}
|
var _ propagation.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 TraceContext) Inject(ctx context.Context, supplier Supplier) {
|
func (hp TraceContext) Inject(ctx context.Context, supplier propagation.Supplier) {
|
||||||
sc := trace.SpanFromContext(ctx).SpanContext()
|
sc := SpanFromContext(ctx).SpanContext()
|
||||||
if sc.IsValid() {
|
if sc.IsValid() {
|
||||||
h := fmt.Sprintf("%.2x-%s-%.16x-%.2x",
|
h := fmt.Sprintf("%.2x-%s-%.16x-%.2x",
|
||||||
supportedVersion,
|
supportedVersion,
|
||||||
@@ -52,7 +53,7 @@ func (hp TraceContext) Inject(ctx context.Context, supplier Supplier) {
|
|||||||
supplier.Set(TraceparentHeader, h)
|
supplier.Set(TraceparentHeader, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
correlationCtx := dctx.FromContext(ctx)
|
correlationCtx := correlation.FromContext(ctx)
|
||||||
firstIter := true
|
firstIter := true
|
||||||
var headerValueBuilder strings.Builder
|
var headerValueBuilder strings.Builder
|
||||||
correlationCtx.Foreach(func(kv core.KeyValue) bool {
|
correlationCtx.Foreach(func(kv core.KeyValue) bool {
|
||||||
@@ -72,13 +73,13 @@ func (hp TraceContext) Inject(ctx context.Context, supplier Supplier) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hp TraceContext) Extract(
|
func (hp TraceContext) Extract(
|
||||||
ctx context.Context, supplier Supplier,
|
ctx context.Context, supplier propagation.Supplier,
|
||||||
) (core.SpanContext, dctx.Map) {
|
) (core.SpanContext, correlation.Map) {
|
||||||
return hp.extractSpanContext(ctx, supplier), hp.extractCorrelationCtx(ctx, supplier)
|
return hp.extractSpanContext(ctx, supplier), hp.extractCorrelationCtx(ctx, supplier)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hp TraceContext) extractSpanContext(
|
func (hp TraceContext) extractSpanContext(
|
||||||
ctx context.Context, supplier Supplier,
|
ctx context.Context, supplier propagation.Supplier,
|
||||||
) core.SpanContext {
|
) core.SpanContext {
|
||||||
h := supplier.Get(TraceparentHeader)
|
h := supplier.Get(TraceparentHeader)
|
||||||
if h == "" {
|
if h == "" {
|
||||||
@@ -146,10 +147,10 @@ func (hp TraceContext) extractSpanContext(
|
|||||||
return sc
|
return sc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hp TraceContext) extractCorrelationCtx(ctx context.Context, supplier Supplier) dctx.Map {
|
func (hp TraceContext) extractCorrelationCtx(ctx context.Context, supplier propagation.Supplier) correlation.Map {
|
||||||
correlationContext := supplier.Get(CorrelationContextHeader)
|
correlationContext := supplier.Get(CorrelationContextHeader)
|
||||||
if correlationContext == "" {
|
if correlationContext == "" {
|
||||||
return dctx.NewEmptyMap()
|
return correlation.NewEmptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
contextValues := strings.Split(correlationContext, ",")
|
contextValues := strings.Split(correlationContext, ",")
|
||||||
@@ -185,7 +186,7 @@ func (hp TraceContext) extractCorrelationCtx(ctx context.Context, supplier Suppl
|
|||||||
|
|
||||||
keyValues = append(keyValues, key.New(trimmedName).String(trimmedValueWithProps.String()))
|
keyValues = append(keyValues, key.New(trimmedName).String(trimmedValueWithProps.String()))
|
||||||
}
|
}
|
||||||
return dctx.NewMap(dctx.MapUpdate{
|
return correlation.NewMap(correlation.MapUpdate{
|
||||||
MultiKV: keyValues,
|
MultiKV: keyValues,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
otelcore "go.opentelemetry.io/otel/api/core"
|
otelcore "go.opentelemetry.io/otel/api/core"
|
||||||
oteldctx "go.opentelemetry.io/otel/api/distributedcontext"
|
otelcorrelation "go.opentelemetry.io/otel/api/correlation"
|
||||||
otelkey "go.opentelemetry.io/otel/api/key"
|
otelkey "go.opentelemetry.io/otel/api/key"
|
||||||
oteltrace "go.opentelemetry.io/otel/api/trace"
|
oteltrace "go.opentelemetry.io/otel/api/trace"
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ type MockContextKeyValue struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MockTracer struct {
|
type MockTracer struct {
|
||||||
Resources oteldctx.Map
|
Resources otelcorrelation.Map
|
||||||
FinishedSpans []*MockSpan
|
FinishedSpans []*MockSpan
|
||||||
SpareTraceIDs []otelcore.TraceID
|
SpareTraceIDs []otelcore.TraceID
|
||||||
SpareSpanIDs []otelcore.SpanID
|
SpareSpanIDs []otelcore.SpanID
|
||||||
@@ -59,7 +59,7 @@ var _ migration.DeferredContextSetupTracerExtension = &MockTracer{}
|
|||||||
|
|
||||||
func NewMockTracer() *MockTracer {
|
func NewMockTracer() *MockTracer {
|
||||||
return &MockTracer{
|
return &MockTracer{
|
||||||
Resources: oteldctx.NewEmptyMap(),
|
Resources: otelcorrelation.NewEmptyMap(),
|
||||||
FinishedSpans: nil,
|
FinishedSpans: nil,
|
||||||
SpareTraceIDs: nil,
|
SpareTraceIDs: nil,
|
||||||
SpareSpanIDs: nil,
|
SpareSpanIDs: nil,
|
||||||
@@ -94,7 +94,7 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S
|
|||||||
officialTracer: t,
|
officialTracer: t,
|
||||||
spanContext: spanContext,
|
spanContext: spanContext,
|
||||||
recording: spanOpts.Record,
|
recording: spanOpts.Record,
|
||||||
Attributes: oteldctx.NewMap(oteldctx.MapUpdate{
|
Attributes: otelcorrelation.NewMap(otelcorrelation.MapUpdate{
|
||||||
MultiKV: spanOpts.Attributes,
|
MultiKV: spanOpts.Attributes,
|
||||||
}),
|
}),
|
||||||
StartTime: startTime,
|
StartTime: startTime,
|
||||||
@@ -193,10 +193,10 @@ func (t *MockTracer) DeferredContextSetupHook(ctx context.Context, span oteltrac
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MockEvent struct {
|
type MockEvent struct {
|
||||||
CtxAttributes oteldctx.Map
|
CtxAttributes otelcorrelation.Map
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
Name string
|
Name string
|
||||||
Attributes oteldctx.Map
|
Attributes otelcorrelation.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockSpan struct {
|
type MockSpan struct {
|
||||||
@@ -206,7 +206,7 @@ type MockSpan struct {
|
|||||||
SpanKind oteltrace.SpanKind
|
SpanKind oteltrace.SpanKind
|
||||||
recording bool
|
recording bool
|
||||||
|
|
||||||
Attributes oteldctx.Map
|
Attributes otelcorrelation.Map
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
EndTime time.Time
|
EndTime time.Time
|
||||||
ParentSpanID otelcore.SpanID
|
ParentSpanID otelcore.SpanID
|
||||||
@@ -237,12 +237,12 @@ func (s *MockSpan) SetError(v bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
|
func (s *MockSpan) SetAttributes(attributes ...otelcore.KeyValue) {
|
||||||
s.applyUpdate(oteldctx.MapUpdate{
|
s.applyUpdate(otelcorrelation.MapUpdate{
|
||||||
MultiKV: attributes,
|
MultiKV: attributes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MockSpan) applyUpdate(update oteldctx.MapUpdate) {
|
func (s *MockSpan) applyUpdate(update otelcorrelation.MapUpdate) {
|
||||||
s.Attributes = s.Attributes.Apply(update)
|
s.Attributes = s.Attributes.Apply(update)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,10 +274,10 @@ func (s *MockSpan) AddEvent(ctx context.Context, name string, attrs ...otelcore.
|
|||||||
|
|
||||||
func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...otelcore.KeyValue) {
|
func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...otelcore.KeyValue) {
|
||||||
s.Events = append(s.Events, MockEvent{
|
s.Events = append(s.Events, MockEvent{
|
||||||
CtxAttributes: oteldctx.FromContext(ctx),
|
CtxAttributes: otelcorrelation.FromContext(ctx),
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Name: name,
|
Name: name,
|
||||||
Attributes: oteldctx.NewMap(oteldctx.MapUpdate{
|
Attributes: otelcorrelation.NewMap(otelcorrelation.MapUpdate{
|
||||||
MultiKV: attrs,
|
MultiKV: attrs,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
@@ -82,7 +82,7 @@ func main() {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ctx = distributedcontext.NewContext(ctx,
|
ctx = correlation.NewContext(ctx,
|
||||||
fooKey.String("foo1"),
|
fooKey.String("foo1"),
|
||||||
barKey.String("bar1"),
|
barKey.String("bar1"),
|
||||||
)
|
)
|
||||||
@@ -105,7 +105,7 @@ func main() {
|
|||||||
|
|
||||||
meter.RecordBatch(
|
meter.RecordBatch(
|
||||||
// Note: call-site variables added as context Entries:
|
// Note: call-site variables added as context Entries:
|
||||||
distributedcontext.NewContext(ctx, anotherKey.String("xyz")),
|
correlation.NewContext(ctx, anotherKey.String("xyz")),
|
||||||
commonLabels,
|
commonLabels,
|
||||||
|
|
||||||
oneMetric.Measurement(1.0),
|
oneMetric.Measurement(1.0),
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
"go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
@@ -39,7 +39,7 @@ func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.Una
|
|||||||
metadataCopy := requestMetadata.Copy()
|
metadataCopy := requestMetadata.Copy()
|
||||||
|
|
||||||
entries, spanCtx := grpctrace.Extract(ctx, &metadataCopy)
|
entries, spanCtx := grpctrace.Extract(ctx, &metadataCopy)
|
||||||
ctx = distributedcontext.WithMap(ctx, distributedcontext.NewMap(distributedcontext.MapUpdate{
|
ctx = correlation.WithMap(ctx, correlation.NewMap(correlation.MapUpdate{
|
||||||
MultiKV: entries,
|
MultiKV: entries,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
@@ -62,7 +62,7 @@ func main() {
|
|||||||
tr := global.TraceProvider().Tracer("stackdriver/example/client")
|
tr := global.TraceProvider().Tracer("stackdriver/example/client")
|
||||||
|
|
||||||
client := http.DefaultClient
|
client := http.DefaultClient
|
||||||
ctx := distributedcontext.NewContext(context.Background(),
|
ctx := correlation.NewContext(context.Background(),
|
||||||
key.String("username", "donuts"),
|
key.String("username", "donuts"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/exporter/trace/stackdriver"
|
"go.opentelemetry.io/otel/exporter/trace/stackdriver"
|
||||||
@@ -58,7 +58,7 @@ func main() {
|
|||||||
helloHandler := func(w http.ResponseWriter, req *http.Request) {
|
helloHandler := func(w http.ResponseWriter, req *http.Request) {
|
||||||
attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
|
attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
|
||||||
|
|
||||||
req = req.WithContext(distributedcontext.WithMap(req.Context(), distributedcontext.NewMap(distributedcontext.MapUpdate{
|
req = req.WithContext(correlation.WithMap(req.Context(), correlation.NewMap(correlation.MapUpdate{
|
||||||
MultiKV: entries,
|
MultiKV: entries,
|
||||||
})))
|
})))
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
@@ -56,7 +56,7 @@ func main() {
|
|||||||
initTracer()
|
initTracer()
|
||||||
|
|
||||||
client := http.DefaultClient
|
client := http.DefaultClient
|
||||||
ctx := distributedcontext.NewContext(context.Background(),
|
ctx := correlation.NewContext(context.Background(),
|
||||||
key.String("username", "donuts"),
|
key.String("username", "donuts"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/exporter/trace/stdout"
|
"go.opentelemetry.io/otel/exporter/trace/stdout"
|
||||||
@@ -52,7 +52,7 @@ func main() {
|
|||||||
helloHandler := func(w http.ResponseWriter, req *http.Request) {
|
helloHandler := func(w http.ResponseWriter, req *http.Request) {
|
||||||
attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
|
attrs, entries, spanCtx := httptrace.Extract(req.Context(), req)
|
||||||
|
|
||||||
req = req.WithContext(distributedcontext.WithMap(req.Context(), distributedcontext.NewMap(distributedcontext.MapUpdate{
|
req = req.WithContext(correlation.WithMap(req.Context(), correlation.NewMap(correlation.MapUpdate{
|
||||||
MultiKV: entries,
|
MultiKV: entries,
|
||||||
})))
|
})))
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/distributedcontext"
|
"go.opentelemetry.io/otel/api/correlation"
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/key"
|
"go.opentelemetry.io/otel/api/key"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
@@ -59,7 +59,7 @@ func main() {
|
|||||||
tracer := tp.Tracer("example/namedtracer/main")
|
tracer := tp.Tracer("example/namedtracer/main")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ctx = distributedcontext.NewContext(ctx,
|
ctx = correlation.NewContext(ctx,
|
||||||
fooKey.String("foo1"),
|
fooKey.String("foo1"),
|
||||||
barKey.String("bar1"),
|
barKey.String("bar1"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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/api/propagators"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -30,7 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
propagator = propagators.TraceContext{}
|
propagator = trace.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/api/propagators"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
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 = propagators.TraceContext{}
|
propagator = trace.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,7 +20,7 @@ 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/propagators"
|
"go.opentelemetry.io/otel/api/propagation"
|
||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ type Handler struct {
|
|||||||
handler http.Handler
|
handler http.Handler
|
||||||
|
|
||||||
tracer trace.Tracer
|
tracer trace.Tracer
|
||||||
prop propagators.TextFormat
|
prop propagation.TextFormat
|
||||||
spanStartOptions []trace.StartOption
|
spanStartOptions []trace.StartOption
|
||||||
public bool
|
public bool
|
||||||
readEvent bool
|
readEvent bool
|
||||||
@@ -79,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/api/propagators.TraceContext is used.
|
// go.opentelemetry.io/otel/api/trace.TraceContext is used.
|
||||||
func WithPropagator(p propagators.TextFormat) Option {
|
func WithPropagator(p propagation.TextFormat) Option {
|
||||||
return func(h *Handler) {
|
return func(h *Handler) {
|
||||||
h.prop = p
|
h.prop = p
|
||||||
}
|
}
|
||||||
@@ -130,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(propagators.TraceContext{}),
|
WithPropagator(trace.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/api/propagators"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
|
|
||||||
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(propagators.TraceparentHeader); got == "" {
|
if got := rr.Header().Get(trace.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/propagators"
|
"go.opentelemetry.io/otel/api/propagation"
|
||||||
)
|
)
|
||||||
|
|
||||||
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, propagators.Supplier)
|
Inject(context.Context, propagation.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
|
||||||
|
|||||||
Reference in New Issue
Block a user