1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-03 22:52:30 +02:00

Add the log/embedded package (#4932)

* Add the log/embedded package

* Embed the Logger and LoggerProvider types
This commit is contained in:
Tyler Yahn 2024-02-18 07:51:13 -08:00 committed by GitHub
parent 395800bbd5
commit 48bb3c8642
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 58 additions and 2 deletions

47
log/embedded/embedded.go Normal file
View File

@ -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() }

View File

@ -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.
//

View File

@ -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.
//