From 48bb3c8642602f9ecec9bc05d48782a527ea7c66 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Sun, 18 Feb 2024 07:51:13 -0800 Subject: [PATCH] Add the `log/embedded` package (#4932) * Add the log/embedded package * Embed the Logger and LoggerProvider types --- log/embedded/embedded.go | 47 ++++++++++++++++++++++++++++++++++++++++ log/logger.go | 6 ++++- log/provider.go | 7 +++++- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 log/embedded/embedded.go diff --git a/log/embedded/embedded.go b/log/embedded/embedded.go new file mode 100644 index 000000000..eeecbdae1 --- /dev/null +++ b/log/embedded/embedded.go @@ -0,0 +1,47 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package embedded provides interfaces embedded within the [OpenTelemetry Logs +// Bridge API]. +// +// Implementers of the [OpenTelemetry Logs Bridge API] can embed the relevant +// type from this package into their implementation directly. Doing so will +// result in a compilation error for users when the [OpenTelemetry Logs Bridge +// API] is extended (which is something that can happen without a major version +// bump of the API package). +// +// [OpenTelemetry Logs Bridge API]: https://github.com/open-telemetry/opentelemetry-go/tree/d3dcb3999c5689a7bb803cb0529e55a651ed14f1/log +package embedded // import "go.opentelemetry.io/otel/log/embedded" + +// LoggerProvider is embedded in the [Logs Bridge API LoggerProvider]. +// +// Embed this interface in your implementation of the [Logs Bridge API +// LoggerProvider] if you want users to experience a compilation error, +// signaling they need to update to your latest implementation, when the [Logs +// Bridge API LoggerProvider] interface is extended (which is something that +// can happen without a major version bump of the API package). +// +// [Logs Bridge API LoggerProvider]: https://github.com/open-telemetry/opentelemetry-go/blob/d3dcb3999c5689a7bb803cb0529e55a651ed14f1/log/provider.go#L22-L32 +type LoggerProvider interface{ loggerProvider() } + +// Logger is embedded in [Logs Bridge API Logger]. +// +// Embed this interface in your implementation of the [Logs Bridge API Logger] +// if you want users to experience a compilation error, signaling they need to +// update to your latest implementation, when the [Logs Bridge API Logger] +// interface is extended (which is something that can happen without a major +// version bump of the API package). +// +// [Logs Bridge API Logger]: https://github.com/open-telemetry/opentelemetry-go/blob/d3dcb3999c5689a7bb803cb0529e55a651ed14f1/log/logger.go#L28-L39 +type Logger interface{ logger() } diff --git a/log/logger.go b/log/logger.go index aefc42c2b..2b00ba094 100644 --- a/log/logger.go +++ b/log/logger.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/log/embedded" ) // Logger emits log records. @@ -26,7 +27,10 @@ import ( // package documentation on API implementation for information on how to set // default behavior for unimplemented methods. type Logger interface { - // TODO (#4909): embed an embedded type from otel/log/embedded. + // Users of the interface can ignore this. This embedded type is only used + // by implementations of this interface. See the "API Implementations" + // section of the package documentation for more information. + embedded.Logger // Emit emits a log record. // diff --git a/log/provider.go b/log/provider.go index 76c870ac2..4a0da4023 100644 --- a/log/provider.go +++ b/log/provider.go @@ -14,13 +14,18 @@ package log // import "go.opentelemetry.io/otel/log" +import "go.opentelemetry.io/otel/log/embedded" + // LoggerProvider provides access to [Logger]. // // Warning: Methods may be added to this interface in minor releases. See // package documentation on API implementation for information on how to set // default behavior for unimplemented methods. type LoggerProvider interface { - // TODO (#4909): embed an embedded type from otel/log/embedded. + // Users of the interface can ignore this. This embedded type is only used + // by implementations of this interface. See the "API Implementations" + // section of the package documentation for more information. + embedded.LoggerProvider // Logger returns a new [Logger] with the provided name and configuration. //