Documentation
¶
Overview ¶
Package tracing carries OpenTelemetry trace context and baggage through the engine, as the other platform services do with gin-middleware/otelx: incoming requests, outgoing requests to platform services, log records and the background execution of instances.
Index ¶
- Constants
- func End(span trace.Span, err error)
- func Handler(endpoint string, handler http.Handler) http.Handler
- func Init(ctx context.Context, endpoint string) error
- func Inject(ctx context.Context, req *http.Request) error
- func Start(ctx context.Context, name string, instance Instance, ...) (context.Context, trace.Span)
- func WithBaggage(ctx context.Context, key string, value string) context.Context
- type Instance
Constants ¶
const ( KeyInstanceId = "automation_instance_id" KeyDeploymentId = "automation_deployment_id" KeyNamespace = "automation_namespace" KeyUserId = "user_id" )
Baggage keys of the engine; the prefix keeps them apart from ids of other services, e.g. the smart_service_instance_id of smart-service-repository. user_id and username come from otelx.
const Off = "off"
Off disables tracing as value of the otel endpoint.
const ServiceName = "automation-engine"
ServiceName is the OpenTelemetry service name of the engine.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler traces incoming requests and takes over trace context and baggage of the caller; otelx adds user_id and username of the token to the baggage. With Off, handler is returned unchanged: otelx would set up its exporter on the first call.
func Init ¶
Init sets up the OpenTelemetry exporter once per process. An empty endpoint selects the platform default of otelx; Off leaves tracing disabled, spans are then dropped.
func Inject ¶
Inject writes trace context and baggage of ctx into a request to another platform service. Requests to targets outside the platform must not carry them, the baggage holds user ids.
func Start ¶
func Start(ctx context.Context, name string, instance Instance, attributes ...attribute.KeyValue) (context.Context, trace.Span)
Start begins a span of background work for an instance, e.g. a task execution, and puts the instance into the baggage. Background work has no caller, so the span starts a trace of its own unless ctx carries one.
func WithBaggage ¶
WithBaggage returns ctx with key=value in its baggage and adds it to the active span. Values with spaces or invalid characters are left out, the baggage is a diagnostic aid and must not fail the work it describes.