-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
30 changed files
with
271 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.