telemetry

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPHeadersKey contextKey = "http_headers"
	TraceIDKey     contextKey = "trace_id"
	SpanIDKey      contextKey = "span_id"
)
View Source
const (
	// Service identification
	OtelServiceName    = "OTEL_SERVICE_NAME"
	OtelServiceVersion = "OTEL_SERVICE_VERSION"
	OtelEnvironment    = "OTEL_ENVIRONMENT" // Custom extension, not in official spec

	// OTLP Exporter configuration
	OtelExporterOtlpEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
	OtelExporterOtlpProtocol = "OTEL_EXPORTER_OTLP_PROTOCOL"
	OtelExporterOtlpHeaders  = "OTEL_EXPORTER_OTLP_HEADERS"

	// Trace-specific OTLP configuration
	OtelExporterOtlpTracesInsecure = "OTEL_EXPORTER_OTLP_TRACES_INSECURE"

	// Sampling configuration
	OtelTracesSamplerArg = "OTEL_TRACES_SAMPLER_ARG"

	// SDK control
	OtelSdkDisabled = "OTEL_SDK_DISABLED"
)

Standard OpenTelemetry environment variable names These follow the official OTLP specification

View Source
const (
	ProtocolGRPC = "grpc"
	ProtocolHTTP = "http/protobuf"
	ProtocolAuto = "auto" // Custom extension for automatic protocol detection
)

OTLP Protocol constants

View Source
const (
	DefaultOtlpGrpcPort = "4317" // Standard OTLP/gRPC port
	DefaultOtlpHttpPort = "4318" // Standard OTLP/HTTP port
)

Standard OTLP port numbers These are the official OTLP default ports as per OpenTelemetry specification

View Source
const (
	DefaultHttpTracesPath = "/v1/traces"
)

Default endpoint paths

Variables

This section is empty.

Functions

func AdaptToolHandler

func AdaptToolHandler(th ToolHandler) server.ToolHandlerFunc

AdaptToolHandler adapts a telemetry.ToolHandler to a server.ToolHandlerFunc.

func AddEvent

func AddEvent(span trace.Span, name string, attrs ...attribute.KeyValue)

func ExtractHTTPHeaders

func ExtractHTTPHeaders(ctx context.Context) map[string]string

ExtractHTTPHeaders retrieves HTTP headers from context

func ExtractTraceInfo

func ExtractTraceInfo(ctx context.Context) (traceID, spanID string)

ExtractTraceInfo retrieves trace information from context

func HTTPMiddleware

func HTTPMiddleware(next http.Handler) http.Handler

HTTPMiddleware wraps an HTTP handler to extract headers and propagate context

func RecordError

func RecordError(span trace.Span, err error, message string)

func RecordSuccess

func RecordSuccess(span trace.Span, message string)

func SetupOTelSDK

func SetupOTelSDK(ctx context.Context) error

SetupOTelSDK initializes the OpenTelemetry SDK

func StartSpan

func StartSpan(ctx context.Context, operationName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

Types

type Config

type Config struct {
	Telemetry Telemetry
}

Config holds all application configuration.

func LoadOtelCfg

func LoadOtelCfg() *Config

LoadOtelCfg initializes and returns the application configuration.

type Telemetry

type Telemetry struct {
	ServiceName    string
	ServiceVersion string
	Environment    string
	Endpoint       string
	Protocol       string
	SamplingRatio  float64
	Insecure       bool
	Disabled       bool
}

Telemetry holds all telemetry-related configuration.

type ToolHandler

type ToolHandler func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

func WithTracing

func WithTracing(toolName string, handler ToolHandler) ToolHandler

Jump to

Keyboard shortcuts

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