Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs Bridge API prototype #4725

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
a6f19fe
Add empty design doc
pellared Nov 17, 2023
c8fcf28
Init Logs Bridge API design
pellared Nov 17, 2023
e48ae14
Document the design
pellared Nov 17, 2023
31c755f
Merge branch 'main' into logs-design
pellared Nov 20, 2023
cd39d63
Add Rationale
pellared Nov 20, 2023
4578694
Move design doc closer to the code
pellared Nov 20, 2023
fbd656f
Cleanup
pellared Nov 20, 2023
9d9f10b
Cleanup
pellared Nov 20, 2023
55bad1e
Fix typo
pellared Nov 20, 2023
249f4ed
Apply suggestions from code review
pellared Nov 20, 2023
33a8aca
Clairfy RecordOption
pellared Nov 20, 2023
2e3587c
document fields that optimize attrs
pellared Nov 21, 2023
f19f0c8
Add missing parenthesis
pellared Nov 21, 2023
5456b9d
Record and NewRecord is needed for SDK
pellared Nov 21, 2023
4365860
Add usage examples
pellared Nov 21, 2023
892ee8f
Document Rejected Alternative: Reuse slog
pellared Nov 21, 2023
f288cf2
Logger.Emit with record as argument
pellared Nov 22, 2023
c0a795b
Document Logger.Emit extensibility
pellared Nov 22, 2023
2704436
Apply suggestions from code review
pellared Nov 24, 2023
a718f69
Write prototype implementation and benchmarks
pellared Nov 24, 2023
700c91f
Add missing vanity import
pellared Nov 24, 2023
2e8403e
gofumpt
pellared Nov 24, 2023
441cde8
Add TODO comments
pellared Nov 24, 2023
de09ce6
Add copywrite header and fix for Go 1.20
pellared Nov 24, 2023
dad0503
refactor
pellared Nov 24, 2023
c43bd51
Update design
pellared Nov 24, 2023
19438ca
Update design
pellared Nov 24, 2023
d4896f6
Rejected Alternative: Passing struct as parameter to LoggerProvider.L…
pellared Nov 24, 2023
cf10dd0
Merge branch 'main' into logs-design
pellared Nov 28, 2023
ddcdbda
Add go.opentelemetry.io/otel/log/benchmark module
pellared Nov 28, 2023
ca5bfb7
Add slog.Handler naive implementation
pellared Nov 28, 2023
21ca157
go mod tidy
pellared Nov 28, 2023
0d9c335
Add logr.LogSink naive implementation
pellared Nov 28, 2023
1c3776b
Update design
pellared Nov 28, 2023
5bb9801
gofumpt
pellared Nov 28, 2023
7084df2
Refactor slogHandler
pellared Nov 28, 2023
3b8a68c
Export AttributesInlineCount
pellared Nov 28, 2023
44e01f8
Merge branch 'main' into logs-design
pellared Nov 30, 2023
e7b8c7a
Rename Record.Attributes to Record.WalkAttributes
pellared Nov 30, 2023
d19ebad
Merge branch 'main' into logs-design
pellared Dec 4, 2023
ba2903a
Unexport AttributesInlineCount
pellared Dec 4, 2023
6443d19
Fix typo
pellared Dec 4, 2023
b170245
Merge branch 'main' into logs-design
pellared Dec 5, 2023
21bea0f
Ignore request cancelation
pellared Dec 5, 2023
c8b3f05
Encapsulate Record fields
pellared Dec 5, 2023
a8ba6be
Fix tests
pellared Dec 5, 2023
60a4e45
Merge branch 'main' into logs-design
pellared Dec 7, 2023
b60433a
Merge branch 'main' into logs-design
pellared Dec 11, 2023
689faff
fix typo
pellared Dec 11, 2023
7f299ff
Merge branch 'main' into logs-design
pellared Dec 15, 2023
9f9acaf
Rejected Alternative: Logger.WithAttributes
pellared Dec 15, 2023
9deedde
Fix MD009/no-trailing-spaces
pellared Dec 15, 2023
ecb503a
Merge branch 'main' into logs-design
pellared Dec 18, 2023
445bae1
Make parallel benchmarks
pellared Dec 18, 2023
cd5a898
Merge branch 'main' into logs-design
pellared Dec 19, 2023
cd8217a
Merge branch 'main' into logs-design
pellared Dec 19, 2023
977f3d7
Record attributes as field and use sync.Pool for reducing allocations
pellared Dec 22, 2023
2d161ca
Merge branch 'main' into logs-design
pellared Dec 22, 2023
11e232c
Merge branch 'main' into logs-design
pellared Dec 27, 2023
033e2e9
go mod tidy
pellared Dec 27, 2023
8c8f7ab
Trace contextg correlation design
pellared Dec 27, 2023
a79b08f
writerLogger and slogHandler handle trace context
pellared Dec 27, 2023
4be490b
go mod tidy
pellared Dec 27, 2023
3552368
logrSink handle trace context
pellared Dec 27, 2023
3fbebee
Refine API implementation section
pellared Dec 27, 2023
8e25e81
Fix grammar
pellared Dec 27, 2023
321a049
Move log/benchmark to log/internal
pellared Dec 27, 2023
2d62729
Merge branch 'main' into logs-design
pellared Jan 10, 2024
a0bc4b8
Update log package
pellared Jan 10, 2024
f6a2308
go mod tidy
pellared Jan 10, 2024
b780472
Remove DESIGN.md
pellared Jan 10, 2024
8eb2fab
Merge branch 'main' into logs-design
pellared Jan 16, 2024
d832817
Add Severity[Level]1 consts
pellared Jan 17, 2024
f78cbec
Record attributes based on slog.Record (#6)
pellared Jan 18, 2024
1a8b1c5
Merge branch 'main' into logs-design
pellared Jan 18, 2024
6730f06
go mod tidy
pellared Jan 18, 2024
d114464
The caller must not subsequently mutate the record passed to Emit
pellared Jan 18, 2024
f08ebbf
Refine Emit docs
pellared Jan 18, 2024
d665181
Merge branch 'main' into logs-design
pellared Jan 18, 2024
a116609
go mod tidy
pellared Jan 18, 2024
5d8c58f
Handle structured body and attributes (#7)
pellared Jan 24, 2024
3131463
Merge branch 'main' into logs-design
pellared Jan 25, 2024
ecc26bc
Record with pointer receivers only (#8)
pellared Jan 26, 2024
2778c55
As[Type] Value methods
pellared Jan 26, 2024
68d99a8
Use stringer for enum types
pellared Jan 26, 2024
e5dc7cf
Revert Makefile changes
pellared Jan 26, 2024
4b96c4d
Merge branch 'main' into logs-design
pellared Jan 29, 2024
4084475
Merge branch 'main' into logs-design
pellared Jan 30, 2024
d4d4274
Fix Severity.String
pellared Jan 30, 2024
91358b4
TestKind
pellared Jan 30, 2024
b90eca9
Refactor Value.String
pellared Jan 30, 2024
a02b8ea
Remove KeyValue.Invalid
pellared Feb 1, 2024
a8a1b7e
Update AddAttributes
pellared Feb 1, 2024
c4a2209
Remove header
pellared Feb 1, 2024
45cfdcb
Update comment
pellared Feb 1, 2024
b55e22e
Refine comment
pellared Feb 1, 2024
aa3b222
Merge branch 'main' into logs-design
pellared Feb 1, 2024
4dccab0
go mod tidy
pellared Feb 1, 2024
4e2e5e3
Merge branch 'logs-design' of https://github.com/pellared/opentelemet…
pellared Feb 1, 2024
a8f265c
Refactor Severity to not use iota
pellared Feb 1, 2024
f8c46f1
Merge branch 'main' into logs-design
pellared Feb 6, 2024
b996e00
Remove Record.Clone as it is not necessary
pellared Feb 7, 2024
ed67f01
Refine KeyValue docs
pellared Feb 7, 2024
5851ead
Remove unused attrsSlice
pellared Feb 7, 2024
273a964
Merge branch 'main' into logs-design
pellared Feb 7, 2024
e89444d
go mod tidy
pellared Feb 7, 2024
147762f
value does not panic and change List to Slice
pellared Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ updates:
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /log
labels:
- dependencies
- go
- Skip Changelog
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /log/internal
labels:
- dependencies
- go
- Skip Changelog
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /metric
labels:
Expand Down
85 changes: 85 additions & 0 deletions log/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

/*
Package log defines the OpenTelemetry Bridge API.
It is supposed to be used by a log bridge implementation
that is an adapter between an existing logging library and OpenTelemetry.
Application code should not call this API directly.

Existing logging libraries generally provide a much richer set of features
than in OpenTelemetry. It is not a goal of OpenTelemetry, to ship
a feature-rich logging library.

# Bridge Implementations

The bridge implementation should allow passing a [context.Context] containing
a trace context from the caller to [Logger]'s Emit method.

A bridge can use [sync.Pool] of attributes for reducing the number of
heap allocations.

# API Implementations

This package does not conform to the standard Go versioning policy, all of its
interfaces may have methods added to them without a package major version bump.
This non-standard API evolution could surprise an uninformed implementation
author. They could unknowingly build their implementation in a way that would
result in a runtime panic for their users that update to the new API.

The API is designed to help inform an instrumentation author about this
non-standard API evolution. It requires them to choose a default behavior for
unimplemented interface methods. There are three behavior choices they can
make:

- Compilation failure
- Panic
- Default to another implementation

All interfaces in this API embed a corresponding interface from
[go.opentelemetry.io/otel/log/embedded]. If an author wants the default
behavior of their implementations to be a compilation failure, signaling to
their users they need to update to the latest version of that implementation,
they need to embed the corresponding interface from
[go.opentelemetry.io/otel/log/embedded] in their implementation. For
example,

import "go.opentelemetry.io/otel/log/embedded"

type LoggerProvider struct {
embedded.LoggerProvider
// ...
}

If an author wants the default behavior of their implementations to a panic,
they need to embed the API interface directly.

import "go.opentelemetry.io/otel/log"

type LoggerProvider struct {
log.LoggerProvider
// ...
}

This is not a recommended behavior as it could lead to publishing packages that
contain runtime panics when users update other package that use newer versions
of [go.opentelemetry.io/otel/log].

Finally, an author can embed another implementation in theirs. The embedded
implementation will be used for methods not defined by the author. For example,
an author who wants to default to silently dropping the call can use
[go.opentelemetry.io/otel/log/noop]:

import "go.opentelemetry.io/otel/log/noop"

type LoggerProvider struct {
noop.LoggerProvider
// ...
}

It is strongly recommended that authors only embed
[go.opentelemetry.io/otel/log/noop] if they choose this default behavior.
That implementation is the only one OpenTelemetry authors can guarantee will
fully implement all the API interfaces when a user updates their API.
*/
package log // import "go.opentelemetry.io/otel/log"
35 changes: 35 additions & 0 deletions log/embedded/embedded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// 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://pkg.go.dev/go.opentelemetry.io/otel/log
package embedded // import "go.opentelemetry.io/otel/log/embedded"

// LoggerProvider is embedded in
// [go.opentelemetry.io/otel/log.LoggerProvider].
//
// Embed this interface in your implementation of the
// [go.opentelemetry.io/otel/log.LoggerProvider] if you want users to
// experience a compilation error, signaling they need to update to your latest
// implementation, when the [go.opentelemetry.io/otel/log.LoggerProvider]
// interface is extended (which is something that can happen without a major
// version bump of the API package).
type LoggerProvider interface{ loggerProvider() }

// Logger is embedded in [go.opentelemetry.io/otel/log.Logger].
//
// Embed this interface in your implementation of the
// [go.opentelemetry.io/otel/log.Logger] if you want users to experience a
// compilation error, signaling they need to update to your latest
// implementation, when the [go.opentelemetry.io/otel/log.Logger] interface
// is extended (which is something that can happen without a major version bump
// of the API package).
type Logger interface{ logger() }
20 changes: 20 additions & 0 deletions log/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module go.opentelemetry.io/otel/log

go 1.20

require (
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.23.0-rc.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace go.opentelemetry.io/otel => ../

replace go.opentelemetry.io/otel/trace => ../trace

replace go.opentelemetry.io/otel/metric => ../metric
11 changes: 11 additions & 0 deletions log/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading