package otel
import "golang.org/x/tools/internal/event/export/otel"
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
- type Exporter
- func NewExporter(ctx context.Context, opts ...Option) *Exporter
- func (e *Exporter) Flush()
- func (e *Exporter) ProcessEvent(ctx context.Context, ev core.Event, lm label.Map) context.Context
- type Option
Constants ¶
const ( DefaultEndpoint = "http://localhost:4318" DefaultServiceName = "unknown_service" DefaultTimeout = 10 * time.Second DefaultFlushPeriod = 2 * time.Second )
Default configuration values.
Types ¶
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
Exporter exports spans and metrics to an OTLP HTTP endpoint.
func NewExporter ¶
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 ¶
ProcessEvent handles events and collects completed spans and metrics.
type Option ¶
type Option func(*Exporter)
Option configures an OTelExporter.
func WithEndpoint ¶
WithEndpoint sets the OTLP HTTP endpoint.
func WithFlushPeriod ¶
WithFlushPeriod sets the interval for automatic background flushing.
func WithServiceName ¶
WithServiceName sets the service name for exported spans.
func WithServiceVersion ¶
WithServiceVersion sets the service version for exported telemetry.
func WithTimeout ¶
WithTimeout sets the HTTP client timeout.
Source Files ¶
common.go metrics.go options.go otel.go otlp.go traces.go
- Version
- v0.44.0 (latest)
- Published
- Apr 9, 2026
- Platform
- linux/amd64
- Imports
- 18 packages
- Last checked
- 1 hour ago –
Tools for package owners.