Giter Club home page Giter Club logo

Comments (8)

macieyng avatar macieyng commented on May 27, 2024 3

Do this and it should suppress those verbose logs.

configure_azure_monitor(connection_string=os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"])
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.WARNING)
logging.getLogger("azure.monitor.opentelemetry.exporter.export").setLevel(logging.WARNING)

from applicationinsights-python.

WaterKnight1998 avatar WaterKnight1998 commented on May 27, 2024

I have seen that those logs come from:


Request URL: 'https://westeurope-5.in.applicationinsights.azure.com//v2.1/track'
Request method: 'POST'
Request headers:
'Content-Type': 'application/json'
'Content-Length': '12891'
'Accept': 'application/json'
'User-Agent': 'azsdk-python-azuremonitorclient/unknown Python/3.9.17 (Linux-5.15.116.1-1.cm2-x86_64-with-glibc2.31)'
A body is sent with the request

sdkVersion
py3.9.17:otel1.20.0:ext1.0.0b17

Same as the explicit log that I do.

from applicationinsights-python.

WaterKnight1998 avatar WaterKnight1998 commented on May 27, 2024

I have tried raising logs to:

logging.basicConfig(level=logging.WARNING)

But I still see them

from applicationinsights-python.

WaterKnight1998 avatar WaterKnight1998 commented on May 27, 2024

Fixed with following code:

from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry import trace
import logging

logging.getLogger().handlers = []
configure_azure_monitor(connection_string=os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"])
logging.getLogger().setLevel(logging.WARNING)

tracer = trace.get_tracer(__name__)

app = fastapi.FastAPI()

@app.get("/x")
async def x():
   with tracer.start_as_current_span("aaaaa"):
      logging.warning("a",extras={"b":1})

def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
    return func.AsgiMiddleware(app).handle(req, context)

from applicationinsights-python.

WaterKnight1998 avatar WaterKnight1998 commented on May 27, 2024

This helped, thank you very much @macieyng . The only thing that I don't understand is why disabling the automatic instrumentations and excluding urls didn't help

from applicationinsights-python.

macieyng avatar macieyng commented on May 27, 2024

It didn't work because Azure SDK is instrumenting itself while suppressing any other instrumentation. Read this comment: Azure/azure-sdk-for-python#31292 (comment)

from applicationinsights-python.

lzchen avatar lzchen commented on May 27, 2024

@WaterKnight1998

These additional logs are appearing in the "traces" table in your Application Insights resource correct? We have recently implemented a feature to define the specific logger that you want to collect traces telemetry. This should allow you to define the logger to your application logger instead of the default which is the root logger. This is why you are seeing logs collected from the SDK itself. This feature should be available soon in the next release.

from applicationinsights-python.

jeremydvoss avatar jeremydvoss commented on May 27, 2024

Migrating to Azure sdk: Azure/azure-sdk-for-python#32503

from applicationinsights-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.