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

[logs] Wrapped batch processor doesn't trigger correct log pool #5250

Closed
CodeBlanch opened this issue Jan 24, 2024 · 0 comments · Fixed by #5255
Closed

[logs] Wrapped batch processor doesn't trigger correct log pool #5250

CodeBlanch opened this issue Jan 24, 2024 · 0 comments · Fixed by #5255
Assignees
Labels
bug Something isn't working logs Logging signal related pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Comments

@CodeBlanch
Copy link
Member

CodeBlanch commented Jan 24, 2024

I worked through an issue with a user who wrapped the BatchLogRecordExportProcessor in a custom processor:

    configure.AddProcessor(new FilteringProcessor<LogRecord>(new BatchLogRecordExportProcessor(exporter), ShouldUpload));

    internal sealed class FilteringProcessor<T> : BaseProcessor<T>
    {
        private readonly BaseProcessor<T> inner;
        private readonly Func<T, bool> filter;

        public FilteringProcessor(BaseProcessor<T> inner, Func<T, bool> filter)
        {
            this.inner = inner;
            this.filter = filter;
        }

        public override void OnEnd(T activity)
        {
            // Call the underlying processor
            // only if the Filter returns true.
            if (this.filter(activity))
            {
                this.inner.OnEnd(activity);
            }
        }
    }

In that case the SDK fails to switch into "shared pool" mode:

public bool ContainsBatchProcessor(BaseProcessor<LogRecord> processor)

Workaround

    configure.AddProcessor(new FilteringBatchLogRecordProcessor(ShouldUpload, exporter));

    internal sealed class FilteringBatchLogRecordProcessor : BatchLogRecordExportProcessor
    {
        private readonly Func<LogRecord, bool> filter;

        public FilteringBatchLogRecordProcessor(Func<LogRecord, bool> filter, BaseExporter<LogRecord> exporter)
            : base(exporter)
        {
            this.filter = filter;
        }

        public override void OnEnd(LogRecord logRecord)
        {
            // Call the underlying processor
            // only if the Filter returns true.
            if (this.filter(logRecord))
            {
                base.OnEnd(logRecord);
            }
        }
    }
@CodeBlanch CodeBlanch added bug Something isn't working pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package logs Logging signal related labels Jan 24, 2024
@CodeBlanch CodeBlanch self-assigned this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logs Logging signal related pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant