Documentation
¶
Overview ¶
Package metry provides a zero-boilerplate OpenTelemetry and LLMOps hub for Go AI applications.
Index ¶
- Variables
- func BaggageValue(ctx context.Context, key string) string
- func Console() (*TraceExporter, *MetricExporter)
- func ContextWithBaggage(ctx context.Context, key, value string) (context.Context, error)
- func Float64(v float64) *float64
- func GlobalMeter() metric.Meter
- func GlobalTracer() trace.Tracer
- func Init(ctx context.Context, opts Options) (shutdown func(context.Context) error, err error)
- func Noop() (*TraceExporter, *MetricExporter)
- func OTLPGRPC(endpoint string, insecure bool) (*TraceExporter, *MetricExporter)
- func OTLPHTTP(endpoint string, headers map[string]string) (*TraceExporter, *MetricExporter)
- type MetricExporter
- type Options
- type TraceExporter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrServiceNameRequired is returned when Init is called with an empty ServiceName. ErrServiceNameRequired = errors.New("metry: ServiceName is required") )
Functions ¶
func BaggageValue ¶
BaggageValue retrieves a value for the given key from the context's baggage. Returns an empty string if the key does not exist.
func Console ¶
func Console() (*TraceExporter, *MetricExporter)
Console returns trace and metric exporters that write to stdout (for local development).
func ContextWithBaggage ¶
ContextWithBaggage injects a key-value pair into the context's baggage. This data will automatically propagate across HTTP and gRPC boundaries.
func Float64 ¶
Float64 returns a pointer to v. Use for Options.TraceRatio to distinguish nil (default 1.0) from explicit 0.0 (disable sampling).
func GlobalMeter ¶
GlobalMeter returns the global Meter for the library (name "metry"). Call after Init.
func GlobalTracer ¶
GlobalTracer returns the global Tracer for the library (name "metry"). Call after Init.
func Init ¶
Init configures global OTel providers and returns a shutdown function. Resource includes service.name, service.version, deployment.environment and telemetry.sdk.* attributes (e.g. telemetry.sdk.language=go) for backend dashboards.
func Noop ¶
func Noop() (*TraceExporter, *MetricExporter)
Noop returns trace and metric exporters that drop all data (for disabling telemetry or tests).
func OTLPGRPC ¶
func OTLPGRPC(endpoint string, insecure bool) (*TraceExporter, *MetricExporter)
OTLPGRPC returns trace and metric exporters that send data via OTLP over gRPC. endpoint is the target host:port (e.g. "localhost:4317"). If insecure is true, TLS is disabled.
func OTLPHTTP ¶
func OTLPHTTP(endpoint string, headers map[string]string) (*TraceExporter, *MetricExporter)
OTLPHTTP returns trace and metric exporters that send data via OTLP over HTTP. endpoint is the target host:port (e.g. "localhost:4318"). headers are optional HTTP headers.
Types ¶
type MetricExporter ¶
type MetricExporter struct {
// contains filtered or unexported fields
}
MetricExporter is an opaque type that produces an OTel metric exporter. Create it via OTLPGRPC, OTLPHTTP, Console, Noop, or testutil.
func NewMetricExporterFromExporter ¶
func NewMetricExporterFromExporter(exp metric.Exporter) *MetricExporter
NewMetricExporterFromExporter wraps an existing metric.Exporter as a MetricExporter. Used by testutil and other packages that need to plug in a custom exporter instance.
type Options ¶
type Options struct {
// ServiceName is the name of the service (required).
ServiceName string
// ServiceVersion is the release version (optional).
ServiceVersion string
// Environment is the deployment environment, e.g. "production", "staging", "local".
Environment string
// TraceExporter exports trace spans. If nil, a no-op exporter is used.
TraceExporter *TraceExporter
// MetricExporter exports metrics. If nil, a no-op exporter is used.
MetricExporter *MetricExporter
// TraceRatio is the fraction of traces to sample (1.0 = 100%, 0.1 = 10%).
// If nil, 1.0 is used. Use Float64(0) to disable tracing (0% sampling).
TraceRatio *float64
}
Options configures the full OTel stack for a service.
type TraceExporter ¶
type TraceExporter struct {
// contains filtered or unexported fields
}
TraceExporter is an opaque type that produces an OTel trace exporter. Create it via OTLPGRPC, OTLPHTTP, Console, Noop, or testutil.
func NewTraceExporterFromSpanExporter ¶
func NewTraceExporterFromSpanExporter(exp sdktrace.SpanExporter) *TraceExporter
NewTraceExporterFromSpanExporter wraps an existing sdktrace.SpanExporter as a TraceExporter. Used by testutil and other packages that need to plug in a custom exporter instance.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package genai provides OpenLLMetry semantic convention constants and helpers for recording GenAI usage (tokens, cost, prompts) on OTel spans.
|
Package genai provides OpenLLMetry semantic convention constants and helpers for recording GenAI usage (tokens, cost, prompts) on OTel spans. |
|
middleware
|
|
|
grpc
Package grpc provides gRPC instrumentation for metry: server and client stats handlers that create spans and propagate trace context.
|
Package grpc provides gRPC instrumentation for metry: server and client stats handlers that create spans and propagate trace context. |
|
http
Package http provides HTTP middleware for metry that creates root spans and propagates trace context.
|
Package http provides HTTP middleware for metry that creates root spans and propagates trace context. |
|
Package security provides semantic convention constants and helpers for AI security observability (tiers, validators, actions, shadow mode).
|
Package security provides semantic convention constants and helpers for AI security observability (tiers, validators, actions, shadow mode). |
|
Package testutil provides in-memory exporters and helpers for testing code that uses metry.
|
Package testutil provides in-memory exporters and helpers for testing code that uses metry. |