otlp

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package otlp is a logging sink that sends records to an OpenTelemetry collector, or any service that takes OTLP over HTTP (Grafana Cloud, Honeycomb, New Relic, SigNoz, Axiom…), as OTLP/HTTP JSON:

logging.New(logging.Options{Sinks: []logging.Sink{otlp.New(otlp.Options{})}})

With no options it reads the standard environment variables: OTEL_EXPORTER_OTLP_LOGS_ENDPOINT or OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_HEADERS or OTEL_EXPORTER_OTLP_HEADERS, OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES. Records logged in a request with a trusted traceparent carry its trace and span.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Severity

func Severity(l slog.Level) int

Severity is OpenTelemetry's severity number for a slog level: DEBUG is 5, INFO 9, WARN 13 and ERROR 17, with the levels between in between.

Types

type Options

type Options struct {
	// Endpoint is the URL logs are posted to, ending in /v1/logs. The
	// default is OTEL_EXPORTER_OTLP_LOGS_ENDPOINT's, or
	// OTEL_EXPORTER_OTLP_ENDPOINT's with /v1/logs added, or
	// http://localhost:4318/v1/logs.
	Endpoint string
	// Headers are sent with each request, such as an API key.
	Headers http.Header
	// ServiceName is the service.name resource attribute. The default is
	// OTEL_SERVICE_NAME's, or the program's name.
	ServiceName string
	// Resource adds resource attributes, after OTEL_RESOURCE_ATTRIBUTES'.
	Resource map[string]string
	// NoGzip sends requests uncompressed.
	NoGzip bool
	// Client sends the requests. The default is http.DefaultClient.
	Client *http.Client
}

Options configures the sink. Unset fields come from the environment.

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink sends records over OTLP/HTTP. Make one with New.

func New

func New(o Options) *Sink

New returns an OTLP sink.

func (*Sink) Export

func (s *Sink) Export(ctx context.Context, entries []logging.Entry) error

Export implements logging.Sink.

func (*Sink) Name

func (*Sink) Name() string

Name implements the name logging reports errors with.

Jump to

Keyboard shortcuts

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