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 GlobalMeter() metric.Meter
- func GlobalTracer() trace.Tracer
- func Init(ctx context.Context, opts ...Option) (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 Option
- func WithConsole() Option
- func WithEnvironment(env string) Option
- func WithMetricExporter(me *MetricExporter) Option
- func WithNoop() Option
- func WithOTLPGRPC(endpoint string, insecure bool) Option
- func WithOTLPHTTP(endpoint string, headers map[string]string) Option
- func WithServiceName(name string) Option
- func WithServiceVersion(version string) Option
- func WithTraceExporter(te *TraceExporter) Option
- func WithTraceRatio(ratio float64) Option
- 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 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. Uses resource.Default() merged with service attributes for host/PID/OS and service identity. On partial failure, already-created providers are shut down and global otel state is restored to the previous tracer/meter (atomic "all or nothing" for global provider state).
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 Option ¶ added in v0.1.2
type Option func(*config)
Option configures Init. Use WithServiceName, WithTraceRatio, etc.
func WithConsole ¶ added in v0.1.2
func WithConsole() Option
WithConsole sets trace and metric exporters that write to stdout (for local dev).
func WithEnvironment ¶ added in v0.1.2
WithEnvironment sets the deployment environment (e.g. "production", "staging").
func WithMetricExporter ¶ added in v0.1.2
func WithMetricExporter(me *MetricExporter) Option
WithMetricExporter sets the metric exporter. If not set, metrics are not exported.
func WithNoop ¶ added in v0.1.2
func WithNoop() Option
WithNoop sets no-op trace and metric exporters (disable telemetry or tests).
func WithOTLPGRPC ¶ added in v0.1.2
WithOTLPGRPC sets trace and metric exporters for OTLP over gRPC (e.g. "localhost:4317").
func WithOTLPHTTP ¶ added in v0.1.2
WithOTLPHTTP sets trace and metric exporters for OTLP over HTTP (e.g. "localhost:4318").
func WithServiceName ¶ added in v0.1.2
WithServiceName sets the service name (required).
func WithServiceVersion ¶ added in v0.1.2
WithServiceVersion sets the service version (optional).
func WithTraceExporter ¶ added in v0.1.2
func WithTraceExporter(te *TraceExporter) Option
WithTraceExporter sets the trace exporter. If not set, a no-op exporter is used.
func WithTraceRatio ¶ added in v0.1.2
WithTraceRatio sets the fraction of traces to sample (1.0 = 100%, 0.0 = disable).
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. |