- 
                Notifications
    
You must be signed in to change notification settings  - Fork 945
 
          feat(sdk-logs): Add FilteringLogRecordProcessor
          #5991
        
          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
base: main
Are you sure you want to change the base?
  
    feat(sdk-logs): Add FilteringLogRecordProcessor
  
  #5991
              Conversation
          Codecov Report❌ Patch coverage is  
 Additional details and impacted files@@            Coverage Diff             @@
##             main    #5991      +/-   ##
==========================================
- Coverage   95.16%   95.13%   -0.03%     
==========================================
  Files         316      317       +1     
  Lines        9207     9233      +26     
  Branches     2075     2087      +12     
==========================================
+ Hits         8762     8784      +22     
- Misses        445      449       +4     
 🚀 New features to boost your workflow:
  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacksonWeber - please also mark all features that are marked as in-development in the spec as @experimental in the TSdoc. This way we can avoid blocking https://github.com/open-telemetry/opentelemetry-js/milestone/19
          
 Experimental features have been marked as such. Thanks for the feedback!  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, overall I'm a bit confused by this feature - the spec for it seems still a bit vague and seems to duplicate functionality from existing features. 🤔 That's not this PR's issue, I feel like it's a symptom of a spec that's not quite where we'd need it to be yet.
I suppose the value proposition for having a LoggerConfigurator is to save on allocations in the pipeline - which is important for a hot path like this. (Q: @JacksonWeber is this the motivation for working on this feature?) If that's not the goal, then we could accomplish the same thing today in the LogRecordProcessor.
Though it seems to me that the optimizing LogRecordImpl to avoid expensive operations until it's properties are first accessed, and then applying filtering in the LogRecordProcessor may be a better way to go about it without adding additional concept to the public API.
The Go SIG seems to have a similar stance: open-telemetry/opentelemetry-specification#4644
| // Get logger configuration | ||
| const loggerConfig = this._sharedState.getLoggerConfig( | ||
| this.instrumentationScope | ||
| ); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that emit is a hot-path, I think we should optimize here wherever possible.
One thing I noticed is that the way it's implemented right now is:
- we call getLoggerConfig()
 - if it has already cached something for this Logger, it will always return that initial config
- dynamic updates are therefore not possible
 
 
Do we need the map lookup or should we just cache it in the logger? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary motivation for this feature work is just to get an implementation of trace-based log sampling and minimum severity-based log sampling implemented in a way that's easy for users to enable as part of the configuration of their LoggerProvider.
Thanks for the link to the issue in the Go repo, I'm happy to refactor this PR to avoid the creation/usage of the LoggerConfigurator and just implement these two filtering strategies in the LogRecordProcessor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pichlermarc the PR has been updated to just add a new logRecordProcessor that handles both types of filtering. Please review when you have a chance.
…ksonWeber/opentelemetry-js into jacksonweber/logger-sampling
loggerConfiguratorFilteringLogRecordProcessor
      
Which problem is this PR solving?
Updates the logs SDK to support the minimum severity filtering and trace-based log filtering via the FilteringLogRecordExporter.
Short description of the changes
This pull request introduces a configurable logger filtering mechanism to the OpenTelemetry SDK logs package, allowing log records to be filtered based on severity and trace sampling, and enabling per-logger configuration through a new pattern-based API. The core changes add a
LoggerConfiguratorinterface, implement pattern-based configuration, and apply these configurations during log record emission. This improves flexibility and compliance with logging specifications.Logger configuration and filtering enhancements
This pull request introduces a new feature to the OpenTelemetry JS SDK for logs: the
FilteringLogRecordProcessor. This processor allows users to filter log records by minimum severity and/or trace sampling before they are exported. The PR includes the implementation, documentation, and comprehensive tests for this functionality.Key changes:
Feature: Filtering Log Records
FilteringLogRecordProcessorclass, which can filter log records based on minimum severity or whether the associated trace is sampled, before passing them to another processor. The processor is configurable and can be combined with existing processors. [1] [2] [3]Documentation
sdk-logsREADME with usage examples and explanations for minimum severity filtering, trace-based filtering, and combining both filters using the newFilteringLogRecordProcessor.Testing
FilteringLogRecordProcessor, covering scenarios for minimum severity filtering, trace-based filtering, default behaviors, and combined filtering logic. [1] [2]Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: