-
Notifications
You must be signed in to change notification settings - Fork 660
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
Logging AutoInstrumentation does not support capturing INFO logs #3473
Comments
I think this could be resolved by setting the log level here based on an env variable, but I'm not totally sure: opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py Line 250 in 5986c25
I am not clear on why the already instrumented error crops up. |
Basic sample usage even results in the same error as well: ` from azure.monitor.opentelemetry import configure_azure_monitor configure_azure_monitor( logger = getLogger(name) INFO does not show. |
any updates here? |
According to Python doc of handler = LoggingHandler(level=logging.NOTSET, logger_provider=provider)
logging.getLogger().addHandler(handler) These lines attach a handler to the root which makes |
Are you sure, @kuza55 ? I tried it out locally but it had no effect for me. This is definitely an error to be addressed, as this makes auto instrumentation in combination with logs kind of useless :( BR |
If anyone has a suggestion to resolve this issue, I will create a pull request to get changes working |
I poked at this for a second and you're right, changing the code there didn't help. I had some partial success with other approaches: Adding Setting force=True on this line caused a formatted log line to be printed, but not connected to OTLP: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/37aba928d45713842941c7efc992726a79ea7d8a/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py#L147C13-L147C32 |
Ok @kuza55 I guess this is not to be considered as a bug, but more likely to be intended behavior. The reason is that The thing to keep in mind is that in fact all loggers (e.g. the ones you create by using That means as long as the loglevel is not configured for specific loggers or the root logger, only warnings and errors will be handled as expected.
Because that makes it possible to explicitly define which log messages should transmitted to which destination (e.g. printing debugs in the console, while pushing only errors to a persistent log file).
That's open for discussion, but I think the reason is to ensure that using the automatic instrumentation won't mess up specific configuration for logging in a users application. Meaning that you still have full control which log levels to use in every situation, but ensure that log messages get transmitted to otel whenever possible.
There is an Environment setting that seems to control the loglevel (see here - OTEL_PYTHON_LOG_LEVEL) but it seems that it works only conditionally (see here. That means, that imho you need to specify at least three ENV variables, to adjust your application log level as expected and start with log exporting
Would be nice if some maintainers here can put light in the dark, and help us understanding better what is exactly going on. Edit: Probably the error is here, but I'm not sure what the side effect of using force=True is logging.basicConfig(format=log_format, level=log_level) # consider adding force=True here Edit2
|
The pull request that addresses - indirectly - this issue , and would resolve it is already there (see here |
Thanks so much for looking into this and apologize for the delayed response.
This is correct, we want to be as non-intrusive as possible to the configuration settings of the user's application.
This seems to be the case today in terms of being able to configure log format and log level. The reason there is such an extensive amount of configuration needed is we do not want to have default behavior override any of the user's configuration without their knowledge (or even worse, in the cases in which they cannot change the config). This means the logging instrumentation is indeed behaving as it was intended to as you have outlined above. Everything else follows the standard Python logging library practices for handlers and loggers. With that being said, maybe there is something that can be done on the AUTOINSTRUMENTATION side of things. We already allow configuration of other OpenTelemetry components (mostly with env vars). Perhaps the better change would be to allow more robust and flexible configuration of the automatically instantiated LoggingHandler that is initialized during auto-instrumentation. Another thing to note is that autoinstrumentation with the LoggingHandler does not need the logging instrumentation, but perhaps we can share the same env var configurations. I also see that you have a pr open. What specifically does this pr solve? Does it address the original issue at hand? |
@lzchen The probably best description what is not working at the moment ist: open-telemetry/opentelemetry-python-contrib#2346 Feel free to get back to me with further questions |
If your pr is simply to enhance the logging instrumentation, I am fine with it. In the future we may want to enhance autoinstrumentation as well to allow for configuration of the root logger for users that are NOT using the logging instrumentation. Not sure if we want to use the same env vars but we may have to deal with potential conflicts in the future. Created a tracking issue: #4034 |
Describe your environment
Python 3.10.12
Steps to reproduce
Using the code here, but with a logging.info rather than logging.warning: https://github.com/kuza55/pants_debug_otel/blob/main/src/no_configuration.py
I would expect setting OTEL_PYTHON_LOG_LEVEL=INFO to let me see info logs
What is the expected behavior?
I would expect to use the OTEL_PYTHON_LOG_LEVEL env variable mentioned in the docs to let me see info logs.
What is the actual behavior?
Environment variable has no impact
Additional context
Calling
LoggingInstrumentor().instrument(set_logging_format=True, log_level="INFO")
can resolve this, but is not compatible with auto-instrumentation, even when the auto-instrumentation env variable is set to false:The text was updated successfully, but these errors were encountered: