diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java index 1d15e065..31f8b1c7 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java @@ -157,12 +157,13 @@ protected MetricsMonitor buildMetricsMonitor() { new TracingReporterMetricsCollector( ReporterProvider.getEventReporter())); - String collector = - (String) ConfigManager.getConfig(ConfigProperty.AGENT_COLLECTOR); - if (collector != null && !collector.contains("appoptics.com")) { + Boolean enabled = + (Boolean) + ConfigManager.getConfig( + ConfigProperty.AGENT_EXPORT_METRICS_ENABLED); + if (enabled == null || enabled) { metricsCollector.removeCollector(MetricsCategory.TRACING_REPORTER); } - return MetricsMonitor.buildInstance(configs, metricsCollector); } catch (InvalidConfigException | ClientException e) { logger.debug(String.format("Error creating MetricsCollector: %s", e)); diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsInboundMetricsSpanProcessor.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsInboundMetricsSpanProcessor.java index fa5126ff..26ab1633 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsInboundMetricsSpanProcessor.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsInboundMetricsSpanProcessor.java @@ -109,12 +109,16 @@ public boolean isEndRequired() { private static class OpenTelemetryInboundMeasurementReporter extends MetricSpanReporter { public static final String MEASUREMENT_NAME_OLD = "TransactionResponseTime"; + public static final String MEASUREMENT_NAME = "ResponseTime"; // cannot use Guava cache here, jboss issue... private final Map measurements = new ConcurrentHashMap(); + // private final String measurementName; - protected OpenTelemetryInboundMeasurementReporter() {} + protected OpenTelemetryInboundMeasurementReporter() { + // super(TRANSACTION_LATENCY_METRIC_NAME); + } @Override public List> consumeMetricEntries() { @@ -186,6 +190,9 @@ private void reportMetrics(SpanData spanData) { if (collector != null && collector.contains("appoptics.com")) { logger.debug("Sending metrics to AO"); recordMeasurementEntryForAo(aoPrimaryKeys, aoSecondaryKey, duration); + } else { + logger.debug("Sending metrics to SWO"); + recordMeasurementEntryForSwo(swoTags, duration); } } @@ -206,11 +213,24 @@ protected void recordMeasurementEntryForAo( .recordValue(duration); } } + + protected void recordMeasurementEntryForSwo(Map tags, long duration) { + Boolean enabled = + (Boolean) ConfigManager.getConfig(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED); + if (enabled == null || enabled) { + return; + } + MetricKey measurementKey = new MetricKey(MEASUREMENT_NAME, new HashMap<>(tags)); + this.measurements + .computeIfAbsent(measurementKey, k -> new SummaryLongMeasurement()) + .recordValue(duration); + } } // TODO copied from Core, should improve to avoid code duplication private static class OpenTelemetryInboundHistogramReporter extends MetricSpanReporter { public static final String TRANSACTION_LATENCY_METRIC_NAME = "TransactionResponseTime"; + public static final String TRANSACTION_NAME_TAG_KEY = "TransactionName"; private static final HistogramFactory.HistogramType HISTOGRAM_TYPE = HistogramFactory.HistogramType.HDR; @@ -243,16 +263,12 @@ public Map consumeHistograms() { } public void reportMetrics(SpanData spanData) { - String collector = (String) ConfigManager.getConfig(ConfigProperty.AGENT_COLLECTOR); - if (collector != null && !collector.contains("appoptics.com")) { - return; - } - final MetricKey serviceHistogramKey = new MetricKey( TRANSACTION_LATENCY_METRIC_NAME, null); // globally for all transactions within this service - final Histogram serviceHistogram = + final Histogram serviceHistogram; + serviceHistogram = histograms.computeIfAbsent( serviceHistogramKey, k -> HistogramFactory.buildHistogram(HISTOGRAM_TYPE, MAX_DURATION));