telemetry

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 52 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package telemetry provides OpenTelemetry tracing, metrics, logging and profiling helpers for keel services.

Wiring

The usual entry point is github.com/foomo/keel.WithTelemetry, which creates the trace, meter and logger providers from the environment through NewTraceProviderFromEnv, NewMeterProviderFromEnv and NewLoggerProviderFromEnv. Every provider constructor in this package also installs its provider as the OpenTelemetry global, which Tracer, Meter and LoggerProvider read.

Environment

The exporters follow the OpenTelemetry environment variable specification:

  • OTEL_TRACES_EXPORTER, OTEL_LOGS_EXPORTER: none (default), console or otlp.
  • OTEL_METRICS_EXPORTER: none (default), console, otlp or prometheus.
  • OTEL_EXPORTER_OTLP_PROTOCOL and OTEL_EXPORTER_OTLP_<SIGNAL>_PROTOCOL: http/protobuf (default) or grpc.
  • OTEL_EXPORTER_OTLP_* endpoint and header variables are read by the OTLP exporters themselves.
  • OTEL_SERVICE_NAME, OTEL_SERVICE_NAMESPACE and OTEL_RESOURCE_ATTRIBUTES populate the resource, see NewResource.

keel specific variables:

  • OTEL_TRACE_RATIO: parent based trace sampling ratio, defaults to 1.
  • OTEL_METRICS_HOST_ENABLED, OTEL_METRICS_RUNTIME_ENABLED: start host and Go runtime metric instrumentation.
  • OTEL_EXPORTER_STDOUT_PRETTY_PRINT, OTEL_EXPORTER_STDOUT_TIMESTAMPS: console exporter formatting, both default to true.
  • OTEL_PROFILE_*: optional profile types of NewProfiler.

Spans and logs

Ctx wraps a context.Context in a Context that bundles span, log and profile helpers. Spans are named after the calling package and annotated with the caller's function, file and line:

func (s *Service) Do(ctx context.Context) (err error) {
	tctx := telemetry.Ctx(ctx).StartSpan()
	defer tctx.DeferEndSpan(&err)

	tctx.LogInfo("doing work", attribute.String("id", s.id))

	if err := s.work(tctx.Context()); err != nil {
		tctx.RecordError(err)
		return err
	}

	return nil
}

Log messages are written through the global zap logger and carry the trace and span IDs of the context.

Metrics

NewIntCounter, NewFloatHistogram and their siblings create instruments from Meter. On error they report through otel.Handle and return a no-op instrument instead of nil.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Name               = "github.com/foomo/keel/telemetry"
	DefaultServiceName = "undefined"
)

Name is the instrumentation scope name used by Tracer and Meter. DefaultServiceName is the service name used by NewProfiler when OTEL_SERVICE_NAME is unset.

View Source
var (
	// DefaultHistogramBuckets are histogram bucket boundaries for metrics in
	// seconds.
	//
	// Deprecated: Configure buckets on the instrument instead.
	DefaultHistogramBuckets = []float64{.001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 60, 120, 300, 600}
)
View Source
var Version = sync.OnceValue(func() string {
	bi, ok := debug.ReadBuildInfo()
	if !ok {
		return ""
	}

	if bi.Main.Path == Name {
		return bi.Main.Version
	}

	for _, d := range bi.Deps {
		if d.Path == Name {
			return d.Version
		}
	}

	return ""
})

Version returns the keel module version for use as the OTel instrumentation scope version. It is resolved once from the build info and is empty if unavailable.

Functions

func AddSpanEvent added in v0.30.0

func AddSpanEvent(sp trace.Span, name string, opts ...trace.EventOption)

AddSpanEvent adds an event to sp.

func AddSpanLink(sp, parent trace.Span, attrs ...attribute.KeyValue)

AddSpanLink adds a link from sp to parent with attrs.

func CodeCaller added in v0.24.0

func CodeCaller(skip int) []attribute.KeyValue

CodeCaller returns the code.function.name, code.file.path and code.line.number attributes of the caller skip frames above the caller of CodeCaller, or nil if the frame cannot be resolved.

func CodeStacktrace added in v0.24.0

func CodeStacktrace(num, skip int) attribute.KeyValue

CodeStacktrace returns a code.stacktrace attribute with up to num frames, skipping skip frames above the caller of CodeStacktrace.

func DeferEndSpan added in v0.30.0

func DeferEndSpan(sp trace.Span, err *error, opts ...trace.SpanEndOption)

DeferEndSpan ends sp with the error err points to, so it can be used as defer DeferEndSpan(sp, &err). A nil err pointer ends the span without error.

func End deprecated

func End(sp trace.Span, err error)

End ends sp like EndSpan.

Deprecated: Use EndSpan instead.

func EndSpan added in v0.30.0

func EndSpan(sp trace.Span, err error, opts ...trace.SpanEndOption)

EndSpan ends sp. A non-nil err is recorded with a stack trace and sets the span status to error with the root cause message and error.type.

func EnvAttributes added in v0.22.0

func EnvAttributes() []attribute.KeyValue

EnvAttributes returns the service namespace and VCS attributes read from well known environment variables. For each attribute the first non-empty variable wins.

func IsSpanRecording added in v0.30.0

func IsSpanRecording(sp trace.Span) bool

IsSpanRecording reports whether sp is recording.

func Log added in v0.22.0

func Log(ctx context.Context, lvl zapcore.Level, msg string, skip int, kv ...attribute.KeyValue)

Log writes msg at level lvl to the global zap logger with kv as fields. It adds the trace and span IDs of a valid span in ctx and the code location of the caller skip frames above the caller of Log. Nothing is done if lvl is not enabled.

func LogDebug added in v0.26.0

func LogDebug(ctx context.Context, msg string, kv ...attribute.KeyValue)

LogDebug logs msg at debug level, see Log.

func LogError added in v0.26.0

func LogError(ctx context.Context, msg string, kv ...attribute.KeyValue)

LogError logs msg at error level, see Log.

func LogInfo added in v0.26.0

func LogInfo(ctx context.Context, msg string, kv ...attribute.KeyValue)

LogInfo logs msg at info level, see Log.

func LogWarn added in v0.26.0

func LogWarn(ctx context.Context, msg string, kv ...attribute.KeyValue)

LogWarn logs msg at warn level, see Log.

func LoggerProvider added in v0.22.0

func LoggerProvider() log.LoggerProvider

LoggerProvider returns the global logger provider instance used throughout the application.

func Meter added in v0.2.0

func Meter(opts ...metric.MeterOption) metric.Meter

Meter returns a metric.Meter named Name from the global MeterProvider. The instrumentation scope version defaults to Version; pass metric.WithInstrumentationVersion to override it. The schema URL defaults to the semconv version used by keel.

func MeterProvider added in v0.22.0

func MeterProvider() metric.MeterProvider

MeterProvider returns the global metric.MeterProvider.

func NewFloatCounter added in v0.22.1

func NewFloatCounter(name string, opts ...metric.Float64CounterOption) metric.Float64Counter

NewFloatCounter creates and returns a Float64Counter metric instrument with the specified name and options.

func NewFloatGauge added in v0.22.1

func NewFloatGauge(name string, opts ...metric.Float64GaugeOption) metric.Float64Gauge

NewFloatGauge creates and returns a Float64Gauge metric instrument with the specified name and options.

func NewFloatHistogram added in v0.22.1

func NewFloatHistogram(name string, opts ...metric.Float64HistogramOption) metric.Float64Histogram

NewFloatHistogram creates and returns a Float64Histogram metric instrument with the specified name and options.

func NewFloatUpDownCounter added in v0.22.1

func NewFloatUpDownCounter(name string, opts ...metric.Float64UpDownCounterOption) metric.Float64UpDownCounter

NewFloatUpDownCounter creates and returns a Float64UpDownCounter metric instrument with the specified name and options.

func NewIntCounter added in v0.22.1

func NewIntCounter(name string, opts ...metric.Int64CounterOption) metric.Int64Counter

