mirror of
https://github.com/golang/go
synced 2024-11-19 03:54:42 -07:00
26 lines
518 B
Go
26 lines
518 B
Go
|
// Copyright 2019 The Go Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package telemetry
|
||
|
|
||
|
import "context"
|
||
|
|
||
|
type contextKeyType int
|
||
|
|
||
|
const (
|
||
|
spanContextKey = contextKeyType(iota)
|
||
|
)
|
||
|
|
||
|
func WithSpan(ctx context.Context, span *Span) context.Context {
|
||
|
return context.WithValue(ctx, spanContextKey, span)
|
||
|
}
|
||
|
|
||
|
func GetSpan(ctx context.Context) *Span {
|
||
|
v := ctx.Value(spanContextKey)
|
||
|
if v == nil {
|
||
|
return nil
|
||
|
}
|
||
|
return v.(*Span)
|
||
|
}
|