hs-opentelemetry-api
Copyright(c) Ian Duncan 2021
LicenseBSD-3
MaintainerIan Duncan
Stabilityexperimental
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

OpenTelemetry.Registry

Description

A global, process-wide registry that allows exporter and propagator libraries to make themselves discoverable by the SDK at initialization time.

This follows the same pattern as Go's autoexport and autoprop packages: the registry is the single source of truth for resolving OTEL_TRACES_EXPORTER, OTEL_PROPAGATORS, and similar environment variables.

How it works

  • The SDK registers its known defaults (otlp, tracecontext, baggage, b3, datadog) using the IfAbsent variants during initialization.
  • Third-party packages that call the plain register variants before SDK init will therefore take precedence over built-in defaults.
  • After SDK init, the registry is no longer consulted; changes have no retroactive effect on an already-initialized TracerProvider.

Usage example

import OpenTelemetry.Registry (registerSpanExporterFactory, registerTextMapPropagator)
import OpenTelemetry.Trace (initializeGlobalTracerProvider)

main :: IO ()
main = do
  -- Register a custom exporter before SDK init.
  -- When OTEL_TRACES_EXPORTER="zipkin", the SDK will use this factory.
  registerSpanExporterFactory "zipkin" myZipkinExporterFactory

  -- Register a custom propagator.
  -- When OTEL_PROPAGATORS="xray", the SDK will use this propagator.
  registerTextMapPropagator "xray" myXRayPropagator

  -- The SDK now resolves exporter/propagator names from the registry.
  initializeGlobalTracerProvider
  ...

Since: 0.4.0.0

Synopsis

Span Exporter Registry

registerSpanExporterFactory :: Text -> IO SpanExporter -> IO () Source #

Register a span exporter factory, replacing any existing entry with the same name.

Use this from third-party exporter packages to override or extend the set of exporters available to the SDK.

Since: 0.4.0.0

registerSpanExporterFactoryIfAbsent :: Text -> IO SpanExporter -> IO Bool Source #

Register a span exporter factory only if no factory is already registered under the given name. Returns True if the factory was registered, False if an entry already existed.

The SDK uses this for built-in defaults so that user registrations (made before SDK initialization) take precedence.

Since: 0.4.0.0

lookupSpanExporterFactory :: Text -> IO (Maybe (IO SpanExporter)) Source #

Look up a span exporter factory by name.

Since: 0.4.0.0

registeredSpanExporterFactories :: IO (HashMap Text (IO SpanExporter)) Source #

Return all registered span exporter factories.

Since: 0.4.0.0

Metric Exporter Registry

registerMetricExporterFactory :: Text -> IO MetricExporter -> IO () Source #

Register a metric exporter factory, replacing any existing entry.

Since: 0.4.0.0

registerMetricExporterFactoryIfAbsent :: Text -> IO MetricExporter -> IO Bool Source #

Register a metric exporter factory only if absent.

Since: 0.4.0.0

lookupMetricExporterFactory :: Text -> IO (Maybe (IO MetricExporter)) Source #

Look up a metric exporter factory by name.

Since: 0.4.0.0

registeredMetricExporterFactories :: IO (HashMap Text (IO MetricExporter)) Source #

Return all registered metric exporter factories.

Since: 0.4.0.0

Log Record Exporter Registry

registerLogRecordExporterFactory :: Text -> IO LogRecordExporter -> IO () Source #

Register a log record exporter factory, replacing any existing entry.

Since: 0.4.0.0

registerLogRecordExporterFactoryIfAbsent :: Text -> IO LogRecordExporter -> IO Bool Source #

Register a log record exporter factory only if absent.

Since: 0.4.0.0

lookupLogRecordExporterFactory :: Text -> IO (Maybe (IO LogRecordExporter)) Source #

Look up a log record exporter factory by name.

Since: 0.4.0.0

registeredLogRecordExporterFactories :: IO (HashMap Text (IO LogRecordExporter)) Source #

Return all registered log record exporter factories.

Since: 0.4.0.0

Text Map Propagator Registry

registerTextMapPropagator :: Text -> TextMapPropagator -> IO () Source #

Register a text map propagator, replacing any existing entry with the same name.

Since: 0.4.0.0

registerTextMapPropagatorIfAbsent :: Text -> TextMapPropagator -> IO Bool Source #

Register a text map propagator only if absent. Returns True when a new entry was inserted.

Since: 0.4.0.0

lookupRegisteredTextMapPropagator :: Text -> IO (Maybe TextMapPropagator) Source #

Look up a text map propagator by name.

Since: 0.4.0.0

registeredTextMapPropagators :: IO (HashMap Text TextMapPropagator) Source #

Return all registered text map propagators.

Since: 0.4.0.0

Resource Detector Registry

type ResourceDetector = IO Resource Source #

A resource detector is an IO action that produces a Resource. Detectors that do not apply to the current environment should return mkResource [] (an empty resource).

Since: 0.4.0.0

registerResourceDetector :: Text -> ResourceDetector -> IO () Source #

Register a resource detector, replacing any existing entry with the same name.

Use this from application code or third-party packages to make a custom detector available to the SDK.

Since: 0.4.0.0

registerResourceDetectorIfAbsent :: Text -> ResourceDetector -> IO Bool Source #

Register a resource detector only if absent. Returns True when a new entry was inserted.

The SDK uses this for built-in detectors so that user registrations (made before SDK initialization) take precedence.

Since: 0.4.0.0

lookupResourceDetector :: Text -> IO (Maybe ResourceDetector) Source #

Look up a resource detector by name.

Since: 0.4.0.0

registeredResourceDetectors :: IO (HashMap Text ResourceDetector) Source #

Return all registered resource detectors.

Since: 0.4.0.0