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

ForEachScope not working before buffering in reused LogRecord #3727

Closed
mbubnich-bunnings opened this issue Oct 5, 2022 · 1 comment · Fixed by #3731
Closed

ForEachScope not working before buffering in reused LogRecord #3727

mbubnich-bunnings opened this issue Oct 5, 2022 · 1 comment · Fixed by #3731
Assignees
Labels
bug Something isn't working logs Logging signal related

Comments

@mbubnich-bunnings
Copy link

Bug Report

List of all OpenTelemetry NuGet
packages
and version that you are
using (e.g. OpenTelemetry 1.0.2):

OpenTelemetry.Api 1.4.0-beta.1
OpenTelemetry.Exporter.Console 1.4.0-beta.1
OpenTelemetry.Extensions.Hosting 1.0.0-rc9.7

Runtime version (e.g. net462, net48, netcoreapp3.1, net6.0 etc. You can
find this information from the *.csproj file):

net6.0

Symptom

A call to LogRecord.ForEachScope on a reused LogRecord that had previously called Buffer dose not do anything prior to a call to Buffer on this usage.

This prevents implementation of a filter processor based on a scope value when using a batch exporter.

What is the expected behavior?

LogRecord.ForEachScope will enumerate scopes regardless of of buffered state.

What is the actual behavior?

LogRecord.ForEachScope will only enumerate scopes if the log record has not been reused before scopes are buffered.

Reproduce

https://github.com/mbubnich-bunnings/ForEachScopeProblem

Additional Context

/// <summary>
/// Executes callback for each currently active scope objects in order
/// of creation. All callbacks are guaranteed to be called inline from
/// this method.
/// </summary>
/// <typeparam name="TState">State.</typeparam>
/// <param name="callback">The callback to be executed for every scope object.</param>
/// <param name="state">The state object to be passed into the callback.</param>
public void ForEachScope<TState>(Action<LogRecordScope, TState> callback, TState state)
{
    Guard.ThrowIfNull(callback);

    var forEachScopeState = new ScopeForEachState<TState>(callback, state);

    if (this.BufferedScopes != null)
    {
        foreach (object? scope in this.BufferedScopes)
        {
            ScopeForEachState<TState>.ForEachScope(scope, forEachScopeState);
        }
    }
    else if (this.ScopeProvider != null)
    {
        this.ScopeProvider.ForEachScope(ScopeForEachState<TState>.ForEachScope, forEachScopeState);
    }
}

"if (this.BufferedScopes != null)" is not null on reuse of the LogRecord and there for will enumerate an empty list.

@mbubnich-bunnings mbubnich-bunnings added the bug Something isn't working label Oct 5, 2022
@reyang
Copy link
Member

reyang commented Oct 5, 2022

@CodeBlanch FYI

@CodeBlanch CodeBlanch self-assigned this Oct 5, 2022
@CodeBlanch CodeBlanch added the logs Logging signal related label Oct 5, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants