Documentation
¶
Overview ¶
Package observability provides integration helpers for using observops with multi-agent systems and general Go applications.
This package provides utilities for:
- HTTP client middleware for distributed tracing
- HTTP server middleware for request instrumentation
- Agent task instrumentation for multi-agent workflows
- Context helpers for trace propagation
HTTP Client Middleware ¶
Wrap your HTTP client to automatically trace outgoing requests:
client := observability.WrapHTTPClient(http.DefaultClient, provider)
resp, err := client.Get("https://api.example.com/data")
HTTP Server Middleware ¶
Use the handler middleware for automatic request tracing:
handler := observability.HTTPMiddleware(provider)(yourHandler)
http.ListenAndServe(":8080", handler)
Agent Task Instrumentation ¶
Instrument agent tasks for multi-agent workflows:
err := observability.ObserveTask(ctx, provider, "ProcessData",
observability.WithAgentID("agent-1"),
observability.WithTaskType("synthesis"),
func(ctx context.Context) error {
// Your task logic here
return nil
},
)
Index ¶
- func HTTPMiddleware(provider observops.Provider) func(http.Handler) http.Handler
- func IncrementAgentCounter(ctx context.Context, provider observops.Provider, name string, agentID string, ...) error
- func ObserveTask(ctx context.Context, provider observops.Provider, name string, ...) error
- func RecordAgentMetric(ctx context.Context, provider observops.Provider, name string, value float64, ...) error
- func StartAgentSpan(ctx context.Context, provider observops.Provider, name string, agentID string, ...) (context.Context, observops.Span)
- func WrapHTTPClient(client *http.Client, provider observops.Provider) *http.Client
- type TaskOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPMiddleware ¶
HTTPMiddleware returns a middleware that instruments HTTP handlers with tracing.
func IncrementAgentCounter ¶
func IncrementAgentCounter(ctx context.Context, provider observops.Provider, name string, agentID string, additionalAttrs ...observops.KeyValue) error
IncrementAgentCounter increments a counter with agent context.
func ObserveTask ¶
func ObserveTask(ctx context.Context, provider observops.Provider, name string, opts []TaskOption, fn func(context.Context) error) error
ObserveTask instruments a task with tracing and metrics. It automatically creates a span for the task, records duration, and logs errors if the task fails.
func RecordAgentMetric ¶
func RecordAgentMetric(ctx context.Context, provider observops.Provider, name string, value float64, agentID string, additionalAttrs ...observops.KeyValue) error
RecordAgentMetric records a metric with agent context.
func StartAgentSpan ¶
func StartAgentSpan(ctx context.Context, provider observops.Provider, name string, agentID string, opts ...observops.SpanOption) (context.Context, observops.Span)
StartAgentSpan creates a new span for an agent operation. This is useful for instrumenting agent workflows without using ObserveTask.
Types ¶
type TaskOption ¶
type TaskOption func(*taskConfig)
TaskOption configures task observation.
func WithAgentID ¶
func WithAgentID(id string) TaskOption
WithAgentID sets the agent ID for the task.
func WithTaskAttributes ¶
func WithTaskAttributes(attrs ...observops.KeyValue) TaskOption
WithTaskAttributes sets additional span attributes.
func WithTaskMetadata ¶
func WithTaskMetadata(metadata map[string]string) TaskOption
WithTaskMetadata sets task metadata.