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

Rename CorrelationContext to Baggage #1142

Merged
merged 4 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Rename Jaeger tags used for instrumentation library information to reflect changes in OpenTelemetry specification. (#1119)
- Rename `ProbabilitySampler` to `TraceIDRatioBased` and change semantics to ignore parent span sampling status. (#1115)
- Move `tools` package under `internal`. (#1141)
- Move `go.opentelemetry.io/otel/api/correlation` package to `go.opentelemetry.io/otel/api/baggage`. (#1142)
The `correlation.CorrelationContext` propagator has been renamed `baggage.Baggage`. Other exported functions and types are unchanged.

## [0.11.0] - 2020-08-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package correlation
package baggage

import (
"context"
Expand All @@ -25,27 +25,27 @@ import (

// Temporary header name until W3C finalizes format.
// https://github.com/open-telemetry/opentelemetry-specification/blob/18b2752ebe6c7f0cdd8c7b2bcbdceb0ae3f5ad95/specification/correlationcontext/api.md#header-name
const correlationContextHeader = "otcorrelations"
const baggageHeader = "otcorrelations"

// CorrelationContext propagates Key:Values in W3C CorrelationContext
// Baggage propagates Key:Values in W3C CorrelationContext
// format.
// nolint:golint
type CorrelationContext struct{}
type Baggage struct{}

var _ propagation.HTTPPropagator = CorrelationContext{}
var _ propagation.HTTPPropagator = Baggage{}

// DefaultHTTPPropagator returns the default context correlation HTTP
// propagator.
func DefaultHTTPPropagator() propagation.HTTPPropagator {
return CorrelationContext{}
return Baggage{}
}

// Inject implements HTTPInjector.
func (CorrelationContext) Inject(ctx context.Context, supplier propagation.HTTPSupplier) {
correlationCtx := MapFromContext(ctx)
func (b Baggage) Inject(ctx context.Context, supplier propagation.HTTPSupplier) {
baggageMap := MapFromContext(ctx)
firstIter := true
var headerValueBuilder strings.Builder
correlationCtx.Foreach(func(kv label.KeyValue) bool {
baggageMap.Foreach(func(kv label.KeyValue) bool {
if !firstIter {
headerValueBuilder.WriteRune(',')
}
Expand All @@ -57,21 +57,21 @@ func (CorrelationContext) Inject(ctx context.Context, supplier propagation.HTTPS
})
if headerValueBuilder.Len() > 0 {
headerString := headerValueBuilder.String()
supplier.Set(correlationContextHeader, headerString)
supplier.Set(baggageHeader, headerString)
}
}

// Extract implements HTTPExtractor.
func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context {
correlationContext := supplier.Get(correlationContextHeader)
if correlationContext == "" {
func (b Baggage) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context {
baggage := supplier.Get(baggageHeader)
if baggage == "" {
return ctx
}

contextValues := strings.Split(correlationContext, ",")
keyValues := make([]label.KeyValue, 0, len(contextValues))
for _, contextValue := range contextValues {
valueAndProps := strings.Split(contextValue, ";")
baggageValues := strings.Split(baggage, ",")
keyValues := make([]label.KeyValue, 0, len(baggageValues))
for _, baggageValue := range baggageValues {
valueAndProps := strings.Split(baggageValue, ";")
if len(valueAndProps) < 1 {
continue
}
Expand Down Expand Up @@ -113,6 +113,6 @@ func (CorrelationContext) Extract(ctx context.Context, supplier propagation.HTTP
}

// GetAllKeys implements HTTPPropagator.
func (CorrelationContext) GetAllKeys() []string {
return []string{correlationContextHeader}
func (b Baggage) GetAllKeys() []string {
return []string{baggageHeader}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package correlation_test
package baggage_test

import (
"context"
Expand All @@ -22,13 +22,13 @@ import (

"github.com/google/go-cmp/cmp"

"go.opentelemetry.io/otel/api/correlation"
"go.opentelemetry.io/otel/api/baggage"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/label"
)

func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
props := propagation.New(propagation.WithExtractors(correlation.CorrelationContext{}))
func TestExtractValidBaggageFromHTTPReq(t *testing.T) {
props := propagation.New(propagation.WithExtractors(baggage.Baggage{}))
tests := []struct {
name string
header string
Expand Down Expand Up @@ -91,18 +91,18 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {

ctx := context.Background()
ctx = propagation.ExtractHTTP(ctx, props, req.Header)
gotCorCtx := correlation.MapFromContext(ctx)
wantCorCtx := correlation.NewMap(correlation.MapUpdate{MultiKV: tt.wantKVs})
if gotCorCtx.Len() != wantCorCtx.Len() {
gotBaggage := baggage.MapFromContext(ctx)
wantBaggage := baggage.NewMap(baggage.MapUpdate{MultiKV: tt.wantKVs})
if gotBaggage.Len() != wantBaggage.Len() {
t.Errorf(
"Got and Want CorCtx are not the same size %d != %d",
gotCorCtx.Len(),
wantCorCtx.Len(),
"Got and Want Baggage are not the same size %d != %d",
gotBaggage.Len(),
wantBaggage.Len(),
)
}
totalDiff := ""
wantCorCtx.Foreach(func(keyValue label.KeyValue) bool {
val, _ := gotCorCtx.Value(keyValue.Key)
wantBaggage.Foreach(func(keyValue label.KeyValue) bool {
val, _ := gotBaggage.Value(keyValue.Key)
diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{}))
if diff != "" {
totalDiff += diff + "\n"
Expand All @@ -117,7 +117,7 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
}

func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
props := propagation.New(propagation.WithExtractors(correlation.CorrelationContext{}))
props := propagation.New(propagation.WithExtractors(baggage.Baggage{}))
tests := []struct {
name string
header string
Expand Down Expand Up @@ -150,20 +150,20 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req.Header.Set("otcorrelations", tt.header)

ctx := correlation.NewContext(context.Background(), tt.hasKVs...)
wantCorCtx := correlation.MapFromContext(ctx)
ctx := baggage.NewContext(context.Background(), tt.hasKVs...)
wantBaggage := baggage.MapFromContext(ctx)
ctx = propagation.ExtractHTTP(ctx, props, req.Header)
gotCorCtx := correlation.MapFromContext(ctx)
if gotCorCtx.Len() != wantCorCtx.Len() {
gotBaggage := baggage.MapFromContext(ctx)
if gotBaggage.Len() != wantBaggage.Len() {
t.Errorf(
"Got and Want CorCtx are not the same size %d != %d",
gotCorCtx.Len(),
wantCorCtx.Len(),
"Got and Want Baggage are not the same size %d != %d",
gotBaggage.Len(),
wantBaggage.Len(),
)
}
totalDiff := ""
wantCorCtx.Foreach(func(keyValue label.KeyValue) bool {
val, _ := gotCorCtx.Value(keyValue.Key)
wantBaggage.Foreach(func(keyValue label.KeyValue) bool {
val, _ := gotBaggage.Value(keyValue.Key)
diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{}))
if diff != "" {
totalDiff += diff + "\n"
Expand All @@ -174,8 +174,8 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
}
}

func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
propagator := correlation.CorrelationContext{}
func TestInjectBaggageToHTTPReq(t *testing.T) {
propagator := baggage.Baggage{}
props := propagation.New(propagation.WithInjectors(propagator))
tests := []struct {
name string
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
ctx := correlation.ContextWithMap(context.Background(), correlation.NewMap(correlation.MapUpdate{MultiKV: tt.kvs}))
ctx := baggage.ContextWithMap(context.Background(), baggage.NewMap(baggage.MapUpdate{MultiKV: tt.kvs}))
propagation.InjectHTTP(ctx, props, req.Header)

gotHeader := req.Header.Get("otcorrelations")
Expand All @@ -250,7 +250,7 @@ func TestInjectCorrelationContextToHTTPReq(t *testing.T) {
}

func TestTraceContextPropagator_GetAllKeys(t *testing.T) {
var propagator correlation.CorrelationContext
var propagator baggage.Baggage
want := []string{"otcorrelations"}
got := propagator.GetAllKeys()
if diff := cmp.Diff(got, want); diff != "" {
Expand Down
2 changes: 1 addition & 1 deletion api/correlation/context.go → api/baggage/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package correlation
package baggage

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions api/correlation/doc.go → api/baggage/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package correlation provides types and utilities for correlation features.
package correlation // import "go.opentelemetry.io/otel/api/correlation"
// Package baggage provides types and utilities for baggage features.
package baggage // import "go.opentelemetry.io/otel/api/baggage"
2 changes: 1 addition & 1 deletion api/correlation/map.go → api/baggage/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package correlation
package baggage

import "go.opentelemetry.io/otel/label"

Expand Down
2 changes: 1 addition & 1 deletion api/correlation/map_test.go → api/baggage/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package correlation
package baggage

import (
"fmt"
Expand Down
10 changes: 5 additions & 5 deletions api/global/internal/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"sync"
"sync/atomic"

"go.opentelemetry.io/otel/api/correlation"
"go.opentelemetry.io/otel/api/baggage"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/trace"
Expand Down Expand Up @@ -121,13 +121,13 @@ func defaultPropagatorsValue() *atomic.Value {
}

// getDefaultPropagators returns a default Propagators, configured
// with W3C trace and correlation context propagation.
// with W3C trace and baggage propagation.
func getDefaultPropagators() propagation.Propagators {
tcPropagator := propagators.TraceContext{}
ccPropagator := correlation.CorrelationContext{}
bagPropagator := baggage.Baggage{}
return propagation.New(
propagation.WithExtractors(tcPropagator, ccPropagator),
propagation.WithInjectors(tcPropagator, ccPropagator),
propagation.WithExtractors(tcPropagator, bagPropagator),
propagation.WithInjectors(tcPropagator, bagPropagator),
)
}

Expand Down
26 changes: 13 additions & 13 deletions bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
otext "github.com/opentracing/opentracing-go/ext"
otlog "github.com/opentracing/opentracing-go/log"

otelcorrelation "go.opentelemetry.io/otel/api/correlation"
otelbaggage "go.opentelemetry.io/otel/api/baggage"
otelglobal "go.opentelemetry.io/otel/api/global"
otelpropagation "go.opentelemetry.io/otel/api/propagation"
oteltrace "go.opentelemetry.io/otel/api/trace"
Expand All @@ -38,15 +38,15 @@ import (
)

type bridgeSpanContext struct {
baggageItems otelcorrelation.Map
baggageItems otelbaggage.Map
otelSpanContext oteltrace.SpanContext
}

var _ ot.SpanContext = &bridgeSpanContext{}

func newBridgeSpanContext(otelSpanContext oteltrace.SpanContext, parentOtSpanContext ot.SpanContext) *bridgeSpanContext {
bCtx := &bridgeSpanContext{
baggageItems: otelcorrelation.NewEmptyMap(),
baggageItems: otelbaggage.NewEmptyMap(),
otelSpanContext: otelSpanContext,
}
if parentOtSpanContext != nil {
Expand All @@ -66,7 +66,7 @@ func (c *bridgeSpanContext) ForeachBaggageItem(handler func(k, v string) bool) {

func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) {
crk := http.CanonicalHeaderKey(restrictedKey)
c.baggageItems = c.baggageItems.Apply(otelcorrelation.MapUpdate{SingleKV: label.String(crk, value)})
c.baggageItems = c.baggageItems.Apply(otelbaggage.MapUpdate{SingleKV: label.String(crk, value)})
}

func (c *bridgeSpanContext) baggageItem(restrictedKey string) string {
Expand Down Expand Up @@ -327,12 +327,12 @@ func (t *BridgeTracer) SetPropagators(propagators otelpropagation.Propagators) {
}

func (t *BridgeTracer) NewHookedContext(ctx context.Context) context.Context {
ctx = otelcorrelation.ContextWithSetHook(ctx, t.correlationSetHook)
ctx = otelcorrelation.ContextWithGetHook(ctx, t.correlationGetHook)
ctx = otelbaggage.ContextWithSetHook(ctx, t.baggageSetHook)
ctx = otelbaggage.ContextWithGetHook(ctx, t.baggageGetHook)
return ctx
}

func (t *BridgeTracer) correlationSetHook(ctx context.Context) context.Context {
func (t *BridgeTracer) baggageSetHook(ctx context.Context) context.Context {
span := ot.SpanFromContext(ctx)
if span == nil {
t.warningHandler("No active OpenTracing span, can not propagate the baggage items from OpenTelemetry context\n")
Expand All @@ -346,16 +346,16 @@ func (t *BridgeTracer) correlationSetHook(ctx context.Context) context.Context {
// we clear the context only to avoid calling a get hook
// during MapFromContext, but otherwise we don't change the
// context, so we don't care about the old hooks.
clearCtx, _, _ := otelcorrelation.ContextWithNoHooks(ctx)
m := otelcorrelation.MapFromContext(clearCtx)
clearCtx, _, _ := otelbaggage.ContextWithNoHooks(ctx)
m := otelbaggage.MapFromContext(clearCtx)
m.Foreach(func(kv label.KeyValue) bool {
bSpan.setBaggageItemOnly(string(kv.Key), kv.Value.Emit())
return true
})
return ctx
}

func (t *BridgeTracer) correlationGetHook(ctx context.Context, m otelcorrelation.Map) otelcorrelation.Map {
func (t *BridgeTracer) baggageGetHook(ctx context.Context, m otelbaggage.Map) otelbaggage.Map {
span := ot.SpanFromContext(ctx)
if span == nil {
t.warningHandler("No active OpenTracing span, can not propagate the baggage items from OpenTracing span context\n")
Expand All @@ -374,7 +374,7 @@ func (t *BridgeTracer) correlationGetHook(ctx context.Context, m otelcorrelation
for k, v := range items {
kv = append(kv, label.String(k, v))
}
return m.Apply(otelcorrelation.MapUpdate{MultiKV: kv})
return m.Apply(otelbaggage.MapUpdate{MultiKV: kv})
}

// StartSpan is a part of the implementation of the OpenTracing Tracer
Expand Down Expand Up @@ -613,7 +613,7 @@ func (t *BridgeTracer) Inject(sm ot.SpanContext, format interface{}, carrier int
sc: bridgeSC.otelSpanContext,
}
ctx := oteltrace.ContextWithSpan(context.Background(), fs)
ctx = otelcorrelation.ContextWithMap(ctx, bridgeSC.baggageItems)
ctx = otelbaggage.ContextWithMap(ctx, bridgeSC.baggageItems)
otelpropagation.InjectHTTP(ctx, t.getPropagators(), header)
return nil
}
Expand All @@ -632,7 +632,7 @@ func (t *BridgeTracer) Extract(format interface{}, carrier interface{}) (ot.Span
}
header := http.Header(hhcarrier)
ctx := otelpropagation.ExtractHTTP(context.Background(), t.getPropagators(), header)
baggage := otelcorrelation.MapFromContext(ctx)
baggage := otelbaggage.MapFromContext(ctx)
otelSC, _, _ := otelparent.GetSpanContextAndLinks(ctx, false)
bridgeSC := &bridgeSpanContext{
baggageItems: baggage,
Expand Down
Loading