otel

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 19 Imported by: 0

README

barney.ci/go-otel

This repo contains OpenTelemetry-related code.

JaegerSetup

JaegerSetup provides boilerplate, slightly Arista-optimized production of Jaeger TracerProviders.

Typical applications require some environment. Kubernetes example:

kind: Deployment
spec:
  template:
    spec:
      containers:
        env:
        - name: JAEGER_ENABLED
          value: "true"
        - name: OTEL_EXPORTER_JAEGER_AGENT_HOST
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        - name: OTEL_SAMPLER_JAEGER_CONFIG_URL_TEMPLATE
          value: http://${OTEL_EXPORTER_JAEGER_AGENT_HOST}:5778/

Please note that there are a few similar-looking URLs floating around for the URL_TEMPLATE. The different URLs are meant for different collector libraries and have subtly different output. You likely need to change your URL_TEMPLATE if you are migrating from a different telemetry library so note carefully this syntax.

EnvironCarrier

EnvironCarrier provides a TextMapCarrier interface to the process environment.

UberTraceContext

UberTraceContext is a propagator that supports the "Jaeger native propagation format", better known as the "uber-trace-id" header.

Documentation

Index

Constants

View Source
const EnvGateCue = "true"
View Source
const EnvGateName = "JAEGER_ENABLED"
View Source
const EnvSamplerTemplateName = "OTEL_SAMPLER_JAEGER_CONFIG_URL_TEMPLATE"
View Source
const EnvironCarrierPrefix = "OTELTEXTMAP_" // exactly 1 underscore, trailing

EnvironCarrierPrefix defines the prefix we attach to carrier key names to store them in the process environment.

Variables

This section is empty.

Functions

func ContextWithEnvPropagation

func ContextWithEnvPropagation(parent context.Context) context.Context

ContextWithEnvPropagation returns a copy of a parent Context with trace context propagation from the process environment.

func JaegerSetup

func JaegerSetup(name string, with ...setupOptionFunc) (
	tp *trace.TracerProvider, closer closerFunc, err error,
)

JaegerSetup returns a jaeger TracerProvider and a closer function to shut down the provider.

Options order can be important. For example, WithRemoteSampler sets the sampler to one that falls back to any existing sampler, whilst WithSampler sets the sampler to the passed argument and overwrites the existing sampler.

It's a good idea to pass WithLogger first, so errors raised by subsequent options will be sent to that callback.

func MapCarrierAsEnviron

func MapCarrierAsEnviron(mc propagation.MapCarrier) []string

MapCarrierAsEnviron returns the contents of a MapCarrier as a slice of "key=value" strings, suitable for e.g. os.exec.Cmd.Env

func WithAgentExporter

func WithAgentExporter() setupOptionFunc

WithAgentExpoter causes JaegerSetup to configure an exporter targeting the Jaeger agent endpoint

func WithEnvGate

func WithEnvGate() setupOptionFunc

WithEnvGate causes a call to JaegerSetup to be a no-op unless the environment variable defined by EnvGatename is set to the value defined by EnvGateCue

func WithGeneralPropagatorSetup

func WithGeneralPropagatorSetup() setupOptionFunc

WithGeneralPropagatorSetup causes JaegerSetup to configure the default propagator with some basic propagators

func WithLogger

func WithLogger(logger logr.Logger) setupOptionFunc

WithLogger configures the given logger to be used for printing errors or info at runtime emitted by the tracer implementation. If unset, a default value of github.com/go-logr/stdr.New(log.Default()) will be used.

func WithRemoteSampler

func WithRemoteSampler() setupOptionFunc

WithRemoteSampler causes JaegerSetup to configure Jaeger with a remote sampler URL constructed using the environment variable defined by EnvSamplerTemplateName, falling back to any previously configured sampler

func WithSampler

func WithSampler(s trace.Sampler) setupOptionFunc

WithSampler causes JaegerSetup to configure Jaeger with the provided sampler only

func WithShutdownTimeout

func WithShutdownTimeout(t time.Duration) setupOptionFunc

WithShutdownTimeout limits the amount of time that the close function returned by JaegerSetup may wait

Types

type EnvironCarrier

type EnvironCarrier struct{}

EnvironCarrier provides a TextMapCarrier interface to the process environment.

func (EnvironCarrier) Get

func (e EnvironCarrier) Get(key string) string

func (EnvironCarrier) Keys

func (e EnvironCarrier) Keys() []string

func (EnvironCarrier) Set

func (e EnvironCarrier) Set(key string, value string)

type UberTraceContext

type UberTraceContext struct{}

UberTraceContext is a propagator that supports the "Jaeger native propagation format", better known as the "uber-trace-id" header. See: https://www.jaegertracing.io/docs/1.40/client-libraries/#propagation-format

UberTraceContext will propagate the uber-trace-id header to guarantee traces employing this type of header are not broken. It is up to the users of this propagator to choose if they want to participate in a trace by modifying the uber-trace-id header and relevant parts of the uber-trace-id header containing their proprietary information.

UberTraceContext operates on the came principle as the upstream TraceContext propagator, which injects and extracts the "W3C trace context format", better known as the "traceparent" header.

When a CompositeTextMapPropagator combines TraceContext and UberTraceContext propagators, SpanContexts will be propagated forward as both types of header, and both inbound header types will be extractable into a local SpanContext (with the later-defined propagator's header taking overriding precedence).

func (UberTraceContext) Extract

Extract reads uber-trace-id from the carrier into a returned Context.

The returned Context will be a copy of ctx and contain the extracted uber-trace-id as the remote SpanContext. If the extracted uber-trace-id is invalid, the passed ctx will be returned directly instead.

func (UberTraceContext) Fields

func (tc UberTraceContext) Fields() []string

Fields returns the keys whose values are set with Inject.

func (UberTraceContext) Inject

func (tc UberTraceContext) Inject(ctx context.Context, carrier propagation.TextMapCarrier)

Inject sets uber-trace-id from the Context into the carrier.

Jump to

Keyboard shortcuts

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