-
Notifications
You must be signed in to change notification settings - Fork 765
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
Pooled objects in attibutes (working with Microsoft.Extensions.ComplianceRedaction) #5276
Comments
You can use a OTEL Collector and OTLP Exporter to show the repro. You may use this example app - https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/examples/Console/TestOtlpExporter.cs#L16 The SDK's ILogger integration is expected to copy all attributes in the sync path itself, so if this is not working, it is likely a bug. But need to see a minimal repro to confirm. |
Here's a repro:
|
This is something to be reported to the owners of
Are you seeing this exception escaping or its caught by OTLPExporter and proceeds without crashing the app? https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/Shared/TagTransformer.cs#L63-L74 is the place where the exception is thrown (and caught correctly as well). I am guessing the issue is with the @CodeBlanch who fixed similar issue in the OTel SDK itself. |
I removed the bug tag. When I saw "pool", I initially assumed the LogRecord pooling in this repo, but since then, it is clear that you were referring to the pooling done inside JustInTimeRedactor. |
I'll try to report the issue on the other repo, but as you said at first glance it's ok to assume that after leaving Log in OpenTelemetryLogger the attributes are safe to collect as they should be "frozen" or projected to something safe. Like I do in my workaround.
I catch it because for debugging purpose I configured VS to catch any CLR exception. With regular settings, it indeed doesn't break. However, in such case I don't have the attribute flowing in my log pipeline. |
Hey @cijothomas, thanks for looking into this. As explained by @geeknoid in this comment we believe that the issue lies in OTel here as it shouldn't try to call ToString on object references that it keeps around as it cannot be guaranteed that doing so is safe (objects might be disposed, nulled out, or simply in a state that is no longer valid). |
As suggested here, OTel SDK is expected to read everything off the state in the sync path itself. If it is not working, then it is a bug in OTel .NET sdk. Would you make a minimal repro app to confirm if this is indeed an issue in OTel .NET? |
Unless I'm missing something, I don't see how the BufferLogAttributes() method can prevent the issue. I've read the associated issue mentioned in the method comment but we are not in the same case. Here the difference is that it is the Value property of Something like this would prevent the issue instead:
|
I don't believe |
Thanks! |
My employer has some logging code that creates logging-specific wrappers for application-specific objects. These objects have limited lifetime and are not safe to access across threads. The wrappers exist to provide ToString() for logs but skip all string formatting if ToString() is not called. These wrappers do not implement IDisposable, because they just reference the application-specific objects rather than own those; and they do not implement Microsoft.Extensions.ObjectPool.IResettable, because they antedate .NET 8.0. |
Whole lot to unpack here! I'll do my best 🤣 High level I do agree OTel should fully capture the log data. Probably mistakes were made along the way in our design/API but we are where are and now we have to do something here which will be non-breaking. I want to start with the proposed workaround. if (value is IDisposable || value is IResettable)
{
value = value.ToString();
}
What if we just did this? if (value is IDisposable)
{
value = value.ToString();
} Perhaps we could do this. I have some concerns with it being a breaking change. But what would this really achieve? If we look at The whole point of that thing is to implement If we force a Let's say we went ahead and made this change anyway. How would that deploy? Here is an idea for a workaround we could do in extensions: https://github.com/dotnet/extensions/compare/main...CodeBlanch:redaction-pool-tweak?expand=1 Right now Let's say we start there to stop the bleeding. That workaround will fix the redacted data being missing and preserve the Could we do more? I think it would be great if OTel allowed users/libraries/extensions to participate in its buffering/pooling. Very tricky to do. I took at stab at making it work using
The idea is OTel would detect values which are |
Hi I just ran into this issue using Creating a processor I see the values are actually there. Do you suggest any workaround or any ETA when this will be fixed? Thanks in advance Edit: I got around this issue with a workaround, by using a Processor and intercepting the redacted attribute (we only have a handful), removing it from Attributes and re-adding it as a ToString() value. Hopefully the SDK can natively support this soon :) |
Bug Report
Currently working on net8.0
Symptom
When using redaction and batch otlp protocol, redacted values are not stored.
What is the expected behavior?
Expected: the redacted value
What is the actual behavior?
Actual: no value store (the key is even not sent)
Reproduce
Little hard to reproduce as it needs a sink to send logs to. However, I've found the issue: when using redaction, the redacted values are stored as JustInTimeRedactor (see) to avoid allocations. When using batch exporter, as it might take time to send telemetry and as JustInTimeRedactor is pooled, the value can either not be available or reused by something else.
Additional Context
I've found a kind of workaround which is adding a Processor which "freezes" pooled values.
The text was updated successfully, but these errors were encountered: