You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-08-10 22:31:50 +02:00
Remove "HTTP" from propagator names (#355)
These propagators are actually multi-purpose, not strictly for HTTP.
This commit is contained in:
committed by
rghetia
parent
13cd2ac417
commit
5f776dbaed
@@ -35,7 +35,7 @@ const (
|
||||
B3ParentSpanIDHeader = "X-B3-ParentSpanId"
|
||||
)
|
||||
|
||||
// HTTPB3Propagator that facilitates core.SpanContext
|
||||
// B3Propagator that facilitates core.SpanContext
|
||||
// propagation using B3 Headers.
|
||||
// This propagator supports both version of B3 headers,
|
||||
// 1. Single Header :
|
||||
@@ -49,13 +49,13 @@ const (
|
||||
//
|
||||
// If SingleHeader is set to true then X-B3 header is used to inject and extract. Otherwise,
|
||||
// separate headers are used to inject and extract.
|
||||
type HTTPB3Propagator struct {
|
||||
type B3Propagator struct {
|
||||
SingleHeader bool
|
||||
}
|
||||
|
||||
var _ apipropagation.TextFormatPropagator = HTTPB3Propagator{}
|
||||
var _ apipropagation.TextFormatPropagator = B3Propagator{}
|
||||
|
||||
func (b3 HTTPB3Propagator) Inject(ctx context.Context, supplier apipropagation.Supplier) {
|
||||
func (b3 B3Propagator) Inject(ctx context.Context, supplier apipropagation.Supplier) {
|
||||
sc := trace.CurrentSpan(ctx).SpanContext()
|
||||
if sc.IsValid() {
|
||||
if b3.SingleHeader {
|
||||
@@ -79,21 +79,21 @@ func (b3 HTTPB3Propagator) Inject(ctx context.Context, supplier apipropagation.S
|
||||
}
|
||||
|
||||
// Extract retrieves B3 Headers from the supplier
|
||||
func (b3 HTTPB3Propagator) Extract(ctx context.Context, supplier apipropagation.Supplier) (core.SpanContext, dctx.Map) {
|
||||
func (b3 B3Propagator) Extract(ctx context.Context, supplier apipropagation.Supplier) (core.SpanContext, dctx.Map) {
|
||||
if b3.SingleHeader {
|
||||
return b3.extractSingleHeader(supplier), dctx.NewEmptyMap()
|
||||
}
|
||||
return b3.extract(supplier), dctx.NewEmptyMap()
|
||||
}
|
||||
|
||||
func (b3 HTTPB3Propagator) GetAllKeys() []string {
|
||||
func (b3 B3Propagator) GetAllKeys() []string {
|
||||
if b3.SingleHeader {
|
||||
return []string{B3SingleHeader}
|
||||
}
|
||||
return []string{B3TraceIDHeader, B3SpanIDHeader, B3SampledHeader}
|
||||
}
|
||||
|
||||
func (b3 HTTPB3Propagator) extract(supplier apipropagation.Supplier) core.SpanContext {
|
||||
func (b3 B3Propagator) extract(supplier apipropagation.Supplier) core.SpanContext {
|
||||
tid, err := core.TraceIDFromHex(supplier.Get(B3TraceIDHeader))
|
||||
if err != nil {
|
||||
return core.EmptySpanContext()
|
||||
@@ -128,7 +128,7 @@ func (b3 HTTPB3Propagator) extract(supplier apipropagation.Supplier) core.SpanCo
|
||||
return sc
|
||||
}
|
||||
|
||||
func (b3 HTTPB3Propagator) extractSingleHeader(supplier apipropagation.Supplier) core.SpanContext {
|
||||
func (b3 B3Propagator) extractSingleHeader(supplier apipropagation.Supplier) core.SpanContext {
|
||||
h := supplier.Get(B3SingleHeader)
|
||||
if h == "" || h == "0" {
|
||||
core.EmptySpanContext()
|
||||
@@ -177,7 +177,7 @@ func (b3 HTTPB3Propagator) extractSingleHeader(supplier apipropagation.Supplier)
|
||||
}
|
||||
|
||||
// extractSampledState parses the value of the X-B3-Sampled b3Header.
|
||||
func (b3 HTTPB3Propagator) extractSampledState(sampled string) (flag byte, ok bool) {
|
||||
func (b3 B3Propagator) extractSampledState(sampled string) (flag byte, ok bool) {
|
||||
switch sampled {
|
||||
case "", "0":
|
||||
return 0, true
|
||||
@@ -196,7 +196,7 @@ func (b3 HTTPB3Propagator) extractSampledState(sampled string) (flag byte, ok bo
|
||||
}
|
||||
|
||||
// extracDebugFlag parses the value of the X-B3-Sampled b3Header.
|
||||
func (b3 HTTPB3Propagator) extracDebugFlag(debug string) (flag byte, ok bool) {
|
||||
func (b3 B3Propagator) extracDebugFlag(debug string) (flag byte, ok bool) {
|
||||
switch debug {
|
||||
case "", "0":
|
||||
return 0, true
|
@@ -53,7 +53,7 @@ func BenchmarkExtractB3(b *testing.B) {
|
||||
}
|
||||
|
||||
for _, tg := range testGroup {
|
||||
propagator := propagation.HTTPB3Propagator{tg.singleHeader}
|
||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
||||
for _, tt := range tg.tests {
|
||||
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
@@ -97,7 +97,7 @@ func BenchmarkInjectB3(b *testing.B) {
|
||||
|
||||
for _, tg := range testGroup {
|
||||
id = 0
|
||||
propagator := propagation.HTTPB3Propagator{tg.singleHeader}
|
||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
||||
for _, tt := range tg.tests {
|
||||
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
@@ -55,7 +55,7 @@ func TestExtractB3(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tg := range testGroup {
|
||||
propagator := propagation.HTTPB3Propagator{tg.singleHeader}
|
||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
||||
for _, tt := range tg.tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||
@@ -99,7 +99,7 @@ func TestInjectB3(t *testing.T) {
|
||||
|
||||
for _, tg := range testGroup {
|
||||
id = 0
|
||||
propagator := propagation.HTTPB3Propagator{tg.singleHeader}
|
||||
propagator := propagation.B3Propagator{tg.singleHeader}
|
||||
for _, tt := range tg.tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||
@@ -130,8 +130,8 @@ func TestInjectB3(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPB3Propagator_GetAllKeys(t *testing.T) {
|
||||
propagator := propagation.HTTPB3Propagator{false}
|
||||
func TestB3Propagator_GetAllKeys(t *testing.T) {
|
||||
propagator := propagation.B3Propagator{false}
|
||||
want := []string{
|
||||
propagation.B3TraceIDHeader,
|
||||
propagation.B3SpanIDHeader,
|
||||
@@ -143,8 +143,8 @@ func TestHTTPB3Propagator_GetAllKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPB3PropagatorWithSingleHeader_GetAllKeys(t *testing.T) {
|
||||
propagator := propagation.HTTPB3Propagator{true}
|
||||
func TestB3PropagatorWithSingleHeader_GetAllKeys(t *testing.T) {
|
||||
propagator := propagation.B3Propagator{true}
|
||||
want := []string{
|
||||
propagation.B3SingleHeader,
|
||||
}
|
@@ -36,13 +36,13 @@ const (
|
||||
CorrelationContextHeader = "Correlation-Context"
|
||||
)
|
||||
|
||||
// HTTPTraceContextPropagator propagates SpanContext in W3C TraceContext format.
|
||||
type HTTPTraceContextPropagator struct{}
|
||||
// TraceContextPropagator propagates SpanContext in W3C TraceContext format.
|
||||
type TraceContextPropagator struct{}
|
||||
|
||||
var _ apipropagation.TextFormatPropagator = HTTPTraceContextPropagator{}
|
||||
var _ apipropagation.TextFormatPropagator = TraceContextPropagator{}
|
||||
var traceCtxRegExp = regexp.MustCompile("^[0-9a-f]{2}-[a-f0-9]{32}-[a-f0-9]{16}-[a-f0-9]{2}-?")
|
||||
|
||||
func (hp HTTPTraceContextPropagator) Inject(ctx context.Context, supplier apipropagation.Supplier) {
|
||||
func (hp TraceContextPropagator) Inject(ctx context.Context, supplier apipropagation.Supplier) {
|
||||
sc := trace.CurrentSpan(ctx).SpanContext()
|
||||
if sc.IsValid() {
|
||||
h := fmt.Sprintf("%.2x-%s-%.16x-%.2x",
|
||||
@@ -72,13 +72,13 @@ func (hp HTTPTraceContextPropagator) Inject(ctx context.Context, supplier apipro
|
||||
}
|
||||
}
|
||||
|
||||
func (hp HTTPTraceContextPropagator) Extract(
|
||||
func (hp TraceContextPropagator) Extract(
|
||||
ctx context.Context, supplier apipropagation.Supplier,
|
||||
) (core.SpanContext, dctx.Map) {
|
||||
return hp.extractSpanContext(ctx, supplier), hp.extractCorrelationCtx(ctx, supplier)
|
||||
}
|
||||
|
||||
func (hp HTTPTraceContextPropagator) extractSpanContext(
|
||||
func (hp TraceContextPropagator) extractSpanContext(
|
||||
ctx context.Context, supplier apipropagation.Supplier,
|
||||
) core.SpanContext {
|
||||
h := supplier.Get(TraceparentHeader)
|
||||
@@ -147,7 +147,7 @@ func (hp HTTPTraceContextPropagator) extractSpanContext(
|
||||
return sc
|
||||
}
|
||||
|
||||
func (hp HTTPTraceContextPropagator) extractCorrelationCtx(ctx context.Context, supplier apipropagation.Supplier) dctx.Map {
|
||||
func (hp TraceContextPropagator) extractCorrelationCtx(ctx context.Context, supplier apipropagation.Supplier) dctx.Map {
|
||||
correlationContext := supplier.Get(CorrelationContextHeader)
|
||||
if correlationContext == "" {
|
||||
return dctx.NewEmptyMap()
|
||||
@@ -191,6 +191,6 @@ func (hp HTTPTraceContextPropagator) extractCorrelationCtx(ctx context.Context,
|
||||
})
|
||||
}
|
||||
|
||||
func (hp HTTPTraceContextPropagator) GetAllKeys() []string {
|
||||
func (hp TraceContextPropagator) GetAllKeys() []string {
|
||||
return []string{TraceparentHeader, CorrelationContextHeader}
|
||||
}
|
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func BenchmarkInject(b *testing.B) {
|
||||
var t HTTPTraceContextPropagator
|
||||
var t TraceContextPropagator
|
||||
|
||||
injectSubBenchmarks(b, func(ctx context.Context, b *testing.B) {
|
||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||
@@ -52,7 +52,7 @@ func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) {
|
||||
|
||||
func BenchmarkExtract(b *testing.B) {
|
||||
extractSubBenchmarks(b, func(b *testing.B, req *http.Request) {
|
||||
var propagator HTTPTraceContextPropagator
|
||||
var propagator TraceContextPropagator
|
||||
ctx := context.Background()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
@@ -46,7 +46,7 @@ func mustSpanIDFromHex(s string) (t core.SpanID) {
|
||||
}
|
||||
|
||||
func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
||||
var propagator propagation.HTTPTraceContextPropagator
|
||||
var propagator propagation.TraceContextPropagator
|
||||
tests := []struct {
|
||||
name string
|
||||
header string
|
||||
@@ -139,7 +139,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
|
||||
var propagator propagation.HTTPTraceContextPropagator
|
||||
var propagator propagation.TraceContextPropagator
|
||||
wantSc := core.EmptySpanContext()
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -231,7 +231,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
|
||||
Sampled: false,
|
||||
StartSpanID: &id,
|
||||
}
|
||||
var propagator propagation.HTTPTraceContextPropagator
|
||||
var propagator propagation.TraceContextPropagator
|
||||
tests := []struct {
|
||||
name string
|
||||
sc core.SpanContext
|
||||
@@ -287,7 +287,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
||||
propagator := propagation.HTTPTraceContextPropagator{}
|
||||
propagator := propagation.TraceContextPropagator{}
|
||||
tests := []struct {
|
||||
name string
|
||||
header string
|
||||
@@ -375,7 +375,7 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
||||
propagator := propagation.HTTPTraceContextPropagator{}
|
||||
propagator := propagation.TraceContextPropagator{}
|
||||
tests := []struct {
|
||||
name string
|
||||
header string
|
||||
@@ -401,7 +401,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
||||
propagator := propagation.HTTPTraceContextPropagator{}
|
||||
propagator := propagation.TraceContextPropagator{}
|
||||
tests := []struct {
|
||||
name string
|
||||
kvs []core.KeyValue
|
||||
@@ -474,8 +474,8 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPTraceContextPropagator_GetAllKeys(t *testing.T) {
|
||||
var propagator propagation.HTTPTraceContextPropagator
|
||||
func TestTraceContextPropagator_GetAllKeys(t *testing.T) {
|
||||
var propagator propagation.TraceContextPropagator
|
||||
want := []string{"Traceparent", "Correlation-Context"}
|
||||
got := propagator.GetAllKeys()
|
||||
if diff := cmp.Diff(got, want); diff != "" {
|
Reference in New Issue
Block a user