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

otellogr: Implement Logsink.Info() and conversions #6111

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

Conversation

scorpionknifes
Copy link
Member

@scorpionknifes scorpionknifes commented Sep 12, 2024

This PR implements a few methods for otellogr package

  • Enabled
  • Info
  • WithName
  • WithValue

TODO remaining

  • Init
  • Error

Please add skip changelog thx 🙏

Part of #5192

Comment on lines +23 to +28
// The Level is transformed by using the [WithLevels] option. If the option is
// not provided, all logr levels will be mapped to [log.SeverityInfo].
// The levels are mapped in order, with the first level in the list corresponding
// to the logr level 0, the second level corresponding to logr level 1, and so on.
// If the logr level is greater than the number of levels provided, it will be
// mapped to [log.SeverityInfo].
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

In scope of this PR I suggest removing level transformation and leave it to a separate PR.

Personally, I preferred the previous design as it was more flexible.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 99.25373% with 1 line in your changes missing coverage. Please review.

Project coverage is 66.1%. Comparing base (e1b1d77) to head (87167c4).

Files with missing lines Patch % Lines
bridges/otellogr/convert.go 99.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #6111     +/-   ##
=======================================
+ Coverage   65.7%   66.1%   +0.3%     
=======================================
  Files        204     205      +1     
  Lines      13085   13209    +124     
=======================================
+ Hits        8607    8738    +131     
+ Misses      4215    4208      -7     
  Partials     263     263             
Files with missing lines Coverage Δ
bridges/otellogr/logsink.go 98.5% <100.0%> (+18.9%) ⬆️
bridges/otellogr/convert.go 99.0% <99.0%> (ø)

@pellared pellared added the Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG label Sep 12, 2024
// The logr records are converted to OpenTelemetry [log.Record] in the following
// way:
//
// - Time is set as the current time of conversion.
Copy link
Member

Choose a reason for hiding this comment

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

Is this true?

Suggested change
// - Time is set as the current time of conversion.

Comment on lines +23 to +28
// The Level is transformed by using the [WithLevels] option. If the option is
// not provided, all logr levels will be mapped to [log.SeverityInfo].
// The levels are mapped in order, with the first level in the list corresponding
// to the logr level 0, the second level corresponding to logr level 1, and so on.
// If the logr level is greater than the number of levels provided, it will be
// mapped to [log.SeverityInfo].
Copy link
Member

Choose a reason for hiding this comment

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

In scope of this PR I suggest removing level transformation and leave it to a separate PR.

Personally, I preferred the previous design as it was more flexible.

ls := NewLogSink("name", WithLoggerProvider(rec))
lsWithName := ls.WithName("test")
require.NotEqual(t, ls, lsWithName)
require.Equal(t, lsWithName, ls.WithName("test"))
Copy link
Member

Choose a reason for hiding this comment

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

I strongly prefer if we assert the exported records (behavior/user output) instead of testing the internals.

for _, tt := range []struct {
name string
f func(*logr.Logger)
wantLoggerCount int
Copy link
Member

Choose a reason for hiding this comment

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

unused?

}

func TestConvertValue(t *testing.T) {
now := time.Now()
Copy link
Member

Choose a reason for hiding this comment

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

Why not a constant value as in other places?

name string
f func(*logr.Logger)
wantLoggerCount int
wantRecords []wantRecord
Copy link
Member

Choose a reason for hiding this comment

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

We are always emitting one record. No need for a slice here.

last := len(rec.Result()) - 1

assert.Len(t, rec.Result()[last].Records, len(tt.wantRecords))
for i, record := range rec.Result()[last].Records {
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 also assert the Name, Version, and SchemeURL of ScopeRecords

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants