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

Logging bridge for logr #5357

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1023952
WIP: Logging bridge for logr
scorpionknifes Apr 3, 2024
d3c70ae
Add basic unit tests
scorpionknifes Apr 6, 2024
9204132
add pkg docs
scorpionknifes Apr 9, 2024
43a8c62
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Apr 9, 2024
26a63c0
bump deps
scorpionknifes Apr 9, 2024
046f6e0
revert lint other files
scorpionknifes Apr 9, 2024
55371c6
Add changelog
scorpionknifes Apr 9, 2024
2ea0523
fix lint go.sum + yml
scorpionknifes Apr 9, 2024
099241e
fix comments and add to versions.yaml
scorpionknifes Apr 9, 2024
53d1fc7
fix goimports
scorpionknifes Apr 9, 2024
232a4fb
Update CODEOWNERS
scorpionknifes Apr 9, 2024
24246eb
fix levelSeverity logic
scorpionknifes Apr 9, 2024
14ba921
use logtest pkg for testing
scorpionknifes Apr 11, 2024
c7a8258
Update bridges/otelslog/example_test.go
scorpionknifes Apr 14, 2024
174a92c
Fix WithName, ctx propagation and errorKey
scorpionknifes Apr 24, 2024
334ce09
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Apr 24, 2024
3a25ec9
attempt to add new config
scorpionknifes Jun 24, 2024
49dbb63
Make WithName create new logger
scorpionknifes Jun 30, 2024
b7fd080
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Jun 30, 2024
cfa60ac
Fix tests
scorpionknifes Jun 30, 2024
d0aba47
fix tests by removing global logger
scorpionknifes Jun 30, 2024
df429b1
fix lint
scorpionknifes Jun 30, 2024
d280f94
Fix tests and add with_name test
scorpionknifes Jun 30, 2024
41b1895
bump dependencies
scorpionknifes Jun 30, 2024
4f954a4
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Jul 2, 2024
9193ace
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Jul 16, 2024
37debd4
update changelog
scorpionknifes Jul 16, 2024
755982b
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Jul 19, 2024
f5b5d3d
remove scope and implement changes
scorpionknifes Jul 19, 2024
f057908
add review changes
scorpionknifes Jul 25, 2024
1f341c7
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Jul 25, 2024
d040e57
Update CHANGELOG.md
pellared Jul 25, 2024
80690be
Merge branch 'main' into feature/impl-otellogr
scorpionknifes Jul 29, 2024
beae842
fix comments and append name
scorpionknifes Jul 29, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Support for the `OTEL_HTTP_CLIENT_COMPATIBILITY_MODE=http/dup` environment variable in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` to emit attributes for both the v1.20.0 and v1.26.0 semantic conventions. (#5401)
- The `go.opentelemetry.io/contrib/bridges/otelzerolog` module.
This module provides an OpenTelemetry logging bridge for `github.com/rs/zerolog`. (#5405)
- The `go.opentelemetry.io/contrib/bridges/otellogr` module.
This module provides an OpenTelemetry logging bridge for `github.com/go-logr/logr`. (#5357)

### Removed

Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bridges/otellogrus/ @open-te
bridges/prometheus/ @open-telemetry/go-approvers @dashpole
bridges/otelzap/ @open-telemetry/go-approvers @pellared @khushijain21
bridges/otelzerolog/ @open-telemetry/go-approvers @dmathieu @AkhigbeEromo
bridges/otellogr/ @open-telemetry/go-approvers @scorpionknifes

config/ @open-telemetry/go-approvers @MadVikingGod @pellared @codeboten

Expand Down
35 changes: 35 additions & 0 deletions bridges/otellogr/example_test.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 otellogr_test

import (
"github.com/go-logr/logr"

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

otellogr "go.opentelemetry.io/contrib/bridges/otellogr"
)

func Example() {
// Use a working LoggerProvider implementation instead e.g. using go.opentelemetry.io/otel/sdk/log.
provider := noop.NewLoggerProvider()

// Create an logr.Logger with *otellogr.LogSink and use it in your application.
logr.New(otellogr.NewLogSink(
"my/pkg/name",
otellogr.WithLoggerProvider(provider),
// Optionally, set the log level severity mapping.
otellogr.WithLevelSeverity(func(i int) log.Severity {
switch i {
case 0:
return log.SeverityInfo
case 1:
return log.SeverityWarn
default:
return log.SeverityFatal
}
})),
)
}
19 changes: 19 additions & 0 deletions bridges/otellogr/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module go.opentelemetry.io/contrib/bridges/otellogr

go 1.21

require (
github.com/go-logr/logr v1.4.2
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel/log v0.4.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
25 changes: 25 additions & 0 deletions bridges/otellogr/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
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.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/log v0.4.0 h1:/vZ+3Utqh18e8TPjuc3ecg284078KWrR8BRz+PQAj3o=
go.opentelemetry.io/otel/log v0.4.0/go.mod h1:DhGnQvky7pHy82MIRV43iXh3FlKN8UUKftn0KbLOq6I=
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
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