From 773be29a82cb6560e654801362d8e9b3999e92a9 Mon Sep 17 00:00:00 2001 From: Tammy Baylis Date: Tue, 17 Oct 2023 14:51:01 -0700 Subject: [PATCH] Add force flush of metrics --- solarwinds_apm/otlp_metrics_processor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/solarwinds_apm/otlp_metrics_processor.py b/solarwinds_apm/otlp_metrics_processor.py index a22a902f..3a9f5a22 100644 --- a/solarwinds_apm/otlp_metrics_processor.py +++ b/solarwinds_apm/otlp_metrics_processor.py @@ -8,6 +8,7 @@ import random from typing import TYPE_CHECKING, Any, Tuple +from opentelemetry.metrics import get_meter_provider from opentelemetry.sdk.trace import SpanProcessor from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import SpanKind, StatusCode @@ -99,6 +100,10 @@ def on_end(self, span: "ReadableSpan") -> None: # for SW-style trace export. This processor is for OTLP-style. # TODO: Cache txn_name for OTLP span export? + # Force flush metrics after every entry span via flush of all meters + # including PeriodicExportingMetricReader + get_meter_provider().force_flush() + # TODO If needed for both inbound and otlp metrics, refactor def is_span_http(self, span: "ReadableSpan") -> bool: """This span from inbound HTTP request if from a SERVER by some http.method"""