tracing

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package tracing provides OpenTelemetry distributed tracing for cloop.

When tracing is enabled (config.Tracing.Enabled = true and Endpoint is set), the package initialises a global OTel TracerProvider that exports spans via OTLP over HTTP to the configured endpoint (e.g. a local Jaeger or OTEL Collector). When disabled, a no-op tracer is used so callers never need to guard on nil spans.

Span hierarchy produced during a PM run:

plan_run                    (one per cloop run)
  └─ task_execute           (one per task)
       └─ provider_call     (one per Complete() invocation)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SpanIDFromContext

func SpanIDFromContext(ctx context.Context) string

SpanIDFromContext returns the hex-encoded span ID of the current span in ctx, or empty when no valid span is active.

func StartSpan

func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan starts a new span named name as a child of the span already in ctx (if any). Extra span attributes can be provided via attrs. The returned context carries the new span; callers must call span.End().

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context) string

TraceIDFromContext returns the hex-encoded trace ID of the current span in ctx, or an empty string when no active span is present (tracing disabled or no span started).

func WrapProvider

func WrapProvider(inner provider.Provider) provider.Provider

WrapProvider returns a provider.Provider that wraps inner and records one "provider_call" OTel span per Complete() invocation. The span captures:

  • provider name and model as attributes
  • input/output token counts after completion
  • wall-clock duration (via span start/end)
  • error status if the call fails

When tracing is disabled (no-op tracer), the wrapper is zero-overhead.

Types

type Config

type Config struct {
	// Enabled activates OTLP trace export. Default: false.
	Enabled bool `yaml:"enabled,omitempty"`
	// Endpoint is the OTLP HTTP receiver URL, e.g. "http://localhost:4318".
	// The exporter uses the /v1/traces path automatically.
	// Required when Enabled is true; ignored otherwise.
	Endpoint string `yaml:"endpoint,omitempty"`
	// ServiceName is reported as the OTel service.name resource attribute.
	// Defaults to "cloop".
	ServiceName string `yaml:"service_name,omitempty"`
}

Config holds tracing settings loaded from .cloop/config.yaml under the "tracing" key. All fields are optional; when Enabled is false (default) the no-op tracer is used and no network connections are made.

type ShutdownFunc

type ShutdownFunc func(context.Context) error

ShutdownFunc flushes and closes the TracerProvider. Always safe to call, even when tracing is disabled (it becomes a no-op).

func Init

func Init(cfg Config) (ShutdownFunc, error)

Init configures the global OTel TracerProvider using the given Config. When cfg.Enabled is false or cfg.Endpoint is empty, a no-op tracer is installed and shutdown is a harmless no-op. The caller must invoke the returned ShutdownFunc (e.g. via defer) to flush pending spans before exit.

Jump to

Keyboard shortcuts

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