|
19 | 19 | package co.elastic.otel.agent; |
20 | 20 |
|
21 | 21 | import io.opentelemetry.javaagent.OpenTelemetryAgent; |
| 22 | +import java.io.IOException; |
| 23 | +import java.io.InputStream; |
22 | 24 | import java.lang.instrument.Instrumentation; |
| 25 | +import java.util.Objects; |
23 | 26 |
|
24 | 27 | /** Elastic agent entry point, delegates to OpenTelemetry agent */ |
25 | 28 | public class ElasticAgent { |
@@ -56,7 +59,36 @@ public static void agentmain(String agentArgs, Instrumentation inst) { |
56 | 59 | * @param args arguments |
57 | 60 | */ |
58 | 61 | public static void main(String[] args) { |
59 | | - OpenTelemetryAgent.main(args); |
| 62 | + boolean upstreamDefault = true; |
| 63 | + for (String arg : args) { |
| 64 | + switch (arg) { |
| 65 | + case "--default-config-yaml": |
| 66 | + printDefaultConfigYaml(); |
| 67 | + upstreamDefault = false; |
| 68 | + break; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if (upstreamDefault) { |
| 73 | + OpenTelemetryAgent.main(args); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + private static void printDefaultConfigYaml() { |
| 78 | + try (InputStream input = |
| 79 | + ElasticAgent.class |
| 80 | + .getClassLoader() |
| 81 | + .getResourceAsStream("inst/co/elastic/otel/config.yaml")) { |
| 82 | + Objects.requireNonNull(input, "Default config yaml resource is missing"); |
| 83 | + |
| 84 | + byte[] buffer = new byte[8192]; |
| 85 | + int read; |
| 86 | + while ((read = input.read(buffer)) != -1) { |
| 87 | + System.out.write(buffer, 0, read); |
| 88 | + } |
| 89 | + } catch (IOException e) { |
| 90 | + throw new IllegalStateException("Failed to print default config yaml", e); |
| 91 | + } |
60 | 92 | } |
61 | 93 |
|
62 | 94 | private static void initLogging() { |
|
0 commit comments