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

Provide a hook to call OpenTelemetry.SuppressInstrumentationScope.Begin #150

Merged
merged 4 commits into from
Aug 19, 2024

Conversation

nblumhardt
Copy link
Member

Usage:

Log.Logger = new LoggerConfiguration()
    .WriteTo.OpenTelemetry(options =>
    {
        options.OnBeginSuppressInstrumentation =
            OpenTelemetry.SuppressInstrumentationScope.Begin;
        // ...

Fixes #41

@badgeratu
Copy link

Thanks for turning this around so quickly Nick. I can confirm it's fixed the issue for me! One thing though - the signature of the Begin() method is:

 IDisposable OpenTelemetry.SuppressInstrumentationScope.Begin(bool value = true);

Due to the optional parameter it doesn't match the type Func<IDisposable> expected by the new OnBeginSuppressInstrumentation property, so I was getting compiler errors using your example implementation. I had to instead use the following:

Log.Logger = new LoggerConfiguration()
    .WriteTo.OpenTelemetry(options =>
    {
        options.OnBeginSuppressInstrumentation =
           () => OpenTelemetry.SuppressInstrumentationScope.Begin();
        // ...

@nblumhardt
Copy link
Member Author

Thanks for checking this out @badgeratu 🙇

I think, since OpenTelemetry suppression will be the vast majority of use cases for this API now and in the future, I might just change the expected signature to match. I'll push an update :-)

@nblumhardt nblumhardt merged commit 02ec0a3 into serilog:dev Aug 19, 2024
1 check passed
@nblumhardt nblumhardt mentioned this pull request Aug 20, 2024
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.

Consider using OpenTelemetry.SupressInstrumentationScope to cleanup tracing
2 participants