NewIntCounter creates and returns a Int64Counter metric instrument with the specified name and options.

func NewIntGauge added in v0.22.1

func NewIntGauge(name string, opts ...metric.Int64GaugeOption) metric.Int64Gauge

NewIntGauge creates and returns a Int64Gauge metric instrument with the specified name and options.

func NewIntHistogram added in v0.22.1

func NewIntHistogram(name string, opts ...metric.Int64HistogramOption) metric.Int64Histogram

NewIntHistogram creates and returns a Int64Histogram metric instrument with the specified name and options.

func NewIntUpDownCounter added in v0.22.1

func NewIntUpDownCounter(name string, opts ...metric.Int64UpDownCounterOption) metric.Int64UpDownCounter

NewIntUpDownCounter creates and returns a Int64UpDownCounter metric instrument with the specified name and options.

func NewLoggerProviderFromEnv added in v0.28.0

func NewLoggerProviderFromEnv(ctx context.Context) (log.LoggerProvider, error)

NewLoggerProviderFromEnv selects a logger provider based on OTEL_LOGS_EXPORTER (none|console|otlp, default none) and OTEL_EXPORTER_OTLP_LOGS_PROTOCOL. It returns (nil, nil) when the exporter is none so the caller's noop fallback owns the default.

func NewMeterProviderFromEnv added in v0.28.0

func NewMeterProviderFromEnv(ctx context.Context) (metric.MeterProvider, error)

NewMeterProviderFromEnv selects a meter provider based on OTEL_METRICS_EXPORTER (none|console|otlp|prometheus, default none) and OTEL_EXPORTER_OTLP_METRICS_PROTOCOL. It returns (nil, nil) when the exporter is none so the caller's noop fallback owns the default.

func NewNoopLoggerProvider added in v0.28.0

func NewNoopLoggerProvider() log.LoggerProvider

NewNoopLoggerProvider returns a no-op log.LoggerProvider.

func NewNoopMeterProvider added in v0.8.0

func NewNoopMeterProvider() metric.MeterProvider

NewNoopMeterProvider returns a no-op metric.MeterProvider.

func NewNoopTraceProvider added in v0.8.0

func NewNoopTraceProvider() trace.TracerProvider

NewNoopTraceProvider creates and returns a no-op tracer provider.

func NewOTLPGRCPLoggerProvider deprecated added in v0.22.0

func NewOTLPGRCPLoggerProvider(ctx context.Context) (log.LoggerProvider, error)

NewOTLPGRCPLoggerProvider is a misspelled alias of NewOTLPGRPCLoggerProvider.

Deprecated: Use NewOTLPGRPCLoggerProvider instead.

func NewOTLPGRPCLoggerProvider added in v0.30.0

func NewOTLPGRPCLoggerProvider(ctx context.Context) (log.LoggerProvider, error)

NewOTLPGRPCLoggerProvider returns a logger provider that batches and exports logs over OTLP gRPC and installs it as the global logger provider. The exporter is configured from the OTEL_EXPORTER_OTLP_* environment.

func NewOTLPGRPCMeterProvider added in v0.28.0

func NewOTLPGRPCMeterProvider(ctx context.Context, opts ...otlpmetricgrpc.Option) (metric.MeterProvider, error)

NewOTLPGRPCMeterProvider creates a push-based metric.MeterProvider that exports metrics over OTLP gRPC via a periodic reader. It configures the exporter from environment variables (e.g. endpoint, insecure transport) unless overridden by the given options. Push-based export suits short-lived workloads (e.g. Jobs) that exit before a scrape. The provider is installed as the global meter provider.

func NewOTLPGRPCTraceProvider added in v0.8.0

func NewOTLPGRPCTraceProvider(ctx context.Context, opts ...otlptracegrpc.Option) (trace.TracerProvider, error)

NewOTLPGRPCTraceProvider creates a new trace provider configured for OTLP over gRPC with optional settings. It uses environment variables for settings like endpoint and insecure mode if not provided explicitly. The provider is installed as the global tracer provider.

