1
0
mirror of https://github.com/golang/go synced 2024-10-01 12:28:37 -06:00
go/internal/telemetry/context.go

26 lines
518 B
Go
Raw Normal View History

// 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)
}