Documentation
¶
Overview ¶
Package telemetry provides OpenTelemetry export for session recordings. This enables exporting session events as distributed traces to observability platforms.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventConverter ¶
type EventConverter struct {
// Resource is the resource to attach to spans.
Resource *Resource
}
EventConverter converts runtime events to OTLP spans.
func NewEventConverter ¶
func NewEventConverter(resource *Resource) *EventConverter
NewEventConverter creates a new event converter.
func (*EventConverter) ConvertSession ¶
func (c *EventConverter) ConvertSession( sessionID string, sessionEvents []events.Event, ) ([]*Span, error)
ConvertSession converts a session's events to spans. The session becomes the root span, with pipeline/middleware/provider calls as child spans.
type Exporter ¶
type Exporter interface {
// Export sends events to the backend.
Export(ctx context.Context, spans []*Span) error
// Shutdown performs cleanup and flushes any pending data.
Shutdown(ctx context.Context) error
}
Exporter exports session events to an observability backend.
type HTTPClient ¶
HTTPClient interface for testing. NOSONAR(godre:S8196) - HTTPClient is clearer than Doer for this use case.
type OTLPExporter ¶
type OTLPExporter struct {
// contains filtered or unexported fields
}
OTLPExporter exports spans to an OTLP endpoint over HTTP.
func NewOTLPExporter ¶
func NewOTLPExporter(endpoint string, opts ...OTLPExporterOption) *OTLPExporter
NewOTLPExporter creates a new OTLP exporter.
type OTLPExporterOption ¶
type OTLPExporterOption func(*OTLPExporter)
OTLPExporterOption configures an OTLPExporter.
func WithBatchSize ¶
func WithBatchSize(size int) OTLPExporterOption
WithBatchSize sets the batch size for exports.
func WithHTTPClient ¶
func WithHTTPClient(client HTTPClient) OTLPExporterOption
WithHTTPClient sets a custom HTTP client.
func WithHeaders ¶
func WithHeaders(headers map[string]string) OTLPExporterOption
WithHeaders sets custom headers for OTLP requests.
func WithResource ¶
func WithResource(resource *Resource) OTLPExporterOption
WithResource sets the resource for exported spans.
type Resource ¶
type Resource struct {
// Attributes are key-value pairs describing the resource.
Attributes map[string]interface{} `json:"attributes"`
}
Resource represents the entity producing telemetry.
func DefaultResource ¶
func DefaultResource() *Resource
DefaultResource returns a default resource for PromptKit.
type Span ¶
type Span struct {
// TraceID is the unique identifier for the trace (16 bytes, hex-encoded).
TraceID string `json:"traceId"`
// SpanID is the unique identifier for this span (8 bytes, hex-encoded).
SpanID string `json:"spanId"`
// ParentSpanID is the ID of the parent span (empty for root spans).
ParentSpanID string `json:"parentSpanId,omitempty"`
// Name is the operation name.
Name string `json:"name"`
// Kind is the span kind (client, server, producer, consumer, internal).
Kind SpanKind `json:"kind"`
// StartTime is when the span started.
StartTime time.Time `json:"startTimeUnixNano"`
// EndTime is when the span ended.
EndTime time.Time `json:"endTimeUnixNano"`
// Attributes are key-value pairs associated with the span.
Attributes map[string]interface{} `json:"attributes,omitempty"`
// Status is the span status.
Status *SpanStatus `json:"status,omitempty"`
// Events are timestamped events within the span.
Events []*SpanEvent `json:"events,omitempty"`
}
Span represents a trace span in OpenTelemetry format.
type SpanEvent ¶
type SpanEvent struct {
// Name is the event name.
Name string `json:"name"`
// Time is when the event occurred.
Time time.Time `json:"timeUnixNano"`
// Attributes are key-value pairs associated with the event.
Attributes map[string]interface{} `json:"attributes,omitempty"`
}
SpanEvent represents an event within a span.
type SpanStatus ¶
type SpanStatus struct {
// Code is the status code (0=Unset, 1=Ok, 2=Error).
Code StatusCode `json:"code"`
// Message is the status message.
Message string `json:"message,omitempty"`
}
SpanStatus represents the status of a span.
type StatusCode ¶
type StatusCode int
StatusCode represents the status of a span.
const ( StatusCodeUnset StatusCode = 0 StatusCodeOk StatusCode = 1 StatusCodeError StatusCode = 2 )
Status codes.