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

[QUERY] How to use a custom log processor #43623

Closed
AlexGlassman opened this issue Apr 24, 2024 · 3 comments
Closed

[QUERY] How to use a custom log processor #43623

AlexGlassman opened this issue Apr 24, 2024 · 3 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Exporter Monitor OpenTelemetry Exporter needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.

Comments

@AlexGlassman
Copy link

Library name and version

Azure.Monitor.OpenTelemetry.AspNetCore v1.1

Query/Question

I have implemented a custom log processor to obfuscate sensitive log data. As per the OpenTelemetry docs here, it looks something like this:

public class OTelSensitiveDataEnricher : BaseProcessor<LogRecord>
{
    private readonly IEnumerable<ISensitiveDataFilter> _sensitiveDataFilters;

    public OTelSensitiveDataEnricher(IEnumerable<ISensitiveDataFilter> sensitiveDataFilters)
    {
        _sensitiveDataFilters = sensitiveDataFilters;
    }

    public override void OnEnd(LogRecord logRecord)
    { 
       //use _sensitiveDataFilters to obfuscate data in logRecord 
    }
}

My issue is understanding how I can register this processor in my Program/StartUp.cs in conjunction with the Azure Monitor Distro, as the UseAzureMonitor() extension method handles log configuration behind the scenes, and it doesn't seem like there is a way to add a Log Processor in the same way as you can add a Trace Processor or Metrics Processor as shown in the docs.

Any help would be greatly appreciated. Thanks!

Environment

.NET 8

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Exporter Monitor OpenTelemetry Exporter needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team. labels Apr 24, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas @rajkumar-rangaraj @reyang @TimothyMothra @vishweshbankwar.

@TimothyMothra TimothyMothra self-assigned this Apr 24, 2024
@TimothyMothra
Copy link
Contributor

Hi @AlexGlassman, I've got some options for you.
Note that for either option you should add your Processor BEFORE calling UseAzureMonitor to place your custom Processor earlier in the chain.

Option 1. Call AddLogging and AddOpenTelemetry

builder.Services.AddLogging(logging =>
{
    logging.AddOpenTelemetry(builderOptions =>
    {
        builderOptions.AddProcessor(new MyCustomProcessor());
    });
});

builder.Services.AddOpenTelemetry().UseAzureMonitor();

Option 2. Experimental Api: ConfigureOpenTelemetryLoggerProvider

As of today, this API is currently only available in beta versions of OpenTelemetry.

You can watch the OpenTelemetry dotnet repo to see when this API is stablized: open-telemetry/opentelemetry-dotnet#5442

builder.Services.ConfigureOpenTelemetryLoggerProvider(builder => builder.AddProcessor<MyCustomProcessor>());
builder.Services.AddOpenTelemetry().UseAzureMonitor();

@AlexGlassman
Copy link
Author

Thanks @TimothyMothra! Option 1 worked a treat; I did initially think about this approach but erroneously assumed calling UseAzureMonitor() would override whatever custom processors were configured before it. This is a production workload so went with the more stable option, but will keep my eyes peeled for ConfigureOpenTelemetryLoggerProvider coming out of beta.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Exporter Monitor OpenTelemetry Exporter needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants