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

Support logging level config of handler through configure_azure_monitor #36395

Open
yli02 opened this issue Jul 9, 2024 · 2 comments
Open

Support logging level config of handler through configure_azure_monitor #36395

yli02 opened this issue Jul 9, 2024 · 2 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor Monitor, Monitor Ingestion, Monitor Query 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

@yli02
Copy link

yli02 commented Jul 9, 2024

Is your feature request related to a problem? Please describe.
The current logging configuration in [1] does not support to set the logging level for handler in [2], and this prevents to separate the logging to Azure and local in different levels based on logger hierarchy. For example

import logging
from azure.monitor.opentelemetry import configure_azure_monitor

app_logger = logging.getLogger("App")
app_logger.setLevel(logging.ERROR)

app_local_logger = logging.getLogger("App.local")
app_local_logger.setLevel(logging.INFO)

configure_azure_monitor(connection_string="", logger_name="app_logger")

In the application, we would like to always use logger "app_logger_local" for different level of loggings to stdout and stderr, and relying on logging hierarchy to pass logs to "app_logger". And we only would like to use Azure AppInsights to collect log with level ERROR or higher.

But this design is so far not feasible, as there is no checking of parent logger level at [3], see also [4].

Describe the solution you'd like
It would be great if a new argument could be added to [1], like logging_level to setup the logging level of the handler in [2], so we could rely on the above example code to collect loggings in different levels at different destination.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
[1]

def configure_azure_monitor(**kwargs) -> None: # pylint: disable=C4758

[2]

handler = LoggingHandler(logger_provider=logger_provider)

[3] https://github.com/python/cpython/blob/15d48aea02099ffc5bdc5511cc53ced460cb31b9/Lib/logging/__init__.py#L1715

[4] python/cpython#75045 (comment)

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage 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 Jul 9, 2024
@xiangyan99 xiangyan99 removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jul 9, 2024
@github-actions github-actions bot added the needs-team-attention This issue needs attention from Azure service team or SDK team label Jul 9, 2024
@xiangyan99 xiangyan99 added Monitor Monitor, Monitor Ingestion, Monitor Query Service Attention This issue is responsible by Azure service team. and removed needs-team-attention This issue needs attention from Azure service team or SDK team labels Jul 9, 2024
@github-actions github-actions bot added the needs-team-attention This issue needs attention from Azure service team or SDK team label Jul 9, 2024
Copy link

github-actions bot commented Jul 9, 2024

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @gracewilcox @gulopesd @Haiying-MSFT @jairmyree @joshfree @KarishmaGhiya @KevinBlasko @kurtzeborn @nisha-bhatia @pvaneck @sarangan12 @scottaddie @srnagar @ToddKingMSFT.

@lzchen
Copy link
Member

lzchen commented Jul 10, 2024

@yli02

This scenario makes sense. A solution via environment variable in upstream OpenTelemetry Python would be able to enable this scenario and allow you to configure log level of the OpenTelemetry LoggingHandler. This however has not been implemented yet.

As a side note, you must also change your code to pass in the namespace of the parent logger you want to use, not the variable name of the logger.

...
app_logger = logging.getLogger("App")
configure_azure_monitor(connection_string="", logger_name="App")
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor Monitor, Monitor Ingestion, Monitor Query 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

4 participants