otel

package
v0.17.5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package otel provides helpers for using OpenTelemetry with Axiom.

Usage:

import "github.com/axiomhq/axiom-go/axiom/otel"

Different levels of helpers are available, from just setting up tracing to getting access to lower level components to costumize tracing or integrate with existing OpenTelemetry setups:

  • InitTracing: Initializes OpenTelemetry and sets the global tracer prodiver so the official OpenTelemetry Go SDK can be used to get a tracer and instrument code. Sane defaults for the tracer provider are applied.
  • TracerProvider: Configures and returns a new OpenTelemetry tracer provider but does not set it as the global tracer provider.
  • TraceExporter: Configures and returns a new OpenTelemetry trace exporter. This sets up the exporter that sends traces to Axiom but allows for a more advanced setup of the tracer provider.

If you wish for traces to propagate beyond the current process, you need to set the global propagator to the OpenTelemetry trace context propagator. This can be done by calling:

import (
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/propagation"
)
// ...
otel.SetTextMapPropagator(propagation.TraceContext{})
// or
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))

Refer to https://opentelemetry.io/docs/instrumentation/go/manual/#propagators-and-context for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTracing

func InitTracing(ctx context.Context, dataset, serviceName, serviceVersion string, options ...TraceOption) (func() error, error)

InitTracing initializes OpenTelemetry tracing with the given service name, version and options. If initialization succeeds, the returned cleanup function must be called to shut down the tracer provider and flush any remaining spans. The error returned by the cleanup function must be checked, as well.

func TraceExporter

func TraceExporter(ctx context.Context, dataset string, options ...TraceOption) (trace.SpanExporter, error)

TraceExporter configures and returns a new exporter for OpenTelemetry spans.

func TracerProvider

func TracerProvider(ctx context.Context, dataset, serviceName, serviceVersion string, options ...TraceOption) (*trace.TracerProvider, error)

TracerProvider configures and returns a new OpenTelemetry tracer provider.

func UserAgentAttribute

func UserAgentAttribute() attribute.KeyValue

UserAgentAttribute returns a new OpenTelemetry axiom-go user agent attribute.

Types

type TraceOption

type TraceOption func(c *traceConfig) error

A TraceOption modifies the behaviour of OpenTelemetry traces. Nonetheless, the official "OTEL_*" environment variables are preferred over the options or "AXIOM_*" environment variables.

func SetAPIEndpoint

func SetAPIEndpoint(path string) TraceOption

SetAPIEndpoint specifies the api endpoint used by the client.

func SetNoEnv

func SetNoEnv() TraceOption

SetNoEnv prevents the client from deriving its configuration from the environment (by auto reading "AXIOM_*" environment variables).

func SetOrganizationID

func SetOrganizationID(organizationID string) TraceOption

SetOrganizationID specifies the organization ID used by the client.

Can also be specified using the "AXIOM_ORG_ID" environment variable.

func SetTimeout

func SetTimeout(timeout time.Duration) TraceOption

SetTimeout specifies the http timeout used by the client.

func SetToken added in v0.13.1

func SetToken(token string) TraceOption

SetToken specifies the authentication token used by the client.

Can also be specified using the "AXIOM_TOKEN" environment variable.

func SetURL

func SetURL(baseURL string) TraceOption

SetURL sets the base URL used by the client.

Can also be specified using the "AXIOM_URL" environment variable.

Jump to

Keyboard shortcuts

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