otelsetup

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package otelsetup wires an OpenTelemetry OTLP pipeline for gopheragent with a single call. It is the ONLY package in the repository that imports the OpenTelemetry SDK and OTLP exporters, so a library consumer that does not need export pays nothing: the core (pkg/agent, pkg/telemetry/otelllm, pkg/telemetry/oteltools) depends only on the OTel API.

Usage:

tel, shutdown, err := otelsetup.Setup(ctx, otelsetup.Config{ServiceName: "my-agent"})
if err != nil { ... }
defer shutdown(context.Background())

llm := otelllm.NewProvider(p, otelllm.WithTracer(tel.Tracer), otelllm.WithMeter(tel.Meter), ...)
loop := agent.New(sm, reg, llm, agent.WithTracer(tel.Tracer), agent.WithMeter(tel.Meter))

Endpoint and credentials follow the standard OTEL_* environment variables honored by the OTLP exporters (e.g. OTEL_EXPORTER_OTLP_ENDPOINT). Config fields, when set, take precedence over the environment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ServiceName sets service.name on emitted telemetry. Empty falls back to
	// "gopheragent" (OTEL_SERVICE_NAME still overrides via the SDK if set).
	ServiceName string
	// Endpoint overrides OTEL_EXPORTER_OTLP_ENDPOINT, e.g. "localhost:4317".
	// Empty defers entirely to the environment.
	Endpoint string
	// Insecure disables transport security (plaintext gRPC). Use for local
	// collectors; leave false in production.
	Insecure bool
}

Config controls the OTLP pipeline. The zero value is usable: it names the service "gopheragent" and reads the endpoint from the standard OTEL_* environment variables.

type Providers

type Providers struct {
	Tracer trace.Tracer
	Meter  metric.Meter
}

Providers holds the ready-to-use Tracer and Meter handles for the gopheragent instrumentation scope.

func Setup

func Setup(ctx context.Context, cfg Config) (*Providers, func(context.Context) error, error)

Setup builds an OTLP TracerProvider and MeterProvider, registers them as the global OpenTelemetry providers, and returns Tracer/Meter handles plus a shutdown function that flushes and closes both exporters. Callers should defer the shutdown function so buffered spans and metrics are exported on exit.

Jump to

Keyboard shortcuts

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