Documentation ¶
Overview ¶
otelhelpers is a package of helper functions for dealing with otel traceparent propagation over files and environment variables.
Index ¶
- func ContextWithCmdlineOrEnvTraceparent(ctx context.Context) context.Context
- func ContextWithCmdlineTraceparent(ctx context.Context) context.Context
- func ContextWithEnvTraceparent(ctx context.Context) context.Context
- func ContextWithTraceparentString(ctx context.Context, traceparent string) context.Context
- func TraceparentStringFromContext(ctx context.Context) string
- type SimpleCarrier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithCmdlineOrEnvTraceparent ¶ added in v0.0.3
ContextWithCmdlineOrEnvTraceparent checks the environment variable first, then /proc/cmdline and returns a context with them set, if available. When both are present, the cmdline is prioritized. When neither is present, the original context is returned as-is. Depends on global OTel TextMapPropagator.
func ContextWithCmdlineTraceparent ¶ added in v0.0.3
ContextWithLinuxCmdlineTraceparent looks in /proc/cmdline for a traceparent= command line option and returns the context with that value as traceparent if it's there. Does no validation. Returns the original context if there is no cmdline option or if there's an error doing the read. This is Linux-only but should be safe on other operating systems. Depends on global OTel TextMapPropagator.
func ContextWithEnvTraceparent ¶
ContextWithEnvTraceparent is a helper that looks for the the TRACEPARENT environment variable and if it's set, it grabs the traceparent and adds it to the context it returns. When there is no envvar or it's empty, the original context is returned unmodified. Depends on global OTel TextMapPropagator.
func ContextWithTraceparentString ¶ added in v0.0.3
ContextWithTraceparentString takes a W3C traceparent string, uses the otel carrier code to get it into a context it returns ready to go. Depends on global OTel TextMapPropagator.
func TraceparentStringFromContext ¶ added in v0.0.3
TraceparentStringFromContext gets the current trace from the context and returns a W3C traceparent string. Depends on global OTel TextMapPropagator.
Types ¶
type SimpleCarrier ¶
SimpleCarrier is an abstraction for handling traceparent propagation that needs a type that implements the propagation.TextMapCarrier(). This is the simplest possible implementation that is a little fragile but since we're not doing anything else with it, it's fine for this.
func (SimpleCarrier) Clear ¶
func (otp SimpleCarrier) Clear()
Clear implements the otel interface for propagation.
func (SimpleCarrier) Get ¶
func (otp SimpleCarrier) Get(key string) string
Get implements the otel interface for propagation.
func (SimpleCarrier) Keys ¶
func (otp SimpleCarrier) Keys() []string
Keys implements the otel interface for propagation.
func (SimpleCarrier) Set ¶
func (otp SimpleCarrier) Set(key, value string)
Set implements the otel interface for propagation.