Kanerix
Kanerix

Reputation: 133

Random and duplicate logging for Azure Functions and OpenTelemetry python

Log spamming

I recently added OpenTelemetry to my azure function. The reason was because i wanted logging with custom dimensions. But when i added this, my app started spamming random logs around every 3 seconds. These logs can be seen on the image below.

Random logs described

Duplicate logging

Whenever i log something, the entries show up twice. It looks like 1 of the log entries comes from the Azure Function itself and 1 entry from the log exporter in the python code.

I found that you could use the OTEL_LOGS_EXPORTER environment variable to disable the OpenTelemetry logger which removes 1 of the duplicate entries, but this is the entry with the custom dimensions i wanted. I was looking for something to disable the native logger for the azure function, but couldn't find anything.

My research

I do not want these logs to show up every 3 seconds since they are very annoying and not useful.

Also i would love to only see the log entry i want with the custom dimensions.

I am not that familiar with OpenTelemetry and i also have limited knowledge when it comes to Azure Functions.

I have tho looked through tons of documentation and have have not found anything useful yet.

My Code

import azure.functions as func 
from azure.monitor.opentelemetry import configure_azure_monitor

import cve, ddc2, ddc3

configure_azure_monitor() 

app = func.FunctionApp() 

app.register_blueprint(cve.bp) 
app.register_blueprint(ddc2.bp)
app.register_blueprint(ddc3.bp)

(All the 3 functions are timer triggers)

Upvotes: 1

Views: 359

Answers (1)

Ikhtesam Afrin
Ikhtesam Afrin

Reputation: 6497

I have referred to this github issue and made below changes to your code to get rid of unwanted logs.

import azure.functions as func 
from azure.monitor.opentelemetry import configure_azure_monitor
import cve, ddc2, ddc3
import logging

configure_azure_monitor(connection_string="InstrumentationKey=2b405*****7b285;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/;ApplicationId=9e0********909") 
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.WARNING)
logging.getLogger("azure.monitor.opentelemetry.exporter.export").setLevel(logging.WARNING)

app = func.FunctionApp() 

app.register_blueprint(cve.bp) 
app.register_blueprint(ddc2.bp)
app.register_blueprint(ddc3.bp)

Now, I am able to see that the unwanted logs are not showing and only function related logs are being reflected in Application insight.

enter image description here

Upvotes: 0

Related Questions