otelhelpers

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

otelhelpers is a package of helper functions for dealing with otel traceparent propagation over files and environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithCmdlineOrEnvTraceparent added in v0.0.3

func ContextWithCmdlineOrEnvTraceparent(ctx context.Context) context.Context

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

func ContextWithCmdlineTraceparent(ctx context.Context) context.Context

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

func ContextWithEnvTraceparent(ctx context.Context) context.Context

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

func ContextWithTraceparentString(ctx context.Context, traceparent string) context.Context

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

func TraceparentStringFromContext(ctx context.Context) string

TraceparentStringFromContext gets the current trace from the context and returns a W3C traceparent string. Depends on global OTel TextMapPropagator.

Types

type SimpleCarrier

type SimpleCarrier map[string]string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL