otel

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package otel exports spans and metrics to an OpenTelemetry collector using the OTLP HTTP/JSON protocol.

Use NewExporter to create an exporter, then chain its Exporter.ProcessEvent method with other exporters:

otelExporter := otel.NewExporter(ctx,
	otel.WithEndpoint("http://localhost:4318"),
	otel.WithServiceName("myservice"),
)
event.SetExporter(otelExporter.ProcessEvent)

The exporter batches telemetry and flushes periodically in a background goroutine. Call Exporter.Flush to force an immediate export.

Index

Constants

View Source
const (
	DefaultEndpoint    = "http://localhost:4318"
	DefaultServiceName = "unknown_service"
	DefaultTimeout     = 10 * time.Second
	DefaultFlushPeriod = 2 * time.Second
)

Default configuration values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

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

Exporter exports spans and metrics to an OTLP HTTP endpoint.

func NewExporter

func NewExporter(ctx context.Context, opts ...Option) *Exporter

NewExporter creates an exporter that sends spans to an OTLP endpoint. Spans are collected and exported periodically in a background goroutine. When the context is done, remaining spans are flushed.

func (*Exporter) Flush

func (e *Exporter) Flush()

Flush exports all collected spans and metrics to the OTLP endpoint.

func (*Exporter) ProcessEvent

func (e *Exporter) ProcessEvent(ctx context.Context, ev core.Event, lm label.Map) context.Context

ProcessEvent handles events and collects completed spans and metrics.

type Option

type Option func(*Exporter)

Option configures an OTelExporter.

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint sets the OTLP HTTP endpoint.

func WithFlushPeriod

func WithFlushPeriod(period time.Duration) Option

WithFlushPeriod sets the interval for automatic background flushing.

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the service name for exported spans.

func WithServiceVersion

func WithServiceVersion(version string) Option

WithServiceVersion sets the service version for exported telemetry.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the HTTP client timeout.

Jump to

Keyboard shortcuts

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