[Python] Applications insights in an azure function app - metrics and custom dimensions missing

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have some trouble adding logs from an azure function app to application insigths. I am using this code:

    import azure.functions as func
    import datetime
    import logging
    import requests
    from settings import settings
    from services.exchangerate_service import ExchangeRateService

    from azure.identity import DefaultAzureCredential
    from azure.monitor.opentelemetry import configure_azure_monitor
    from opentelemetry import metrics

    credential = DefaultAzureCredential()

    configure_azure_monitor(
    connection_string="InstrumentationKey=xx-xx-xx-xx-xx;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=xx-xx-xx-xx-xx",
    credential=credential
    )

    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)

    app = func.FunctionApp()
    @app.timer_trigger(schedule=settings.IBAN_CRON, arg_name="myTimer", run_on_startup=True,
    use_monitor=False)
    def timer_trigger(myTimer: func.TimerRequest) -> None:

    if myTimer.past_due:
    logging.info('The timer is past du3e!')

    logger.info("Segato5", extra={"custom_dimension": "Kam_value","test1": "val1"})

    meter = metrics.get_meter_provider().get_meter(__name__)
    counter = meter.create_counter("segato2")
    counter.add(8)


    I get traces but not custom dimesions and no metrics: [​IMG]

    [​IMG]

    Continue reading...

Compartilhe esta Página