Documentation ¶
Overview ¶
Package telemetry provides functions for managing instrumented code and measure data about that code's performance and operation.
You can setup instrumentation by creating providers
// Create Tracer. tracer, _ := telemetry.NewTracer("myservicename") // Create a Meter. meter, _ := telemetry.NewMeter("myservicename")
Index ¶
- func Middleware(m middleware.Middleware) func(http.Handler) http.Handler
- func NewMeter(name string, opts ...func(option *MeterOption)) (*metric.MeterProvider, error)
- func NewTracer(serviceName string, opts ...func(*TracerOption)) (*sdktrace.TracerProvider, error)
- func WithOtelEndpoint(endpoint string) func(option *TracerOption)
- func WithSampleRate(rate float64) func(*TracerOption)
- type MeterOption
- type TracerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(m middleware.Middleware) func(http.Handler) http.Handler
Middleware sets up a handler to record metric of the incoming requests. This middleware will register the route template and not the url path. in case of high cardinality path
Eg: mux register /users/{id}/devices/{device_id} ulr will be /users/12345467/devices/omni_123232 the metric record will be under /users/{id}/devices/{device_id}
func NewMeter ¶
func NewMeter(name string, opts ...func(option *MeterOption)) (*metric.MeterProvider, error)
NewMeter configures the OpenTelemetry Resource and metrics exporter.
A list of attributes can be passed via env variable OTEL_RESOURCE_ATTRIBUTES;
eg:
OTEL_RESOURCE_ATTRIBUTES=service.version=0.0.1,service.namespace=default
see: https://pkg.go.dev/go.opentelemetry.io/otel/semconv/v1.7.0#pkg-constants
func NewTracer ¶
func NewTracer(serviceName string, opts ...func(*TracerOption)) (*sdktrace.TracerProvider, error)
NewTracer returns a new and configured TracerProvider.
You can define the Trace sample rate by env var via OTL_TRACE_SAMPLE_RATE You can define the OTL endpoint by env var via OTL_ENDPOINT A list of attributes can be passed via env variable OTEL_RESOURCE_ATTRIBUTES;
eg:
OTEL_RESOURCE_ATTRIBUTES=service.version=0.0.1,service.namespace=default
see: https://pkg.go.dev/go.opentelemetry.io/otel/semconv/v1.7.0#pkg-constants
func WithOtelEndpoint ¶
func WithOtelEndpoint(endpoint string) func(option *TracerOption)
func WithSampleRate ¶
func WithSampleRate(rate float64) func(*TracerOption)
WithSampleRate set the sample rate of tracing. For example, set sample_rate to 1 if you wanna sampling 100% of trace data. Set 0.5 if you wanna sampling 50% of trace data, and so forth.
Types ¶
type TracerOption ¶
TracerOption for the Tracer.