1

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)

azure-monitor chart

krishg
  • 5,935
  • 2
  • 12
  • 19
kenoc1
  • 52
  • 5
  • 1
    'OpenTelemetry Azure Monitor' is currently in beta. You can report this issue [here](https://github.com/microsoft/opentelemetry-azure-monitor-python/issues). – krishg Nov 19 '20 at 12:50
  • Thanks @krishg, i created an issue. Should i now delete this question or wait? [github issue](https://github.com/microsoft/opentelemetry-azure-monitor-python/issues/133) – kenoc1 Nov 20 '20 at 16:01
  • I think let's leave it here. Once we get update from the issue, let's put the answer here too. – krishg Nov 20 '20 at 16:01

1 Answers1

0

My problem was solved by a comment on my github bug report. The only change to be made is to add statefull=False to the MeterProvider like this:

metrics.set_meter_provider(MeterProvider(stateful=False))

kenoc1
  • 52
  • 5