Documentation
¶
Overview ¶
Package otel provides OpenTelemetry initialisation helpers for the LFX MCP server.
Package otel provides OpenTelemetry initialisation helpers for the LFX MCP server.
Index ¶
Constants ¶
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.
func Traceparent ¶ added in v0.22.0
Traceparent returns the W3C traceparent header value for a request made under ctx: the trace context of the span in ctx, or, when ctx carries none (tracing is off), that of a new trace that is not sampled, so that a downstream request always carries one. It writes the header itself rather than through the configured propagators: a caller of an upstream that takes no caller data forwards the trace context and nothing else, such as baggage.
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 ¶
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.