telemetry

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Overview

Package telemetry provides OpenTelemetry integration for PromptKit, including TracerProvider management and an event-to-span listener.

Index

Constants

View Source
const (
	// InstrumentationName is the OTel instrumentation scope name.
	InstrumentationName = "github.com/AltairaLabs/PromptKit"

	// InstrumentationVersion is the OTel instrumentation scope version.
	InstrumentationVersion = "1.0.0"
)

Variables

This section is empty.

Functions

func NewTracerProvider added in v1.3.2

func NewTracerProvider(ctx context.Context, endpoint, serviceName string) (*sdktrace.TracerProvider, error)

NewTracerProvider creates a TracerProvider that exports spans via OTLP/HTTP. The caller is responsible for calling Shutdown on the returned provider.

func SetupPropagation added in v1.3.2

func SetupPropagation()

SetupPropagation configures the global OTel text-map propagator to handle W3C TraceContext, W3C Baggage, and AWS X-Ray trace headers.

func Tracer added in v1.3.2

func Tracer(tp trace.TracerProvider) trace.Tracer

Tracer returns a named tracer from the given TracerProvider. If tp is nil the global noop provider is used.

Types

type AgentInfo added in v1.3.10

type AgentInfo struct {
	Name string // Agent/pack name (maps to gen_ai.agent.name)
	ID   string // Agent/pack ID (maps to gen_ai.agent.id)
}

AgentInfo holds optional agent identity metadata for session spans.

type OTelEventListener added in v1.3.2

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

OTelEventListener converts runtime events into OTel spans in real time. It implements the events.Listener function signature via its OnEvent method. It is safe for concurrent use and tolerates out-of-order event delivery. Call Close when the listener is no longer needed to stop the cleanup goroutine.

func NewOTelEventListener added in v1.3.2

func NewOTelEventListener(tracer trace.Tracer, opts ...OTelOption) *OTelEventListener

NewOTelEventListener creates a listener that creates OTel spans from runtime events. A background goroutine periodically cleans up stale entries to prevent unbounded map growth. Call Close when the listener is no longer needed.

func (*OTelEventListener) Close added in v1.3.10

func (l *OTelEventListener) Close()

Close stops the background cleanup goroutine.

func (*OTelEventListener) EndSession added in v1.3.2

func (l *OTelEventListener) EndSession(sessionID string)

EndSession ends the root span for the given session.

func (*OTelEventListener) OnEvent added in v1.3.2

func (l *OTelEventListener) OnEvent(evt *events.Event)

OnEvent handles a single runtime event and creates/completes OTel spans accordingly. It is safe for concurrent use and can be passed to EventBus.SubscribeAll.

func (*OTelEventListener) StartSession added in v1.3.2

func (l *OTelEventListener) StartSession(parentCtx context.Context, sessionID string, agent ...AgentInfo)

StartSession creates a root span for the given session, optionally parented under the span context in parentCtx. It is idempotent: if a session already exists for the given ID, the previous session span is ended before creating a new one. This allows callers to call StartSession on every Send/Stream with a fresh parent context. The optional agent parameter provides agent identity attributes for the span.

type OTelOption added in v1.6.0

type OTelOption func(*OTelEventListener)

OTelOption configures an OTelEventListener.

func WithContentCapture added in v1.6.0

func WithContentCapture(enabled bool) OTelOption

WithContentCapture enables attaching conversation content and tool payloads to spans.

OFF by default. Span structure, timing, token usage, model names and tool NAMES are unaffected — those carry the operational value without the payload, and remain on regardless.

Enable this only where the trace backend is an appropriate place for customer data. Where tool arguments may carry credentials — on-behalf-of token exchange puts per-user delegated OAuth tokens there — wrap the subscriber in events.Redacting rather than reaching for a hook on this listener.

Jump to

Keyboard shortcuts

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