66package io .opentelemetry .contrib .jmxscraper ;
77
88import io .opentelemetry .api .GlobalOpenTelemetry ;
9+ import io .opentelemetry .api .OpenTelemetry ;
910import io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig ;
1011import io .opentelemetry .contrib .jmxscraper .config .PropertiesCustomizer ;
1112import io .opentelemetry .contrib .jmxscraper .config .PropertiesSupplier ;
1213import io .opentelemetry .instrumentation .jmx .engine .JmxMetricInsight ;
1314import io .opentelemetry .instrumentation .jmx .engine .MetricConfiguration ;
1415import io .opentelemetry .instrumentation .jmx .yaml .RuleParser ;
16+ import io .opentelemetry .sdk .OpenTelemetrySdk ;
1517import io .opentelemetry .sdk .autoconfigure .AutoConfiguredOpenTelemetrySdk ;
1618import io .opentelemetry .sdk .autoconfigure .spi .ConfigurationException ;
1719import java .io .DataInputStream ;
@@ -62,22 +64,12 @@ public static void main(String[] args) {
6264 Properties argsConfig = argsToConfig (effectiveArgs );
6365 propagateToSystemProperties (argsConfig );
6466
65- // auto-configure and register SDK
6667 PropertiesCustomizer configCustomizer = new PropertiesCustomizer ();
67- AutoConfiguredOpenTelemetrySdk .builder ()
68- .addPropertiesSupplier (new PropertiesSupplier (argsConfig ))
69- .addPropertiesCustomizer (configCustomizer )
70- .setResultAsGlobal ()
71- .build ();
72-
7368 JmxScraperConfig scraperConfig = configCustomizer .getScraperConfig ();
7469
7570 long exportSeconds = scraperConfig .getSamplingInterval ().toMillis () / 1000 ;
7671 logger .log (Level .INFO , "metrics export interval (seconds) = " + exportSeconds );
7772
78- JmxMetricInsight service =
79- JmxMetricInsight .createService (
80- GlobalOpenTelemetry .get (), scraperConfig .getSamplingInterval ().toMillis ());
8173 JmxConnectorBuilder connectorBuilder =
8274 JmxConnectorBuilder .createNew (scraperConfig .getServiceUrl ());
8375
@@ -91,7 +83,16 @@ public static void main(String[] args) {
9183 if (testMode ) {
9284 System .exit (testConnection (connectorBuilder ) ? 0 : 1 );
9385 } else {
94- JmxScraper jmxScraper = new JmxScraper (connectorBuilder , service , scraperConfig );
86+ // auto-configure SDK
87+ OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk .builder ()
88+ .addPropertiesSupplier (new PropertiesSupplier (argsConfig ))
89+ .addPropertiesCustomizer (configCustomizer )
90+ .build ()
91+ .getOpenTelemetrySdk ();
92+ JmxMetricInsight jmxInsight =
93+ JmxMetricInsight .createService (
94+ openTelemetry , scraperConfig .getSamplingInterval ().toMillis ());
95+ JmxScraper jmxScraper = new JmxScraper (connectorBuilder , jmxInsight , scraperConfig );
9596 jmxScraper .start ();
9697 }
9798 } catch (ConfigurationException e ) {
0 commit comments