open-telemetry / opentelemetry-go

OpenTelemetry Go API and SDK
https://opentelemetry.io/docs/languages/go
Apache License 2.0
5.37k stars 1.09k forks source link

log: Add global LoggerProvider #4980

Open pellared opened 9 months ago

pellared commented 9 months ago

Problem Statement

From https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/bridge-api.md#loggerprovider

Normally, the LoggerProvider is expected to be accessed from a central place. Thus, the API SHOULD provide a way to set/register and access a global default LoggerProvider.

Proposed Solution

Add GetLoggerProvider and SetLoggerProvider to go.opentelemetry.io/otel.

Notice that this can be released only when Bridge API gets stable as go.opentelemetry.io/otel is already stable.

MrAlias commented 9 months ago

We cannot add support for this to otel until log is stable. If we want to support this prior to 1.0 a similar approach to https://pkg.go.dev/go.opentelemetry.io/otel/metric/global should be used.

pellared commented 9 months ago

If we want to support this prior to 1.0 a similar approach to https://pkg.go.dev/go.opentelemetry.io/otel/metric/global should be used.

Do you think that it is worth doing it prior 1.0? It may be inconvenient as otherwise we will make a breaking change when going stable. I would rather add it even in "1.1" as this is not a MUST in the specification and adding after the API is already stable would be more gentle for the users. This change would not affect the SDK.

MrAlias commented 9 months ago

I'm fine with a post-1.0. I think the metric one was motivated by a user ask and our desire to build a proof-of-concept for how it would work. I don't know of any user ask for this, currently, and I think the global implementation will be one of the easier ones.

Kimbohlovette commented 8 months ago

@pellared could you please assign this task to me? @jpkrohling could I peak this one? It directly related to the project "Implement one Logging bridge" in outreachy-otel

pellared commented 8 months ago

It is blocked until Go Logs SDK is stable.

Kimbohlovette commented 8 months ago

@pellared alright thanks

JPFrancoia commented 3 months ago

It took me a while to figure out I could do that: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp#example-package

Since the SetLoggerProvider isn't in otel's index, it's not easily discoverable. I'm already setting the tracer and provider with Set*Provider, can't wait for the logger one :)