Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "HTTP" from propagator names #355

Merged
merged 2 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
HostKey = key.New("http.host")
URLKey = key.New("http.url")

propagator = propagation.HTTPTraceContextPropagator{}
propagator = propagation.TraceContextPropagator{}
)

// Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.
Expand Down
4 changes: 2 additions & 2 deletions plugin/othttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func WithPublicEndpoint() Option {

// WithPropagator configures the Handler with a specific propagator. If this
// option isn't specificed then
// go.opentelemetry.io/otel/propagation.HTTPTraceContextPropagator is used.
// go.opentelemetry.io/otel/propagation.TraceContextPropagator is used.
func WithPropagator(p propagation.TextFormatPropagator) Option {
return func(h *Handler) {
h.prop = p
Expand Down Expand Up @@ -131,7 +131,7 @@ func NewHandler(handler http.Handler, operation string, opts ...Option) http.Han
h := Handler{handler: handler, operation: operation}
defaultOpts := []Option{
WithTracer(global.TraceProvider().Tracer("go.opentelemetry.io/plugin/othttp")),
WithPropagator(prop.HTTPTraceContextPropagator{}),
WithPropagator(prop.TraceContextPropagator{}),
WithSpanOptions(trace.WithSpanKind(trace.SpanKindServer)),
}

Expand Down
20 changes: 10 additions & 10 deletions propagation/http_b3_propagator.go → propagation/b3_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand Down