Skip to content

[QUERY] Azure.Monitor.OpenTelemetry.AspNetCore - How to write custom dimensions with ILogger? #47594

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

Open
Leonardo-Ferreira opened this issue Dec 17, 2024 · 5 comments
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 - Distro Monitor OpenTelemetry Distro needs-team-attention Workflow: 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 Workflow: This issue is responsible by Azure service team.

Comments

@Leonardo-Ferreira
Copy link

Library name and version

Azure.Monitor.OpenTelemetry.AspNetCore 1.3.0-beta.2

Query/Question

using Azure.Monitor.OpenTelemetry.AspNetCore as a "sink" and ILogger, how can I write a log with a custom dimension that will show for that log alone? I don't want the custom dimension to reflect for the all the logs/dependencies/metrics of a given request... just like the classical LogTelemetry.CustomDimensions.Add("specificDimensionA", "value A") ?

Environment

.net 9, latest version
other packages:
OpenTelemetry.Exporter.Console
OpenTelemetry.Extensions.Hosting
OpenTelemetry.Instrumentation.AspNetCore

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 17, 2024
@cidico
Copy link

cidico commented Dec 17, 2024

I've being trying to do this as well.
Let me know if you find a solution!

@jsquire jsquire added Service Attention Workflow: This issue is responsible by Azure service team. Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Monitor - Distro Monitor OpenTelemetry Distro and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Dec 18, 2024
Copy link

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

@AugustoNeves
Copy link

I would also like to know the answer to this question.

@gastonmuijtjens
Copy link

gastonmuijtjens commented Jan 7, 2025

Hi @Leonardo-Ferreira @cidico @AugustoNeves,

While perhaps not ideal, one possibility would be to wrap the log statement inside a logging scope that sets tags: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/logs/customizing-the-sdk/README.md#includescopes

See also this example: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/logs/customizing-the-sdk/Program.cs. You should set IncludeScopes to true to make this work.

According to the source code, the Azure Monitor Exporter exports those logging scopes to custom dimensions in Application Insights:

foreach (KeyValuePair<string, object?> scopeItem in scope)

@PraveenVerma17
Copy link

PraveenVerma17 commented Apr 13, 2025

@gastonmuijtjens
It's not ideal because it adds many other properties from different scopes. For example, in HTTP requests, it logs all HTTP scope tags in custom dimensions.

The worst part is that Azure.Monitor.OpenTelemetry.AspNetCore does not honor predefined tags. For instance, client.address, user.id, etc., all go to custom dimensions. I'm not sure if Azure.Monitor.OpenTelemetry.AspNetCore has any plans to provide an option to override predefined tags in middleware.

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 - Distro Monitor OpenTelemetry Distro needs-team-attention Workflow: 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 Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

6 participants