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

Custom logging level to Application Insight does not work as expected #33980

Closed
yli02 opened this issue Jan 24, 2024 · 6 comments
Closed

Custom logging level to Application Insight does not work as expected #33980

yli02 opened this issue Jan 24, 2024 · 6 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-author-feedback Workflow: More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@yli02
Copy link

yli02 commented Jan 24, 2024

  • Package Name: azure-monitor-opentelemetry
  • Package Version: 1.2.0
  • Operating System: python:3.8.18-slim
  • Python Version: python 3.8.18

Describe the bug
The documentation at [1] in footnote 4 told that we could use the reference link to setup logging level to send to Application Insight. I have tried to set APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL="INFO" to environment variable, however, it still sends debug log to Application Insights, as the instrument logger is set with logging level DEBUG. I also tried to set OTEL_LOG_LEVEL to INFO, which also don't work, debug logs are still sent to Application Insights.

To Reproduce
Steps to reproduce the behavior:

  1. Create a logger from the standard python logging library with a name
  2. Set the logging level from 1st step created logger to DEBUG
  3. Use configure_azure_monitor function to bind to the logger created in 1st step
  4. Set the environment variables like described in the *Describe the bug section
  5. Logs send with debug method from 1st step created logger to be sent to Application Insights.

Expected behavior
Log level specified to send to Application Insights should be effective.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
The python:3.8.18-slim is a docker image.

[1] https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-add-modify?tabs=python%2Cpython-1%2Cpython-2%2Cpython-3%2Cpython-4%2Cpython-5%2Cpython-6%2Cpython-8%2Cpython-9%2Cpython-10%2Cpython-11%2Cpython-12%2Cpython-13%2Cpython-14%2Cpython-15#included-instrumentation-libraries
[2] https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration

@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 - ApplicationInsights needs-team-triage Workflow: This issue needs the team to triage. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 24, 2024
@kristapratico kristapratico added Monitor - Exporter Monitor OpenTelemetry Exporter and removed Monitor - ApplicationInsights needs-team-triage Workflow: This issue needs the team to triage. labels Jan 24, 2024
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jan 24, 2024
@kristapratico
Copy link
Member

@yli02 thanks for your issue, the library owners will take a look soon and respond.

@jeremydvoss
Copy link
Member

OTEL_LOG_LEVEL is not implemented yet by opentelemetry-python due to a spec dispute
APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL is an environment variable for the Java SDK not Python. (I will talk to our docs team to make this clearer)
Please see our README and configuration docs for more configuration options.

I think I understand your confusion, though. In opentelemetry-python, the OTel logging is built on native python logging which is hierarchical. Take the following example:

configure_azure_monitor()

logger1 = getLogger("foo1.bar")
logger1.setLevel(INFO)
logger1.debug("foo1.bar debug")
logger1.info("foo1.bar info")

logger2 = getLogger("foo2.bar")
logger2.setLevel(WARN)
logger2.debug("foo2.bar debug")
logger2.info("foo2.bar info")
logger2.warn("foo2.bar warn")

Because no logger_name was passed in, the root logger is instrumented. This means all logs are captured if they pass their respective logger's levels. So, foo1.bar info and foo2.bar warn are captured. If you wanting to limit captured logs to a specific module, you can specify logger_name:

configure_azure_monitor(logger_name="foo1")

logger1 = getLogger("foo1.bar")
logger1.setLevel(INFO)
logger1.debug("foo1.bar debug")
logger1.info("foo1.bar info")

logger2 = getLogger("foo2.bar")
logger2.setLevel(WARN)
logger2.debug("foo2.bar debug")
logger2.info("foo2.bar info")
logger2.warn("foo2.bar warn")

In this case, only foo1.bar info is captured. Let me know if this clears things up.

@yli02
Copy link
Author

yli02 commented Jan 25, 2024

@jeremydvoss thanks a lot for your explanations.

We actually configured the monitoring to be the 2nd case you mentioned. But I was thinking that during development time, I could set logger2.setLevel(DEBUG), but configure an env variable like OTEL_LOG_LEVEL to be INFO, so that I could still check the debugging logs from the stdout, but only get logs equal to or above INFO to be send to Application Insights. To me, this sounds what should have been supported based on the footnote 4 at [1], right? or I misinterpreted it? Thanks.

[1] https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-add-modify?tabs=python%2Cpython-1%2Cpython-2%2Cpython-3%2Cpython-4%2Cpython-5%2Cpython-6%2Cpython-8%2Cpython-9%2Cpython-10%2Cpython-11%2Cpython-12%2Cpython-13%2Cpython-14%2Cpython-15#included-instrumentation-libraries

@jeremydvoss
Copy link
Member

I am not sure I understand. The link here does not mention OTEL_LOG_LEVEL, which I explained does not currently do anything. Could you explain what your desired behavior is?

@xiangyan99 xiangyan99 added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Feb 8, 2024
@github-actions github-actions bot removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Feb 8, 2024
Copy link

github-actions bot commented Feb 8, 2024

Hi @yli02. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@yli02
Copy link
Author

yli02 commented Feb 13, 2024

@jeremydvoss sorry for the delay in replying. I think the example you have given should be fine for our use case, I will close this bug report.

@yli02 yli02 closed this as completed Feb 13, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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-author-feedback Workflow: More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

5 participants