1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-15 01:04:25 +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:
Krzesimir Nowak
2020-01-28 19:13:46 +01:00
committed by Rahul Patel
parent 437d9af9ab
commit 6b4acf47b8
30 changed files with 271 additions and 312 deletions

View 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()
}