Documentation
¶
Index ¶
- Variables
- func BytesMeasure(pkg string, meterName string, description string) metric.Int64Counter
- func CounterView(pkg string, meterName string, description string) []sdkmetric.View
- func DimensionlessMeasure(pkg string, meterName string, description string) metric.Int64Counter
- func ErrorCode(err error) string
- func LatencyMeasure(pkg string) metric.Float64Histogram
- func NewTraceContextHandler(inner slog.Handler) slog.Handler
- func TenantAttributes(ctx context.Context) []attribute.KeyValue
- func TraceContextHandlerWrapper() func(slog.Handler) slog.Handler
- func Views(pkg string) []sdkmetric.View
- func WithTenantAttributes(ctx context.Context) metric.MeasurementOption
- type BusinessMetrics
- func (b *BusinessMetrics) Counter(name, description string, opts ...metric.Int64CounterOption) Counter
- func (b *BusinessMetrics) FloatCounter(name, description string, opts ...metric.Float64CounterOption) FloatCounter
- func (b *BusinessMetrics) FloatGauge(name, description string, opts ...metric.Float64GaugeOption) FloatGauge
- func (b *BusinessMetrics) Gauge(name, description string, opts ...metric.Int64GaugeOption) Gauge
- func (b *BusinessMetrics) Histogram(name, description string, opts ...metric.Float64HistogramOption) Histogram
- type Counter
- type FloatCounter
- type FloatGauge
- type Gauge
- type Histogram
- type Manager
- type Option
- func WithDisableTracing() Option
- func WithMetricsReader(reader sdkmetrics.Reader) Option
- func WithPropagationTextMap(carrier propagation.TextMapPropagator) Option
- func WithServiceEnvironment(env string) Option
- func WithServiceName(name string) Option
- func WithServiceVersion(version string) Option
- func WithTraceExporter(exporter sdktrace.SpanExporter) Option
- func WithTraceLogsExporter(exporter sdklogs.Exporter) Option
- func WithTraceSampler(sampler sdktrace.Sampler) Option
- type TraceContextHandler
- type Tracer
Constants ¶
This section is empty.
Variables ¶
var ( AttrTenantKey = attribute.Key("tenant_id") AttrPartitionKey = attribute.Key("partition_id") )
Attribute keys for multi-tenant context.
var ( AttrMethodKey = attribute.Key("frame_method") AttrPackageKey = attribute.Key("frame_package") AttrStatusKey = attribute.Key("frame_status") AttrErrorKey = attribute.Key("frame_error") )
Common attribute keys used across the frame.
Functions ¶
func BytesMeasure ¶
func BytesMeasure(pkg string, meterName string, description string) metric.Int64Counter
BytesMeasure creates a counter for bytes measurements.
func CounterView ¶
CounterView returns summation views that add up individual measurements the counter takes.
func DimensionlessMeasure ¶
func DimensionlessMeasure(pkg string, meterName string, description string) metric.Int64Counter
DimensionlessMeasure creates a simple counter specifically for dimensionless measurements.
func LatencyMeasure ¶
func LatencyMeasure(pkg string) metric.Float64Histogram
LatencyMeasure returns the measure for method call latency used by Go CDK APIs.
func NewTraceContextHandler ¶ added in v1.90.2
NewTraceContextHandler wraps an existing slog.Handler to inject trace context.
func TenantAttributes ¶ added in v1.94.0
TenantAttributes extracts tenant_id and partition_id from the context's security claims and returns them as OpenTelemetry attributes. When claims are absent or fields are empty, those attributes are omitted rather than recorded as blank strings. This makes the function safe to call unconditionally — unauthenticated or pre-auth code paths simply get an empty slice.
func TraceContextHandlerWrapper ¶ added in v1.90.2
TraceContextHandlerWrapper returns a function suitable for util.WithLogHandlerWrapper that wraps any slog.Handler with trace context injection.
func WithTenantAttributes ¶ added in v1.94.0
func WithTenantAttributes(ctx context.Context) metric.MeasurementOption
WithTenantAttributes returns a metric.MeasurementOption that attaches tenant_id and partition_id from the context. Services use this when recording custom product metrics so every data point is automatically attributed to the correct tenant and partition.
Usage:
counter.Add(ctx, 1,
telemetry.WithTenantAttributes(ctx),
metric.WithAttributes(attribute.String("login_method", "email")),
)
Types ¶
type BusinessMetrics ¶ added in v1.98.4
type BusinessMetrics struct {
// contains filtered or unexported fields
}
BusinessMetrics is the standard factory for product/business metrics. Every instrument it creates is tenant-scoped TRANSPARENTLY: each measurement automatically carries tenant_id and partition_id derived from the context's security claims (see TenantAttributes), so call sites cannot forget tenant attribution. Unauthenticated/system paths simply record without tenant attributes.
Usage:
var bm = telemetry.NewBusinessMetrics("service-loans")
var loansCreated = bm.Counter("loans_created_total", "New loan accounts created")
...
loansCreated.Add(ctx, 1) // tenant_id/partition_id attached from ctx
func NewBusinessMetrics ¶ added in v1.98.4
func NewBusinessMetrics(meterName string) *BusinessMetrics
NewBusinessMetrics returns a factory bound to the named meter on the global OTel meter provider (frame's telemetry manager sets it up).
func (*BusinessMetrics) Counter ¶ added in v1.98.4
func (b *BusinessMetrics) Counter(name, description string, opts ...metric.Int64CounterOption) Counter
Counter creates a tenant-scoped counter. On instrument-creation error it returns a no-op-backed instrument (matching LatencyMeasure's fallback behaviour) — metrics must never break the service.
func (*BusinessMetrics) FloatCounter ¶ added in v1.98.4
func (b *BusinessMetrics) FloatCounter(name, description string, opts ...metric.Float64CounterOption) FloatCounter
FloatCounter creates a tenant-scoped float64 counter, suited to monetary amounts in major units.
func (*BusinessMetrics) FloatGauge ¶ added in v1.98.4
func (b *BusinessMetrics) FloatGauge(name, description string, opts ...metric.Float64GaugeOption) FloatGauge
FloatGauge creates a tenant-scoped float64 gauge.
func (*BusinessMetrics) Gauge ¶ added in v1.98.4
func (b *BusinessMetrics) Gauge(name, description string, opts ...metric.Int64GaugeOption) Gauge
Gauge creates a tenant-scoped int64 gauge.
func (*BusinessMetrics) Histogram ¶ added in v1.98.4
func (b *BusinessMetrics) Histogram(name, description string, opts ...metric.Float64HistogramOption) Histogram
Histogram creates a tenant-scoped histogram in milliseconds by default; pass metric.WithUnit to override.
type Counter ¶ added in v1.98.4
type Counter struct {
// contains filtered or unexported fields
}
Counter is a tenant-scoped monotonic int64 counter.
type FloatCounter ¶ added in v1.98.4
type FloatCounter struct {
// contains filtered or unexported fields
}
FloatCounter is a tenant-scoped monotonic float64 counter (amounts).
type FloatGauge ¶ added in v1.98.4
type FloatGauge struct {
// contains filtered or unexported fields
}
FloatGauge is a tenant-scoped float64 gauge (last-value).
type Gauge ¶ added in v1.98.4
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a tenant-scoped int64 gauge (last-value).
type Histogram ¶ added in v1.98.4
type Histogram struct {
// contains filtered or unexported fields
}
Histogram is a tenant-scoped float64 histogram.
type Manager ¶ added in v1.63.0
type Manager interface {
Init(ctx context.Context) error
Disabled() bool
LogHandler() slog.Handler
}
func NewManager ¶ added in v1.63.0
NewManager creates a new telemetry setup manager.
type Option ¶ added in v1.63.0
func WithDisableTracing ¶ added in v1.63.0
func WithDisableTracing() Option
WithDisableTracing disable tracing for the service.
func WithMetricsReader ¶ added in v1.63.0
func WithMetricsReader(reader sdkmetrics.Reader) Option
WithMetricsReader specifies the metrics reader for the service.
func WithPropagationTextMap ¶ added in v1.63.0
func WithPropagationTextMap(carrier propagation.TextMapPropagator) Option
WithPropagationTextMap specifies the trace baggage carrier exporter to use.
func WithServiceEnvironment ¶ added in v1.63.0
WithServiceEnvironment sets the service environment for resource tagging.
func WithServiceName ¶ added in v1.63.0
WithServiceName sets the service name for resource tagging.
func WithServiceVersion ¶ added in v1.63.0
WithServiceVersion sets the service version for resource tagging.
func WithTraceExporter ¶ added in v1.63.0
func WithTraceExporter(exporter sdktrace.SpanExporter) Option
WithTraceExporter specifies the trace exporter to use.
func WithTraceLogsExporter ¶ added in v1.63.0
WithTraceLogsExporter specifies the trace logs exporter for the service.
func WithTraceSampler ¶ added in v1.63.0
WithTraceSampler specifies the trace sampler to use.
type TraceContextHandler ¶ added in v1.90.2
type TraceContextHandler struct {
// contains filtered or unexported fields
}
TraceContextHandler is an slog.Handler that injects trace_id and span_id from the OTel span context into every log record. This enables correlation between stdout/stderr logs and distributed traces in production.