From 99b180839f0d86d39a24f68abae21a2dc24b5a76 Mon Sep 17 00:00:00 2001 From: Kausik Date: Tue, 17 May 2022 13:29:41 -0700 Subject: [PATCH 1/2] Added new metrics to match java sdk metrics parity --- .../flask/setup_metrics.py | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/integration-test-apps/manual-instrumentation/flask/setup_metrics.py b/integration-test-apps/manual-instrumentation/flask/setup_metrics.py index 6471724a..b056f2cd 100644 --- a/integration-test-apps/manual-instrumentation/flask/setup_metrics.py +++ b/integration-test-apps/manual-instrumentation/flask/setup_metrics.py @@ -21,23 +21,46 @@ # Setup Metric Components -apiBytesSentMetricName = "apiBytesSent" latencyMetricName = "latency" +apiBytesSentMetricName = "apiBytesSent" +totalApiBytesSentMetricName = "totalApiBytesSent" +lastLatencyMetricName = "lastLatency" +queueSizeChangeMetricName = "queueSizeChange" +actualQueueSizeMetricName = "actualQueueSize" if "INSTANCE_ID" in os.environ: instanceId = os.environ["INSTANCE_ID"] if not instanceId.strip() == "": latencyMetricName += "_" + instanceId apiBytesSentMetricName += "_" + instanceId + totalApiBytesSentMetricName += "_" + instanceId + lastLatencyMetricName += "_" + instanceId + queueSizeChangeMetricName += "_" + instanceId + actualQueueSizeMetricName += "_" + instanceId apiBytesSentCounter = meter.create_counter( apiBytesSentMetricName, "API request load sent in bytes", "one", int ) -apiLatencyRecorder = meter.create_valuerecorder( +apiLatencyRecorder = meter.create_histogram( latencyMetricName, "API latency time", "ms", int ) +apiqueueSizeChangeMetric = meter.create_up_down_counter( + queueSizeChangeMetricName, "Queue Size change", "one", int +) + +apitotalApiBytesSentMetric = meter.create_observable_gauge( + totalApiBytesSentMetricName, "Total API request load sent in bytes", "one", int +) + +apilastLatencyMetric = meter.create_observable_gauge( + lastLatencyMetricName, "The last API latency observed at collection interval", "ms", int +) + +apiactualQueueSizeMetric = meter.create_observable_gauge( + actualQueueSizeMetricName, "The actual queue size observed at collection interval", "one", int +) # Start Metric Pipeline # Exporter to export metrics to the console From ee7c2f71bf516afd28a4c438fea97c5b27705d73 Mon Sep 17 00:00:00 2001 From: Kausik Date: Wed, 18 May 2022 09:09:55 -0700 Subject: [PATCH 2/2] added in after_request_func to generate metrics data --- .../flask/create_flask_app.py | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/integration-test-apps/manual-instrumentation/flask/create_flask_app.py b/integration-test-apps/manual-instrumentation/flask/create_flask_app.py index 2a29250f..f47c64f9 100644 --- a/integration-test-apps/manual-instrumentation/flask/create_flask_app.py +++ b/integration-test-apps/manual-instrumentation/flask/create_flask_app.py @@ -22,7 +22,7 @@ # NOTE: (NathanielRN) Metrics is on hold. # See https://github.com/open-telemetry/opentelemetry-python/issues/1835 -# from setup_metrics import apiBytesSentCounter, apiLatencyRecorder +from setup_metrics import apiBytesSentCounter, apiLatencyRecorder, apiqueueSizeChangeMetric, apitotalApiBytesSentMetric, apilastLatencyMetric # Constants @@ -59,22 +59,22 @@ def mimicPayloadSize(): @app.after_request def after_request_func(response): - # if request.path == "/outgoing-http-call": - # apiBytesSentCounter.add( - # response.calculate_content_length() + mimicPayloadSize(), - # { - # DIMENSION_API_NAME: request.path, - # DIMENSION_STATUS_CODE: response.status_code, - # }, - # ) - - # apiLatencyRecorder.record( - # int(time.time() * 1_000) - session[REQUEST_START_TIME], - # { - # DIMENSION_API_NAME: request.path, - # DIMENSION_STATUS_CODE: response.status_code, - # }, - # ) + if request.path == "/outgoing-http-call": + apiBytesSentCounter.add( + response.calculate_content_length() + mimicPayloadSize(), + { + DIMENSION_API_NAME: request.path, + DIMENSION_STATUS_CODE: response.status_code, + }, + ) + + apiLatencyRecorder.record( + int(time.time() * 1_000) - session[REQUEST_START_TIME], + { + DIMENSION_API_NAME: request.path, + DIMENSION_STATUS_CODE: response.status_code, + }, + ) return response