Skip to content

Commit 8f71a1d

Browse files
committed
add simple '--default-config-yaml' CLI option
1 parent 31ee949 commit 8f71a1d

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

agent/entrypoint/src/main/java/co/elastic/otel/agent/ElasticAgent.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
package co.elastic.otel.agent;
2020

2121
import io.opentelemetry.javaagent.OpenTelemetryAgent;
22+
import java.io.IOException;
23+
import java.io.InputStream;
2224
import java.lang.instrument.Instrumentation;
25+
import java.util.Objects;
2326

2427
/** Elastic agent entry point, delegates to OpenTelemetry agent */
2528
public class ElasticAgent {
@@ -56,7 +59,36 @@ public static void agentmain(String agentArgs, Instrumentation inst) {
5659
* @param args arguments
5760
*/
5861
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+
}
6092
}
6193

6294
private static void initLogging() {

0 commit comments

Comments
 (0)