otel

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package otel provides OpenTelemetry initialisation helpers for the LFX MCP server.

Index

Constants

View Source
const (
	// OTelProtocolGRPC is the spec value for the gRPC OTLP transport protocol.
	// Ref: https://opentelemetry.io/docs/specs/otel/protocol/exporter/#specify-protocol
	OTelProtocolGRPC = "grpc"
	// OTelProtocolHTTPProtobuf is the spec value for the HTTP/protobuf OTLP transport protocol.
	OTelProtocolHTTPProtobuf = "http/protobuf"
	// OTelProtocolHTTPJSON is the spec value for the HTTP/JSON OTLP transport protocol.
	// The Go SDK does not support this; it is warned about and treated as http/protobuf.
	OTelProtocolHTTPJSON = "http/json"

	// OTelExporterOTLP configures signals to export via OTLP.
	OTelExporterOTLP = "otlp"
	// OTelExporterNone disables exporting for a signal.
	OTelExporterNone = "none"
)

Variables

This section is empty.

Functions

func SetupSDKWithConfig

func SetupSDKWithConfig(ctx context.Context, cfg Config) (shutdown func(context.Context) error, err error)

SetupSDKWithConfig bootstraps the OpenTelemetry pipeline with the provided configuration. Call the returned shutdown function (e.g. via defer) for proper cleanup.

Types

type Config

type Config struct {
	// ServiceName is the name of the service for resource identification.
	// Env: OTEL_SERVICE_NAME (default: "lfx-mcp-server")
	ServiceName string
	// ServiceVersion is the version of the service.
	// Env: OTEL_SERVICE_VERSION
	ServiceVersion string
	// Protocol specifies the OTLP transport protocol: "grpc", "http/protobuf", or "http/json".
	// Env: OTEL_EXPORTER_OTLP_PROTOCOL (default: "grpc")
	Protocol string
	// Endpoint is the OTLP collector endpoint.
	// For gRPC: typically "http://localhost:4317" or bare "localhost:4317" (http:// is assumed).
	// For HTTP: typically "http://localhost:4318" or bare "localhost:4318" (http:// is assumed).
	// To use TLS, provide an explicit https:// scheme.
	// Env: OTEL_EXPORTER_OTLP_ENDPOINT
	Endpoint string
	// TracesExporter specifies the traces exporter: "otlp" or "none".
	// Env: OTEL_TRACES_EXPORTER (default: "none")
	TracesExporter string
	// TracesSampler specifies the sampler to use for traces.
	// Env: OTEL_TRACES_SAMPLER (default: "parentbased_traceidratio")
	// Known values: "parentbased_traceidratio", "traceidratio", "always_on",
	// "always_off", "parentbased_always_on", "parentbased_always_off".
	TracesSampler string
	// TracesSamplerArg is the argument for the sampler (e.g. ratio for traceidratio).
	// Env: OTEL_TRACES_SAMPLER_ARG (default: 1.0 for ratio-based samplers)
	TracesSamplerArg float64
	// MetricsExporter specifies the metrics exporter: "otlp" or "none".
	// Env: OTEL_METRICS_EXPORTER (default: "none")
	MetricsExporter string
	// LogsExporter specifies the logs exporter: "otlp" or "none".
	// Env: OTEL_LOGS_EXPORTER (default: "none")
	LogsExporter string
	// Propagators specifies the propagators to use, comma-separated.
	// Supported values: "tracecontext", "baggage", "jaeger".
	// Env: OTEL_PROPAGATORS (default: "tracecontext,baggage")
	Propagators string
}

Config holds OpenTelemetry configuration options.

func ConfigFromEnv

func ConfigFromEnv(serviceVersion string) Config

ConfigFromEnv creates a Config from standard OTEL environment variables.

func SetupSDK

func SetupSDK(ctx context.Context, serviceVersion string) (cfg Config, shutdown func(context.Context) error, err error)

SetupSDK bootstraps the OpenTelemetry pipeline using environment variables. It returns the resolved Config (including the effective ServiceName) so that callers can use it for otelhttp instrumentation and similar. Call the returned shutdown function (e.g. via defer) for proper cleanup.

Jump to

Keyboard shortcuts

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