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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging bridge for logr #5357

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

scorpionknifes
Copy link
Member

@scorpionknifes scorpionknifes commented Apr 3, 2024

Resolves #5192

Looking to do benchmarks in a different PR

Notes:

  • slogSink converts any non string value to slog.Any which is handled with fmt.Sprintf("%+v", v) by otelslog. This PR does not do the above and instead opts to use convertValue to get the convert based on type which maybe less performant 馃
  • convertValue - follows how funcr handle interface{}
  • currently it's designed to convert nested values recursively with convertValue, is there a max depth for converted attributes?
  • kvBuffer - is used in otelslog, I propose to move kvBuffer to internal pkg and reused it here too?

Copy link

codecov bot commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 99.44444% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 62.9%. Comparing base (fed6e67) to head (334ce09).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #5357     +/-   ##
=======================================
+ Coverage   62.3%   62.9%   +0.5%     
=======================================
  Files        189     190      +1     
  Lines      11575   11755    +180     
=======================================
+ Hits        7219    7398    +179     
- Misses      4146    4147      +1     
  Partials     210     210             
Files Coverage 螖
bridges/otellogr/logsink.go 99.4% <99.4%> (酶)

@scorpionknifes scorpionknifes changed the title WIP: Logging bridge for logr Logging bridge for logr Apr 9, 2024
@scorpionknifes scorpionknifes marked this pull request as ready for review April 9, 2024 15:29
@scorpionknifes scorpionknifes requested a review from a team as a code owner April 9, 2024 15:29
bridges/otelslog/example_test.go Outdated Show resolved Hide resolved
// nameKey is used to log the `WithName` values as an additional attribute.
nameKey = "logger"
// errKey is used to log the error parameter of Error as an additional attribute.
errKey = "err"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use semantic conventions for this, err is too go-specific.
Logs have the notion of exception attributes, but not errors. Maybe that's what we should rely on?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about it, I wonder if we shouldn't suggest adding an error namespace to semantic conventions.
I have started a semantic conventions discussion about this: open-telemetry/semantic-conventions#921

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to rename it to error for now. I think this should not block this PR given that this bridge would be versioned as experimental.

Co-authored-by: Damien Mathieu <42@dmathieu.com>
Comment on lines 22 to 23
// - Context is not propagated to the OpenTelemetry log record, as logr does
// not provide a way to access it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we handle it if someone passes context as an attributes?

This is what I have done in https://github.com/pellared/opentelemetry-go/blob/147762ffb5c4394417b3f973274cc570723db79b/log/internal/logr.go.

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a quick review.

Comment on lines 266 to 270
if len(l.name) > 0 {
l.name += "/"
}
l.name += name
return &l
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rather create a new LogSink with a new l.logger that has the name appended to the previous logger. See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/bridge-api.md?plain=1#L72-L74

@@ -22,6 +22,7 @@

CODEOWNERS @MrAlias @MadVikingGod @pellared @dashpole

bridges/otellogr/ @open-telemetry/go-approvers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be an codeowner?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the requirement to be a member?

Copy link
Member

@pellared pellared Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not required.

However, if you want to be I can be your sponsor per https://github.com/pulls?q=author%3Ascorpionknifes+org%3Aopen-telemetry+is%3Apr+is%3Amerged+

You would just need to find a second sponsor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to sponsor you as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate it 馃檹 thanks

@scorpionknifes scorpionknifes force-pushed the feature/impl-otellogr branch 2 times, most recently from 1da0e2f to 9d75ae7 Compare April 24, 2024 13:58
Comment on lines +214 to +216
if l.name != "" {
record.AddAttributes(log.String(nameKey, l.name))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this the WithName method should create a new l.logger. The nameKey should not be needed.

#5357 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add logr log bridge
3 participants