77import com .oracle .svm .core .jdk .Resources ;
88import datadog .trace .agent .tooling .Instrumenter ;
99import datadog .trace .agent .tooling .InstrumenterModule ;
10+ import java .io .BufferedReader ;
11+ import java .io .IOException ;
1012import java .io .InputStream ;
13+ import java .io .InputStreamReader ;
14+ import java .util .ArrayList ;
15+ import java .util .List ;
1116import net .bytebuddy .asm .Advice ;
1217
1318@ AutoService (InstrumenterModule .class )
@@ -33,32 +38,57 @@ public static void onExit() {
3338 // (drop trace/shared prefixes from embedded resources, so we can find them in native-image
3439 // as the final executable won't have our isolating class-loader to map these resources)
3540
36- String [] tracerResources = {
37- "dd-java-agent.version" ,
38- "dd-trace-api.version" ,
39- "trace/dd-trace-core.version" ,
40- "shared/dogstatsd/version.properties" ,
41- "shared/version-utils.version" ,
42- "shared/datadog/okhttp3/internal/publicsuffix/publicsuffixes.gz" ,
43- "profiling/jfr/dd.jfp" ,
44- "profiling/jfr/safepoints.jfp" ,
45- "profiling/jfr/overrides/comprehensive.jfp" ,
46- "profiling/jfr/overrides/minimal.jfp" ,
47- // jmxfetch configs
48- "metrics/project.properties" , // org.datadog.jmxfetch.AppConfig reads its version
49- "metrics/org/datadog/jmxfetch/default-jmx-metrics.yaml" ,
50- "metrics/org/datadog/jmxfetch/new-gc-default-jmx-metrics.yaml" ,
51- "metrics/org/datadog/jmxfetch/old-gc-default-jmx-metrics.yaml" ,
52- // tracer's jmxfetch configs
53- "metrics/jmxfetch-config.yaml" ,
54- "metrics/jmxfetch-websphere-config.yaml" ,
55- };
41+ List <String > tracerResources = new ArrayList <>();
42+ tracerResources .add ("dd-java-agent.version" );
43+ tracerResources .add ("dd-trace-api.version" );
44+ tracerResources .add ("trace/dd-trace-core.version" );
45+ tracerResources .add ("shared/dogstatsd/version.properties" );
46+ tracerResources .add ("shared/version-utils.version" );
47+ tracerResources .add ("shared/datadog/okhttp3/internal/publicsuffix/publicsuffixes.gz" );
48+ tracerResources .add ("profiling/jfr/dd.jfp" );
49+ tracerResources .add ("profiling/jfr/safepoints.jfp" );
50+ tracerResources .add ("profiling/jfr/overrides/comprehensive.jfp" );
51+ tracerResources .add ("profiling/jfr/overrides/minimal.jfp" );
5652
53+ // jmxfetch configs
54+ tracerResources .add (
55+ "metrics/project.properties" ); // org.datadog.jmxfetch.AppConfig reads its version
56+ tracerResources .add ("metrics/org/datadog/jmxfetch/default-jmx-metrics.yaml" );
57+ tracerResources .add ("metrics/org/datadog/jmxfetch/new-gc-default-jmx-metrics.yaml" );
58+ tracerResources .add ("metrics/org/datadog/jmxfetch/old-gc-default-jmx-metrics.yaml" );
59+
60+ // tracer's jmxfetch configs
61+ tracerResources .add ("metrics/jmxfetch-config.yaml" );
62+ tracerResources .add ("metrics/jmxfetch-websphere-config.yaml" );
63+
64+ {
65+ // jmxfetch integrations metricconfigs
66+ String metricConfigsPath = "metrics/datadog/trace/agent/jmxfetch/" ;
67+ String metricConfigs = metricConfigsPath + "metricconfigs.txt" ;
68+ tracerResources .add (metricConfigs );
69+ InputStream is = ClassLoader .getSystemResourceAsStream (metricConfigs );
70+ if (is == null ) {
71+ System .err .println ("ERROR: metricconfigs.txt not found" );
72+ } else
73+ try (BufferedReader reader = new BufferedReader (new InputStreamReader (is ))) {
74+ String metricConfig ;
75+ while ((metricConfig = reader .readLine ()) != null ) {
76+ if (!metricConfig .trim ().isEmpty ()) {
77+ tracerResources .add (metricConfigsPath + "metricconfigs/" + metricConfig );
78+ }
79+ }
80+ } catch (IOException e ) {
81+ System .err .println ("ERROR: reading metricconfig: " + e );
82+ }
83+ }
84+
85+ // registering tracer resources to include in the native build
5786 for (String original : tracerResources ) {
5887 String flattened = original .substring (original .indexOf ('/' ) + 1 );
5988 try (InputStream is = ClassLoader .getSystemResourceAsStream (original )) {
6089 Resources .registerResource (flattened , is );
61- } catch (Throwable ignore ) {
90+ } catch (Throwable t ) {
91+ System .err .println ("ERROR: reading `" + original + "` " + t );
6292 }
6393 }
6494 }
0 commit comments