Skip to main content
Agent SDK for Go emits structured logs throughout the agent lifecycle — config validation, runtime execution, workflow steps, and exporter diagnostics. Logs are separate from Telemetry (run summaries) and Tracing (spans).

Default behavior

Without observability config, the SDK uses a default logger writing to stderr at level error. Set the level with WithLogLevel:
No OTLP export unless you configure it.

OTLP log export

When WithObservabilityConfig is set and DisableLogs is false, SDK logs export to your OTLP backend automatically — the default logger is bridged to the same OpenTelemetry LoggerProvider:
No separate WithLogger call is needed for OTLP — the SDK wires logger.DefaultLoggerWithOtelProvider when logs are enabled. Use the same WithObservabilityConfig and log level on NewAgentWorker for worker-side log export.

Custom logger + OTLP

If you pass WithLogger with a custom logger, OTLP logs from WithObservabilityConfig are not automatically bridged — the SDK warns at build time. Bridge manually:
When WithObservabilityConfig enables logs, any standalone WithLogs value is replaced by the OTLP client built from config.

Bring your own logs exporter

Use WithLogs with observability.NewLogs when not using WithObservabilityConfig:

Disable logging

Discards all SDK log output — useful in tests or when an external wrapper captures everything.

Log levels

Shutdown and flush

OTLP log records are batched before export. Allow a brief drain window on shutdown in production — call Agent.Close() or AgentWorker.Stop() before the process exits, not just on signal receipt.

Integrate with your logging pipeline

Write to a file or stdout — override the default logger with a custom writer:
Forward to an aggregator (Loki, Datadog, Splunk) via the OTLP Collector. Wire OTLP log export from the SDK, then configure the collector to forward to your backend:
Forward to an existing slog pipeline — implement interfaces.Logger wrapping your handler and pass it to WithLogger.

Hooks logging

Hook examples in the repository log hook activity to stderr with a [hooks] prefix. See Hooks and Hooks example. Example: Observability · Logs example.

Example

Observability

OTLP traces, metrics, and logs

Tracing

OTLP traces in the same config block

Metrics

OTLP metrics export