From 49e196441bbdc113151c74baf3755445d66e9326 Mon Sep 17 00:00:00 2001 From: Tammy Baylis Date: Wed, 18 Oct 2023 15:50:00 -0700 Subject: [PATCH] otlpmetricsprocessor uses config service_name --- solarwinds_apm/configurator.py | 6 +++--- solarwinds_apm/otlp_metrics_processor.py | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/solarwinds_apm/configurator.py b/solarwinds_apm/configurator.py index b94d142e..32af9cdd 100644 --- a/solarwinds_apm/configurator.py +++ b/solarwinds_apm/configurator.py @@ -107,6 +107,7 @@ def _configure_otel_components( ) self._configure_otlp_metrics_span_processor( apm_txname_manager, + apm_config, apm_meters, ) self._configure_exporter( @@ -171,12 +172,14 @@ def _configure_metrics_span_processor( def _configure_otlp_metrics_span_processor( self, apm_txname_manager: SolarWindsTxnNameManager, + apm_config: SolarWindsApmConfig, apm_meters: SolarWindsMeterManager, ) -> None: """Configure SolarWindsOTLPMetricsSpanProcessor""" trace.get_tracer_provider().add_span_processor( SolarWindsOTLPMetricsSpanProcessor( apm_txname_manager, + apm_config, apm_meters, ) ) @@ -287,9 +290,6 @@ def _configure_metrics_exporter( "Creating PeriodicExportingMetricReader using %s", exporter_name, ) - # TODO: Does it have to be PeriodicExporting? - # What about pull exporters i.e. Prometheus - # https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#pull-metric-exporter reader = PeriodicExportingMetricReader(exporter) metric_readers.append(reader) diff --git a/solarwinds_apm/otlp_metrics_processor.py b/solarwinds_apm/otlp_metrics_processor.py index b6460d7b..ebcd1c18 100644 --- a/solarwinds_apm/otlp_metrics_processor.py +++ b/solarwinds_apm/otlp_metrics_processor.py @@ -18,6 +18,7 @@ if TYPE_CHECKING: from opentelemetry.sdk.trace import ReadableSpan + from solarwinds_apm.apm_config import SolarWindsApmConfig from solarwinds_apm.apm_meter_manager import SolarWindsMeterManager from solarwinds_apm.apm_txname_manager import SolarWindsTxnNameManager @@ -37,9 +38,11 @@ class SolarWindsOTLPMetricsSpanProcessor(SpanProcessor): def __init__( self, apm_txname_manager: "SolarWindsTxnNameManager", + apm_config: "SolarWindsApmConfig", apm_meters: "SolarWindsMeterManager", ) -> None: self.apm_txname_manager = apm_txname_manager + self.service_name = apm_config.service_name self.apm_meters = apm_meters # TODO Assumes SolarWindsInboundMetricsSpanProcessor.on_start @@ -57,9 +60,8 @@ def on_end(self, span: "ReadableSpan") -> None: return # support ssa and conform to Otel proto common_pb2 - # TODO init with ApmConfig to get service_name meter_attrs = { - "sw.service_name": "flask-metrics-test", + "sw.service_name": self.service_name, "sw.nonce": random.getrandbits(64) >> 1, }