otel

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package otel provides an OpenTelemetry adapter for the LoopKit Telemetry port.

It emits:

  • Spans: one root span per loop run ("loopkit.run"), one child span per iteration ("loopkit.iteration"), one child span per action ("loopkit.action").
  • Counters: loopkit.tokens (gen_ai.usage.input_tokens / output_tokens), loopkit.cost_usd (total USD spend).
  • Histograms: loopkit.iteration_duration_ms, loopkit.action_duration_ms.

GenAI semantic conventions (gen_ai.*) are applied where applicable.

Span attributes use snake_case keys following OTel conventions. No OTel imports exist outside this package (enforced by arch_test.go).

Usage:

tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader))
tel := otel.New(otel.Config{TracerProvider: tp, MeterProvider: mp})
runner := loopkit.New(def, loopkit.WithTelemetry(tel))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter implements runtime.Telemetry using OpenTelemetry.

func New

func New(cfg Config) (*Adapter, error)

New creates a new OTel Adapter.

func (*Adapter) OnEvent

func (a *Adapter) OnEvent(ev event.Envelope)

OnEvent implements runtime.Telemetry. Adds the event as a span event on the current (innermost active) span for the loop.

func (*Adapter) RecordSpend

func (a *Adapter) RecordSpend(loopID event.LoopID, spend budget.Spend, actionType string)

RecordSpend implements runtime.Telemetry.

func (*Adapter) SpanEnd

func (a *Adapter) SpanEnd(id runtime.SpanID, attrs runtime.SpanAttrs, elapsed time.Duration, err error)

SpanEnd implements runtime.Telemetry.

func (*Adapter) SpanStart

func (a *Adapter) SpanStart(kind runtime.SpanKind, loopID event.LoopID, attrs runtime.SpanAttrs) runtime.SpanID

SpanStart implements runtime.Telemetry.

type Config

type Config struct {
	// TracerProvider to use. If nil, the global tracer provider is used.
	TracerProvider trace.TracerProvider
	// MeterProvider to use. If nil, the global meter provider is used.
	MeterProvider metric.MeterProvider
}

Config configures the OTel adapter.

Jump to

Keyboard shortcuts

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