[Python] Writing to application insights from a Phyton Azure Function App

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to add logs with custom dimensions to the trace table in application insights. I have code below working but it writes to the dependency table. Any pointers how to write to traces and metrics?

    import azure.functions as cho
    from azure.monitor.opentelemetry import configure_azure_monitor
    from opentelemetry import trace

    tt = cho.FunctionApp(http_auth_level=cho.AuthLevel.ANONYMOUS)

    @tt.route(route="http_trigger")
    def http_trigger(req: cho.HttpRequest) -> cho.HttpResponse:
    configure_azure_monitor(connection_string="ai conn str")
    ri_ch = trace.get_tracer(__name__)
    with ri_ch.start_as_current_span("This is a Log") as val:
    val.set_attribute("who", "rithwik")
    print("Hello Rithwik Bojja, the logs are Logged")
    return cho.HttpResponse("This HTTP triggered function executed successfully.",status_code=200)

    Continue reading...

Compartilhe esta Página