i want to track the use of certain ids in ms azure monitor (application insights). I'm doing this at the moment with the following code excerpt. The problem is that if, for example, six calls are made in quick succession, the first call is tracked six times. the second is tracked five times. the third four times and so on. (look at the picture below) How can I resolve that all ids are only tracked when they are explicitly called?
from azure_monitor import AzureMonitorMetricsExporter
from opentelemetry import metrics
from opentelemetry.sdk.metrics import Counter, MeterProvider
from opentelemetry.sdk.metrics.export.controller import PushController
metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
exporter = AzureMonitorMetricsExporter(
connection_string='InstrumentationKey=<my-key>'
)
controller = PushController(meter, exporter, 0)
def add_question(question_id):
requests_counter = meter.create_metric(
name=question_id,
description="question used",
unit="1",
value_type=int,
metric_type=Counter,
)
labels = {"type": "question"}
requests_counter.add(1, labels)
controller.shutdown()
print(str(datetime.now()) + " - Done recording metric: question")
print(question_id)