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

Introduce component logger with appropriate attributes #12259

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

Conversation

djaglowski
Copy link
Member

@djaglowski djaglowski commented Feb 3, 2025

Implements the logger described in #12217

Alternative to #12057

Resolves #11814

component/componentattribute:

  • Initializes new module
  • Defines constants for component telemetry attribute keys
  • Defines a zapcore.Core which can remove attributes from the root logger

service:

  • Rebases component instantiation on attribute sets
  • Internal constructors for attribute sets for each component type
  • Constructs loggers from componentattribute

otlpreceiver:

  • Uses componentattribute to remove otelcol.signal attribute from logger

memorylimiter:

  • Uses componentattribute to remove otelcol.signal, otelcol.pipeline.id and otelcol.component.id attributes from logger

@djaglowski djaglowski force-pushed the component-logger branch 8 times, most recently from 8845f3e to e8565de Compare February 4, 2025 16:32
@djaglowski djaglowski force-pushed the component-logger branch 4 times, most recently from 8ebe64f to 0cdc5de Compare February 4, 2025 17:05
Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 90.32258% with 9 lines in your changes missing coverage. Please review.

Project coverage is 91.32%. Comparing base (fb06c99) to head (95a3234).

Files with missing lines Patch % Lines
component/telemetry.go 0.00% 9 Missing ⚠️

❌ Your patch check has failed because the patch coverage (90.32%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12259      +/-   ##
==========================================
- Coverage   91.35%   91.32%   -0.03%     
==========================================
  Files         467      467              
  Lines       25761    25780      +19     
==========================================
+ Hits        23533    23543      +10     
- Misses       1810     1819       +9     
  Partials      418      418              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@djaglowski djaglowski force-pushed the component-logger branch 2 times, most recently from ddc480f to 39415d7 Compare February 4, 2025 17:59
@djaglowski djaglowski marked this pull request as ready for review February 4, 2025 18:42
@djaglowski djaglowski requested a review from a team as a code owner February 4, 2025 18:42
@djaglowski djaglowski requested a review from dmitryax February 4, 2025 18:42
Comment on lines 14 to 18
type Core struct {
zapcore.Core
from *zap.Logger
attrs attribute.Set
}
Copy link
Member

@bogdandrutu bogdandrutu Feb 5, 2025

Choose a reason for hiding this comment

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

Looking at usages (outside the service) the only think needed is Without(keys ...string) *zap.Logger

Can we do some golang magic, and actually public expose only an interface (rest of the implementation is in otelcol/service)?

The ideal scenario may be something that extend Logger, not sure if that works because Logger is a struct.

Copy link
Member

Choose a reason for hiding this comment

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

Here is where I got #12289

I don't have to expose public any interface. We will still need to expose the fields keys not sure where though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have to expose public any interface

I'm trying to incorporate your solution to simplify mine, but one consideration overlooked is that in practice we pass different kinds of loggers into tests, so we must make a type assertion to check for the Without method. If we're doing this, I think we need to at least give a name the interface so that components do not need to assert against an anonymous interface. The alternative would be to enforce somehow that tests use the same logger, but this is impractical IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly, for tests that do want to validate the functionality of the shared logger, they need to be able to instantiate a logger, so at least then you need to expose a testing logger which is very similar to the actual logger.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was able to reduce the surface area of componentattribute but still think we need a constructor for the logger

Comment on lines 47 to 51
return zap.New(&Core{
Core: withAttributes.Core(),
from: l.from,
attrs: attribute.NewSet(newAttrs...),
})
Copy link
Member

Choose a reason for hiding this comment

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

With this people lose other settings (options of the logger). You need to use logger.WithOptions(zap.WrapCore(...){})

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reworked logger creation to use WithOptions

attrs attribute.Set
}

func NewLogger(from *zap.Logger, attrs *attribute.Set) *zap.Logger {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how to avoid exposing this. It's used in component tests, and also in the graph when instantiating the loggers for components.

Comment on lines +19 to +22
type loggerCore interface {
zapcore.Core
Without(fields ...string) *zap.Logger
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is defined both here and internally in component in order to avoid exposing it.

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.

Loggers for shared components should not report signal type.
3 participants