1// Copyright 2019 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package telemetry 6 7import "context" 8 9type contextKeyType int 10 11const ( 12 spanContextKey = contextKeyType(iota) 13) 14 15func WithSpan(ctx context.Context, span *Span) context.Context { 16 return context.WithValue(ctx, spanContextKey, span) 17} 18 19func GetSpan(ctx context.Context) *Span { 20 v := ctx.Value(spanContextKey) 21 if v == nil { 22 return nil 23 } 24 return v.(*Span) 25} 26