Skip to main content

RegisterProvidersWithContext

Registers a tracer & metric provider for the given service name.

def RegisterProvidersWithContext(
ctx: context.Context,
serviceName: string,
config: *Config
) - > error

Registers a tracer and metric provider for the given service name. This function configures and initializes OpenTelemetry tracing and metrics based on the provided configuration, allowing for observability of the specified service.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used for OTLP gRPC and HTTP exporters to manage their lifecycle.
serviceNamestringThe name of the service for which the tracer and metric providers are being registered. This name is used to identify the telemetry resource.
config*ConfigThe configuration object specifying the type of exporter (e.g., File, Jaeger, OTLP gRPC, OTLP HTTP) and its associated settings. If nil, no providers are registered.

Returns

TypeDescription
errorAn error if the configuration is invalid, an exporter cannot be created, or if there's an issue setting up the tracer or meter providers.