Closed jos-h closed 2 weeks ago
Thanks for the feedback, we’ll investigate asap.
@lzchen Any update on the above?
@jos-h
Taking a look.
@jos-h
I am not able to replicate your behavior. Could you try doing the following:
enable_live_metrics=True
"opentelemetry": {
"class": "opentelemetry.sdk._logs.handler",
"formatter": "verbose",
},
to be
"opentelemetry": {
"class": "opentelemetry.sdk._logs.LoggingHandler",
"formatter": "verbose",
},
logging.config.dictConfig(LOGGING)
@jos-h
I am not able to replicate your behavior. Could you try doing the following:
enable_live_metrics=True
- Change
"opentelemetry": { "class": "opentelemetry.sdk._logs.handler", "formatter": "verbose", },
to be
"opentelemetry": { "class": "opentelemetry.sdk._logs.LoggingHandler", "formatter": "verbose", },
- Remove
logging.config.dictConfig(LOGGING)
@lzchen, I modified the code and tried it again based on your steps. But still, logs are getting logged twice. Would you let me know what steps you followed while trying to replicate the issue? Do we need to make some updations in the Azure Portal like in Diagnostic Settings etc?
@jos-h
Apologies can you set enable_live_metrics=False
.
Are you also running the Django app standalone? With python manage.py runserver
?
In your views.py
, how and when are you instantiating the logger
object with name app_logger
?
Below is the code I have that only produces one trace
telemetry entry:
manage.py
from azure.monitor.opentelemetry import configure_azure_monitor
...
def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample.settings")
configure_azure_monitor(
logger_name="app_logger",
)
...
views.py
...
logger = logging.getLogger("app_logger")
# Requests sent to the django application will be automatically captured
def index(request):
logger.info("index page")
return HttpResponse("Hello, world.")
...
settings.py
...
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "%(asctime)s : %(name)s : %(levelname)s - %(message)s",
"datefmt": "%Y/%b/%d %H:%M:%S",
},
"simple": {"format": "%(levelname)s %(message)s"},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "verbose",
},
"opentelemetry": {
"class": "opentelemetry.sdk._logs.LoggingHandler",
"formatter": "verbose",
},
},
"loggers": {
"azure": {
"level": "WARNING",
"handlers": [],
"propagate": False,
},
"azure.core.pipeline.policies.http_logging_policy": {
"level": "CRITICAL",
"handlers": [],
"propagate": False,
},
"azure.monitor.opentelemetry.exporter.export._base": {
"level": "WARNING",
"handlers": [],
"propagate": False,
},
"app_logger": {
"level": "INFO",
"handlers": ["opentelemetry"],
"propagate": False,
},
},
}
...
Hi @jos-h. 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.
@jos-h
- Apologies can you set
enable_live_metrics=False
.- Are you also running the Django app standalone? With
python manage.py runserver
?- In your
views.py
, how and when are you instantiating thelogger
object with nameapp_logger
?Below is the code I have that only produces one
trace
telemetry entry:manage.py
from azure.monitor.opentelemetry import configure_azure_monitor ... def main(): """Run administrative tasks.""" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample.settings") configure_azure_monitor( logger_name="app_logger", ) ...
views.py
... logger = logging.getLogger("app_logger") # Requests sent to the django application will be automatically captured def index(request): logger.info("index page") return HttpResponse("Hello, world.") ...
settings.py
... LOGGING = { "version": 1, "disable_existing_loggers": False, "formatters": { "verbose": { "format": "%(asctime)s : %(name)s : %(levelname)s - %(message)s", "datefmt": "%Y/%b/%d %H:%M:%S", }, "simple": {"format": "%(levelname)s %(message)s"}, }, "handlers": { "console": { "class": "logging.StreamHandler", "formatter": "verbose", }, "opentelemetry": { "class": "opentelemetry.sdk._logs.LoggingHandler", "formatter": "verbose", }, }, "loggers": { "azure": { "level": "WARNING", "handlers": [], "propagate": False, }, "azure.core.pipeline.policies.http_logging_policy": { "level": "CRITICAL", "handlers": [], "propagate": False, }, "azure.monitor.opentelemetry.exporter.export._base": { "level": "WARNING", "handlers": [], "propagate": False, }, "app_logger": { "level": "INFO", "handlers": ["opentelemetry"], "propagate": False, }, }, } ...
@lzchen Thank you for the quick update. Below are my answers to your queries
enable_live_metrics=False
python manage.py runserver
. I tried sending logs to Application Insights with your code changes, but I still see duplicate logs. Is it related to some configuration issue while setting up the Application Insights? In the Diagnostic settings, send logs to the Log Analytics Workspace checkbox is enabled. Will it cause any issues?
@jos-h
In the Diagnostic settings, send logs to the Log Analytics Workspace checkbox is enabled. Will it cause any issues?
In my testing, my appinsights resource has no diagnostic settings defined.
Perhaps uncheck this and try this out? Otherwise, could you try this with a fresh Appinsights resource and note down any extraneous configuration settings you use?
@jos-h
In the Diagnostic settings, send logs to the Log Analytics Workspace checkbox is enabled. Will it cause any issues?
In my testing, my appinsights resource has no diagnostic settings defined.
Perhaps uncheck this and try this out? Otherwise, could you try this with a fresh Appinsights resource and note down any extraneous configuration settings you use?
@lzchen Sure I will try and get back to you
Hi @jos-h. 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.
Hi @jos-h, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
Requirements
Issue
configure_azure_monitor(connection_string=os.environ.get("APPLICATIONINSIGHTS_CONNECTION_STRING"), enable_live_metrics=True, logger_name="app_logger")
logging.config.dictConfig(LOGGING)`
I am following the below links to configure the Azure monitor with Opentelemetery
Output: ` Testing logs
Testing logs ` NOTE:- I can't share the exact output log due to compliance policy. Sorry for the inconvenience