func NewOTLPHTTPLoggerProvider added in v0.22.0

func NewOTLPHTTPLoggerProvider(ctx context.Context) (log.LoggerProvider, error)

NewOTLPHTTPLoggerProvider returns a logger provider that batches and exports logs over OTLP HTTP and installs it as the global logger provider. The exporter is configured from the OTEL_EXPORTER_OTLP_* environment.

func NewOTLPHTTPMeterProvider added in v0.28.0

func NewOTLPHTTPMeterProvider(ctx context.Context, opts ...otlpmetrichttp.Option) (metric.MeterProvider, error)

NewOTLPHTTPMeterProvider creates a push-based metric.MeterProvider that exports metrics over OTLP HTTP via a periodic reader. It configures the exporter from environment variables (e.g. endpoint, insecure transport) unless overridden by the given options. Push-based export suits short-lived workloads (e.g. Jobs) that exit before a scrape. The provider is installed as the global meter provider.

func NewOTLPHTTPTraceProvider added in v0.8.0

func NewOTLPHTTPTraceProvider(ctx context.Context, opts ...otlptracehttp.Option) (trace.TracerProvider, error)

NewOTLPHTTPTraceProvider creates an OTLP HTTP trace provider using the given context and options. It configures the provider based on environment variables, such as endpoint and insecure transport. The provider is installed as the global tracer provider.

func NewProfiler added in v0.22.0

func NewProfiler(ctx context.Context) (*pyroscope.Profiler, error)

NewProfiler starts a pyroscope profiler named after the service and tagged with the pod name, service namespace and resource attributes. CPU and memory profiles are always collected; block, mutex and goroutine profiles are enabled with OTEL_PROFILE_BLOCK_ENABLED, OTEL_PROFILE_MUTEX_ENABLED and OTEL_PROFILE_GOROUTINES_ENABLED, with rates from OTEL_PROFILE_BLOCK_RATE and OTEL_PROFILE_MUTEX_FRACTION (default 5). It also wraps the global tracer provider so spans are linked to profiles.

func NewPrometheusMeterProvider added in v0.8.0

func NewPrometheusMeterProvider(ctx context.Context) (metric.MeterProvider, error)

NewPrometheusMeterProvider returns a meter provider backed by the OTEL Prometheus exporter, which registers into prometheus.DefaultRegisterer, and installs it as the global meter provider.

func NewResource added in v0.22.0

func NewResource(ctx context.Context) (*resource.Resource, error)

NewResource returns the resource attached to all providers of this package. It combines OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES and EnvAttributes.

func NewStdOutLoggerProvider added in v0.22.0

func NewStdOutLoggerProvider(ctx context.Context) (log.LoggerProvider, error)

NewStdOutLoggerProvider returns a logger provider that exports logs to stdout and installs it as the global logger provider. Output formatting is controlled by OTEL_EXPORTER_STDOUT_PRETTY_PRINT and OTEL_EXPORTER_STDOUT_TIMESTAMPS, both defaulting to true.

func NewStdOutMeterProvider added in v0.8.0

func NewStdOutMeterProvider(ctx context.Context, opts ...stdoutmetric.Option) (metric.MeterProvider, error)

NewStdOutMeterProvider returns a meter provider that periodically exports metrics to stdout and installs it as the global meter provider. Output formatting is controlled by OTEL_EXPORTER_STDOUT_PRETTY_PRINT and OTEL_EXPORTER_STDOUT_TIMESTAMPS, both defaulting to true; opts are passed to the exporter.

func NewStdOutTraceProvider added in v0.8.0

func NewStdOutTraceProvider(ctx context.Context) (trace.TracerProvider, error)

NewStdOutTraceProvider creates a new stdout trace provider with optional configurations from the environment variables. It uses pretty print and timestamps by default unless overridden by the respective environment variables. The provider is installed as the global tracer provider.

func NewTraceProviderFromEnv added in v0.28.0

func NewTraceProviderFromEnv(ctx context.Context) (trace.TracerProvider, error)

NewTraceProviderFromEnv selects a trace provider based on OTEL_TRACES_EXPORTER (none|console|otlp, default none) and OTEL_EXPORTER_OTLP_TRACES_PROTOCOL. It returns (nil, nil) when the exporter is none so the caller's noop fallback owns the default.

func NewZapBridgeCore added in v0.28.0

func NewZapBridgeCore(lp log.LoggerProvider) zapcore.Core

NewZapBridgeCore returns a zapcore.Core that emits entries as OTEL log records through lp, for teeing into an existing logger.

func NewZapLoggerProvider added in v0.22.0

func NewZapLoggerProvider(ctx context.Context, logger *zap.Logger) (log.LoggerProvider, error)

NewZapLoggerProvider returns a logger provider that writes OTEL log records to logger and installs it as the global logger provider.

Example
package main

import (
	"context"

	"github.com/foomo/keel/telemetry"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/log"
	"go.uber.org/zap"
)

func main() {
	l := zap.NewExample()
	ctx := context.Background()

	_, _ = telemetry.NewZapLoggerProvider(ctx, l)

	// Raw log record
	record := log.Record{}
	record.SetSeverity(log.SeverityInfo)
	record.SetBody(attribute.StringValue("something really cool"))

	tl := telemetry.LoggerProvider().Logger(telemetry.Name)
	tl.Emit(ctx, record)

}
Output:
{"level":"info","msg":"something really cool"}

func PushToGateway added in v0.28.0

func PushToGateway(ctx context.Context, url, jobName string) error

PushToGateway pushes the metrics gathered by prometheus.DefaultGatherer to a Prometheus Pushgateway at the given URL, grouped under the given job name.

This is intended for short-lived workloads (e.g. Kubernetes Jobs) that exit before a scrape can occur. The OTEL Prometheus exporter registers into prometheus.DefaultRegisterer, so OTEL metrics are included in the push.

func PyroscopeLabels added in v0.22.0

func PyroscopeLabels(kv ...attribute.KeyValue) pyroscope.LabelSet

PyroscopeLabels converts the valid attributes in kv to pyroscope labels, replacing dots in keys with underscores.

func Readme deprecated added in v0.33.0

func Readme() string

Readme returns a markdown table of all metrics gathered from the default Prometheus gatherer, or an empty string if there are none.

Deprecated: Readme has no replacement.

func SetSpanAttributes added in v0.30.0

func SetSpanAttributes(sp trace.Span, attrs ...attribute.KeyValue)

SetSpanAttributes sets attrs on sp.

func SetSpanDebug added in v0.30.0

func SetSpanDebug(sp trace.Span)

SetSpanDebug marks sp as a debug span.

func SetSpanName added in v0.30.0

func SetSpanName(sp trace.Span, name string)

SetSpanName sets the name of sp.

func SetSpanSamplingPriority added in v0.33.0

func SetSpanSamplingPriority(sp trace.Span, v int)

SetSpanSamplingPriority sets the sampling priority of span.

func SetSpanStatusError added in v0.30.0

func SetSpanStatusError(sp trace.Span, description string)

SetSpanStatusError sets the status of sp to error with description.

func SetSpanStatusOK added in v0.30.0

func SetSpanStatusOK(sp trace.Span)

SetSpanStatusOK sets the status of sp to ok.

Leave the status unset on success; backends treat unset as ok. Statuses override in the order Ok > Error > Unset: once set to ok, later error statuses are ignored. Use it only to explicitly mark an operation as successful despite recorded errors, e.g. a retry that succeeded after failed attempts set the status to error.

func SpanFromContext added in v0.30.0

func SpanFromContext(ctx context.Context) trace.Span

SpanFromContext returns the current span of ctx, or a non-recording span if there is none.

func Start deprecated

func Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

Start starts a span like StartSpan; spanName is ignored.

Deprecated: Use StartSpan instead.

func StartDebugSpan added in v0.30.0

func StartDebugSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartDebugSpan is like StartSpan but marks the span as a debug span.

func StartSpan added in v0.30.0

func StartSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpan starts a span named <package>.<function> after the caller (e.g. "keelmongo.(*Collection).Find"), annotated with the caller's function, file and line, from the global Tracer.

func StartSpanWithSkip added in v0.30.2

func StartSpanWithSkip(ctx context.Context, skip int, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpanWithSkip is like StartSpan but uses the caller skip frames above the caller of StartSpanWithSkip for the span name and code attributes. It is intended for telemetry helper packages.

func Tracer

func Tracer(opts ...trace.TracerOption) trace.Tracer

Tracer returns a trace.Tracer named Name from the global TracerProvider. The instrumentation scope version defaults to Version; pass trace.WithInstrumentationVersion to override it. The schema URL defaults to the semconv version used by keel.

func TracerProvider added in v0.2.0

func TracerProvider() trace.TracerProvider

TracerProvider returns the global trace.TracerProvider.

Types

type Context added in v0.22.0

type Context struct {
	// contains filtered or unexported fields
}

Context wraps a context.Context and provides span, log and profile helpers bound to it. It implements context.Context. Create one with Ctx; the zero value is not usable.

func Ctx added in v0.22.0

func Ctx(ctx context.Context) Context

Ctx returns a Context wrapping ctx.

func (Context) AddSpanEvent added in v0.22.0

func (c Context) AddSpanEvent(name string, kv ...attribute.KeyValue)

AddSpanEvent adds an event with attributes kv to the current span.

func (c Context) AddSpanLink(parent trace.Span, attrs ...attribute.KeyValue)

AddSpanLink adds a link from the current span to parent.

func (Context) Context added in v0.30.0

func (c Context) Context() context.Context

Context returns the wrapped context.Context.

func (Context) Deadline added in v0.30.0

func (c Context) Deadline() (deadline time.Time, ok bool)

Deadline returns the time when work done on behalf of this context should be canceled. Deadline returns ok==false when no deadline is set.

func (Context) DeferEndSpan added in v0.22.1

func (c Context) DeferEndSpan(err *error, opts ...trace.SpanEndOption)

DeferEndSpan ends the current span with the error err points to, so it can be used as defer ctx.DeferEndSpan(&err). See DeferEndSpan.

func (Context) Done added in v0.30.0

func (c Context) Done() <-chan struct{}

Done returns a channel that's closed when work done on behalf of this context should be canceled. Done may return nil if this context can never be canceled.

func (Context) EndSpan added in v0.22.0

func (c Context) EndSpan(err error, opts ...trace.SpanEndOption)

EndSpan ends the current span, see EndSpan.

func (Context) Err added in v0.30.0

func (c Context) Err() error

Err returns a non-nil error value after Done is closed. Err returns Canceled if the context was canceled or DeadlineExceeded if the context's deadline passed.

func (Context) LogDebug added in v0.22.0

func (c Context) LogDebug(msg string, kv ...attribute.KeyValue)

LogDebug logs msg at debug level, see Log.

func (Context) LogError added in v0.22.0

func (c Context) LogError(msg string, kv ...attribute.KeyValue)

LogError logs msg at error level, see Log.

func (Context) LogInfo added in v0.22.0

func (c Context) LogInfo(msg string, kv ...attribute.KeyValue)

LogInfo logs msg at info level, see Log.

func (Context) LogWarn added in v0.22.0

func (c Context) LogWarn(msg string, kv ...attribute.KeyValue)

LogWarn logs msg at warn level, see Log.

func (Context) RecordError added in v0.22.0

func (c Context) RecordError(err error, kv ...attribute.KeyValue)

RecordError records a non-nil err with kv and a stack trace on the current span and sets the span status to error with the root cause message and error.type. It does not log the error.

func (Context) RecordSpanError added in v0.22.0

func (c Context) RecordSpanError(err error, kv ...attribute.KeyValue)

RecordSpanError records a non-nil err with kv and a stack trace on the current span without changing the span status.

func (Context) SetProfileAttributes added in v0.22.0

func (c Context) SetProfileAttributes(kv ...attribute.KeyValue) Context

SetProfileAttributes adds kv as pprof labels to the context and the current goroutine and returns the labeled Context.

func (Context) SetSpanAttributes added in v0.22.0

func (c Context) SetSpanAttributes(kv ...attribute.KeyValue)

SetSpanAttributes sets attributes on the current span.

func (Context) SetSpanDebug added in v0.22.1

func (c Context) SetSpanDebug()

SetSpanDebug marks the current span as a debug span.

func (Context) SetSpanName added in v0.22.0

func (c Context) SetSpanName(name string)

SetSpanName sets the name of the current span.

func (Context) SetSpanStatusError added in v0.22.0

func (c Context) SetSpanStatusError(description string)

SetSpanStatusError sets the status of the current span to error with the given description.

func (Context) SetSpanStatusOK added in v0.22.0

func (c Context) SetSpanStatusOK()

SetSpanStatusOK sets the status of the current span to ok, see SetSpanStatusOK for when to use it.

func (Context) Span added in v0.22.0

func (c Context) Span() trace.Span

Span returns the current span of the context.

func (Context) StartProfile added in v0.22.0

func (c Context) StartProfile(name string, handler func(ctx Context), kv ...attribute.KeyValue)

StartProfile runs handler with pyroscope labels for the profile name and kv applied and sets the profile name attribute on the current span.

func (Context) StartSpan added in v0.22.0

func (c Context) StartSpan(opts ...trace.SpanStartOption) Context

StartSpan starts a child span named after the calling package and returns a Context holding it, see StartSpan.

func (Context) StartSpanWithNewRoot added in v0.22.1

func (c Context) StartSpanWithNewRoot(opts ...trace.SpanStartOption) Context

StartSpanWithNewRoot starts a span in a new trace, linked to the span of the context, and returns a Context holding it.

func (Context) StartSpanWithProfile added in v0.22.0

func (c Context) StartSpanWithProfile(name string, handler func(ctx Context), kv ...attribute.KeyValue)

StartSpanWithProfile starts a span with attributes kv, runs handler within a profile named name (see Context.StartProfile) and ends the span.

func (Context) Value added in v0.30.0

func (c Context) Value(key any) any

Value returns the value associated with this context for key, or nil if no value is associated with key.

func (Context) WithCancel added in v0.30.0

func (c Context) WithCancel() (Context, context.CancelFunc)

WithCancel returns a copy of the context with a new Done channel. The returned context's Done channel is closed when the returned cancel function is called or when the parent context's Done channel is closed, whichever happens first.

func (Context) WithCancelCause added in v0.30.0

func (c Context) WithCancelCause() (Context, context.CancelCauseFunc)

WithCancelCause returns a copy of the context with a new Done channel and a CancelCauseFunc instead of a CancelFunc. Calling cancel with a non-nil error (the "cause") records that error in the context; it can then be retrieved using Cause(ctx).

func (Context) WithDeadline added in v0.30.0

func (c Context) WithDeadline(deadline time.Time) (Context, context.CancelFunc)

WithDeadline returns a copy of the context with a deadline. The returned context's Done channel is closed when the deadline expires, when the returned cancel function is called, or when the parent context's Done channel is closed, whichever happens first.

func (Context) WithTimeout added in v0.30.0

func (c Context) WithTimeout(timeout time.Duration) (Context, context.CancelFunc)

WithTimeout returns a copy of the context with a timeout. It is equivalent to WithDeadline(time.Now().Add(timeout)).

func (Context) WithValue added in v0.30.0

func (c Context) WithValue(key, val any) Context

WithValue returns a copy of the context with the key-value pair associated.

func (Context) WithoutCancel added in v0.30.0

func (c Context) WithoutCancel() Context

WithoutCancel returns a copy of the context that is not canceled when parent is canceled. The returned context returns no Deadline or Err, and its Done channel is nil.

Directories

Path Synopsis
Package telemetrytest provides helpers for testing code instrumented with github.com/foomo/keel/telemetry.
Package telemetrytest provides helpers for testing code instrumented with github.com/foomo/keel/telemetry.

Jump to

Keyboard shortcuts

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