OpenTelemetry SDK provider

OpenTelemetry SDK wiring for Piko's logger and monitoring services. It registers the SDK-backed TracerProvider and MeterProvider factory, and exposes service factories for the in-process monitoring transport.

Overview

The package does two distinct jobs and you usually want both. Importing the package runs an init() that registers an OtelProviderFactory with the logger driver. A blank import is enough to install it. When an OTLP-protocol module (for example logger_integration_otel_grpc or logger_integration_otel_http) is also imported, the logger builds SDK-backed sdktrace.TracerProvider and sdkmetric.MeterProvider instances configured against the OTLP endpoint. Without the package, the logger sees no factory and falls back to a noop OTEL pipeline. The package handles span batching, metric reading, and resource detection (Kubernetes, AWS Lambda, AWS ECS, Cloud Run, Azure Container Apps).

The second job is OtelServiceFactories(), which returns factories for the in-process monitoring service. Pass the result to piko.WithMonitoringOtelFactories to give the monitoring transport SDK-backed SpanProcessor and MetricsCollector adapters that feed a TelemetryStore. These factories override the noop defaults the bootstrap layer installs, so the integration slots into the monitoring port without new plumbing. The CLI/TUI then reads spans and metrics over the monitoring gRPC transport without needing an external Jaeger or Prometheus. NewSpanProcessor(store) records every finished span into the store. NewMetricsCollector(store, interval, opts...) wraps the SDK's ManualReader.

The two paths read metrics on independent intervals. The in-process collector polls its ManualReader on the interval you pass to NewMetricsCollector. A non-positive interval falls back to the DefaultMetricsCollectionInterval of 5 seconds. The OTLP export path is separate. It uses a 30-second PeriodicReader to push metrics to the endpoint. Treat these as two pipelines, not one shared number.

The OTEL SDK dependency stays off the internal monitoring domain. createProviders accepts []any and filters for the SDK types, so an import of the package drives the only path that pulls the SDK in. The trace provider uses a parent-based TraceIDRatioBased sampler driven by OtelSetupConfig.TraceSampleRate, and a Shutdown chain flushes pending spans and metrics before closing the OTLP connection. All public methods are safe for concurrent use.

Requirements

  • One OTLP transport package imported as well: OpenTelemetry gRPC or OpenTelemetry HTTP. Without a registered protocol, OTLP-mode startup fails with unsupported OTLP protocol.
  • An OTEL setup config with Enabled: true and a valid Endpoint to use OTLP export. Without it, the package still produces local providers (no export) for use with the in-process monitoring transport.

Configuration

There is no Config struct in the package. Wiring divides between the OTEL driver config (consumed during logger initialisation) and the optional monitoring service factories.

import (
    "piko.sh/piko"
    "piko.sh/piko/wdk/logger/logger_otel_sdk"
    _ "piko.sh/piko/wdk/logger/logger_integration_otel_grpc"
    "piko.sh/piko/wdk/monitoring/monitoring_transport_grpc"
)

ssr := piko.New(
    piko.WithMonitoring(
        piko.WithMonitoringTransport(monitoring_transport_grpc.Transport()),
        piko.WithMonitoringOtelFactories(logger_otel_sdk.OtelServiceFactories()),
    ),
)

If you only need OTLP export and not the in-process monitoring transport, importing the package is enough. The init() registration runs unconditionally, so a blank import installs the provider factory.

Bootstrap

The integration wires in with no glue code. piko.WithMonitoringOtelFactories(logger_otel_sdk.OtelServiceFactories()) is the single bootstrap call for the monitoring side. The OTLP-export side has no piko.With* step. The package's init() and the OTEL setup config drive it.

WithMonitoringOtelFactories replaces a default set of noop factories. If you wire WithMonitoringTransport but omit WithMonitoringOtelFactories, the transport still starts but records nothing, and the Telemetry view stays empty. Pass both options together for SDK-backed monitoring.

See also

Sibling OTEL integrations:

Monitoring transport (the typical consumer of OtelServiceFactories):

Other logger integrations:

  • Sentry, error reporting with OTEL trace correlation.
  • Prometheus, Prometheus scrape endpoint for metrics.
  • File, file-based log persistence.

Framework docs:

External: