Documentation
¶
Overview ¶
Package otlp provides OpenTelemetry Protocol (OTLP) provider implementations
Package otlp provides OpenTelemetry Protocol (OTLP) provider implementations ¶
Package otlp provides OpenTelemetry Protocol (OTLP) provider implementations
Index ¶
- Constants
- func NewLoggerProviderWithShutdown(ctx context.Context, config Config, res *resource.Resource) (log.LoggerProvider, func(context.Context) error, error)
- func NewMetricReader(ctx context.Context, config Config) (sdkmetric.Reader, error)
- func NewTracerProviderWithShutdown(ctx context.Context, config Config, res *resource.Resource, ...) (trace.TracerProvider, func(context.Context) error, error)
- type Config
Constants ¶
const ( // ProtocolHTTPProtobuf selects the OTLP/HTTP transport with protobuf payloads. // This is the default when Protocol is left unset. ProtocolHTTPProtobuf = "http/protobuf" // ProtocolGRPC selects the OTLP/gRPC transport. ProtocolGRPC = "grpc" )
Protocol values accepted by Config.Protocol. An empty/unset Protocol is equivalent to ProtocolHTTPProtobuf.
const DefaultExportTimeout = 30 * time.Second
DefaultExportTimeout bounds one export when Config.ExportTimeout is unset and no OTel timeout variable applies. It replaces the SDK exporters' own 10s default, which is tight for the off-cluster destinations this package exists to reach — a custom base path on Endpoint is how a caller targets a third-party ingest route.
The value matters because the SDK's two timeouts are asymmetric. Under OTLP/HTTP — this package's default transport — the exporter's timeout is the HTTP client's PER-REQUEST deadline, and a request that trips it is classified retryable and sent again; only the processor's or reader's export budget bounds that retry. A destination that accepts a batch but answers slower than the exporter's deadline is therefore handed the same batch twice, and because the retry succeeds nothing is logged on this side. A receiver that counts what it receives then counts those spans, points or records twice. Giving both the same budget leaves that re-send no room.
Variables ¶
This section is empty.
Functions ¶
func NewLoggerProviderWithShutdown ¶ added in v0.0.42
func NewLoggerProviderWithShutdown( ctx context.Context, config Config, res *resource.Resource, ) (log.LoggerProvider, func(context.Context) error, error)
NewLoggerProviderWithShutdown creates an OTLP logger provider with a shutdown function. When no endpoint is configured, it returns a no-op provider with a nil shutdown function.
The Logs API/SDK used here (go.opentelemetry.io/otel/log, go.opentelemetry.io/otel/sdk/log, and the otlploghttp exporter) implements the OpenTelemetry specification's Logs API, which is marked Stable (https://opentelemetry.io/docs/specs/otel/logs/api/). Their Go module version (v0.21.0 as of writing) hasn't crossed 1.0 yet, but that mirrors the Prometheus metrics exporter this package already depends on (go.opentelemetry.io/otel/exporters/prometheus, also 0.x): pre-1.0 module versioning here tracks release cadence, not spec/API stability.
func NewMetricReader ¶
NewMetricReader creates an OTLP metric reader for use in a unified meter provider
func NewTracerProviderWithShutdown ¶
func NewTracerProviderWithShutdown( ctx context.Context, config Config, res *resource.Resource, extraProcessors ...sdktrace.SpanProcessor, ) (trace.TracerProvider, func(context.Context) error, error)
NewTracerProviderWithShutdown creates an OTLP tracer provider with a shutdown function. Additional span processors (e.g. a Sentry bridge) can be registered via extraProcessors. When neither Endpoint nor TracesEndpoint is set but extra processors are provided, a real SDK provider is created without an OTLP exporter so the processors still receive spans.
Types ¶
type Config ¶
type Config struct {
Endpoint string
Headers map[string]string
Insecure bool
SamplingRate float64
CACertPath string
// Protocol selects the OTLP transport: ProtocolGRPC ("grpc") or
// ProtocolHTTPProtobuf ("http/protobuf"). An empty value means
// ProtocolHTTPProtobuf, preserving this package's original HTTP-only
// behavior for callers that don't set it.
Protocol string
// ExportTimeout bounds a single export, for traces, metrics and logs alike.
// It is applied to both the exporter and the processor or reader driving it,
// so neither can outlive the other. Set it above the destination's worst-case
// response time.
//
// Zero or negative means the OTel environment variables for the signal, and
// DefaultExportTimeout when those are unset too — see exportTimeoutFor for the
// precedence and why this package resolves those variables itself.
ExportTimeout time.Duration
// Sampler, when non-nil, is the tracer provider's sampler and SamplingRate
// is ignored. Nil keeps the default,
// ParentBased(TraceIDRatioBased(SamplingRate)), which follows a remote
// parent's sampled flag in both directions. Set this when an unsampled
// parent from upstream (e.g. an edge proxy sampling at a low rate) must not
// suppress this service's spans. Traces sampled that way reference upstream
// spans that were never exported, so backends show a missing parent.
Sampler sdktrace.Sampler
// TracesEndpoint, when set, is the full URL traces are POSTed to, used
// verbatim: no "/v1/traces" suffix is appended and its scheme alone decides
// TLS (Insecure is not consulted for it). It overrides Endpoint for traces
// only; metrics and logs keep using Endpoint, which may be left empty for a
// traces-only setup. Exact paths are an OTLP/HTTP concept, so setting it
// with ProtocolGRPC is a configuration error, as is a URL with userinfo or
// a query, or a path the exporter could not send exactly as written.
TracesEndpoint string
// EnvReader is consulted for the OTel timeout variables that ExportTimeout
// falls back to. A nil value falls back to the real OS environment, so the
// zero value of this struct reads the process environment as before.
EnvReader env.Reader
}
Config holds OTLP-specific configuration