Skip to content

Commit 27f49eb

Browse files
authored
More OTLP support (#1908)
* More OTLP support * And bump submodule * Better error logging * Fix sporadic CI failure
1 parent 0060a1a commit 27f49eb

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/ConfigOverride.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.opentelemetry.instrumentation.api.config.Config;
2929
import io.opentelemetry.instrumentation.api.config.ConfigBuilder;
3030
import java.util.HashMap;
31+
import java.util.Locale;
3132
import java.util.Map;
3233

3334
class ConfigOverride {
@@ -99,17 +100,22 @@ static Config getConfig(Configuration config) {
99100

100101
properties.put("otel.propagators", DelegatingPropagatorProvider.NAME);
101102

102-
String tracesExporter = System.getProperty("otel.traces.exporter");
103-
if (tracesExporter == null) {
104-
tracesExporter = System.getenv("OTEL_TRACES_EXPORTER");
105-
}
103+
String tracesExporter = getProperty("otel.traces.exporter");
106104
if (tracesExporter == null) {
107105
// currently Application Insights Exporter has to be configured manually because it relies on
108106
// using a BatchSpanProcessor with queue size 1 due to live metrics (this will change in the
109107
// future)
110108
properties.put("otel.traces.exporter", "none");
111109
} else {
112110
properties.put("otel.traces.exporter", tracesExporter);
111+
// when using another exporter, populate otel.service.name and otel.resource.attributes
112+
if (config.role.name != null) {
113+
properties.put("otel.service.name", config.role.name);
114+
}
115+
String resourceAttributes = getProperty("otel.resource.attributes");
116+
if (resourceAttributes != null) {
117+
properties.put("otel.resource.attributes", resourceAttributes);
118+
}
113119
}
114120

115121
String metricsExporter = System.getProperty("otel.metrics.exporter");
@@ -127,5 +133,14 @@ static Config getConfig(Configuration config) {
127133
return new ConfigBuilder().readProperties(properties).build();
128134
}
129135

136+
private static String getProperty(String propertyName) {
137+
String value = System.getProperty(propertyName);
138+
if (value != null) {
139+
return value;
140+
}
141+
String envVarName = propertyName.replace('.', '_').toUpperCase(Locale.ROOT);
142+
return System.getenv(envVarName);
143+
}
144+
130145
private ConfigOverride() {}
131146
}

test/smoke/appServers/JavaSE/resources/linux/startServer.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ do
66
sleep 1
77
done
88

9+
# need to give time for app.jar to be completely copied, otherwise sporadic
10+
# Error: Invalid or corrupt jarfile app.jar
11+
sleep 5
12+
913
if [ ! -z "$AI_AGENT_MODE" ]; then
1014

1115
echo "AI_AGENT_MODE=$AI_AGENT_MODE"

test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/docker/AiDockerClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,25 @@ public void execOnContainer(String id, String cmd, String... args)
180180
p,
181181
10,
182182
TimeUnit.SECONDS,
183-
String.format("executing command on container %s: '%s'", id, Joiner.on(' ').join(cmdList)));
183+
String.format("executing command on container %s: '%s'", id, Joiner.on(' ').join(cmdList)),
184+
id);
184185
flushStdout(p);
185186
}
186187

187188
private static void waitAndCheckCodeForProcess(
188189
Process p, long timeout, TimeUnit unit, String actionName)
189190
throws IOException, InterruptedException {
191+
waitAndCheckCodeForProcess(p, timeout, unit, actionName, null);
192+
}
193+
194+
private static void waitAndCheckCodeForProcess(
195+
Process p, long timeout, TimeUnit unit, String actionName, String containerId)
196+
throws IOException, InterruptedException {
190197
waitForProcessToReturn(p, timeout, unit, actionName);
191198
if (p.exitValue() != 0) {
199+
if (containerId != null) {
200+
printContainerLogs(containerId);
201+
}
192202
flushStdout(p);
193203
throw new SmokeTestException(
194204
String.format(

0 commit comments

Comments
 (0)