Documentation
¶
Overview ¶
Package telemetry provides OpenTelemetry integration for PromptKit, including TracerProvider management and an event-to-span listener.
Index ¶
Constants ¶
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.
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) *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.