Skip to content

Commit 7a5ea6b

Browse files
authored
Merge pull request #1410 from microsoft/trask/update-to-otel-0.12.0
Update to otel-java-instrumentation 0.12.0
2 parents c956e8e + 95137f4 commit 7a5ea6b

File tree

30 files changed

+365
-181
lines changed

30 files changed

+365
-181
lines changed

agent/agent-bootstrap/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ task generateVersionProperties(type: PropsFileGen) {
2424
processResources.dependsOn generateVersionProperties
2525

2626
dependencies {
27-
compile (group: 'io.opentelemetry.javaagent', name: 'opentelemetry-javaagent-bootstrap', version: '0.11.0+ai.patch.1') {
27+
compile (group: 'io.opentelemetry.javaagent', name: 'opentelemetry-javaagent-bootstrap', version: '0.12.0+ai.patch.1') {
2828
exclude group: 'org.slf4j', module: 'slf4j-simple'
2929
}
30-
compile group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-api', version: '0.11.0+ai.patch.1'
31-
compile group: 'io.opentelemetry.javaagent', name: 'opentelemetry-javaagent-api', version: '0.11.0+ai.patch.1'
30+
compile group: 'io.opentelemetry.instrumentation', name: 'opentelemetry-instrumentation-api', version: '0.12.0+ai.patch.1'
31+
compile group: 'io.opentelemetry.javaagent', name: 'opentelemetry-javaagent-api', version: '0.12.0+ai.patch.1'
3232
compile 'ch.qos.logback:logback-classic:1.2.3'
3333
compile 'ch.qos.logback.contrib:logback-json-classic:0.1.5'
3434

agent/agent-bootstrap/spotbugs.exclude.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@
4545
<Class name="com.microsoft.applicationinsights.agent.bootstrap.diagnostics.PidFinder" />
4646
<Method name="getPidUsingProcessHandle" />
4747
</Match>
48+
<Match>
49+
<Bug pattern="CRLF_INJECTION_LOGS" />
50+
<Class name="com.microsoft.applicationinsights.agent.bootstrap.MainEntryPoint" />
51+
<Method name="logErrorMessage" />
52+
</Match>
53+
<Match>
54+
<Bug pattern="CRLF_INJECTION_LOGS" />
55+
<Class name="com.microsoft.applicationinsights.agent.bootstrap.MainEntryPoint" />
56+
<Method name="start" />
57+
</Match>
4858
</FindBugsFilter>

agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/MainEntryPoint.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.microsoft.applicationinsights.agent.bootstrap.configuration.ConfigurationBuilder;
3232
import com.microsoft.applicationinsights.agent.bootstrap.customExceptions.FriendlyException;
3333
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.DiagnosticsHelper;
34+
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.SdkVersionFinder;
3435
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.status.StatusFile;
3536
import io.opentelemetry.javaagent.bootstrap.AgentInitializer;
3637
import io.opentelemetry.javaagent.bootstrap.ConfigureLogging;
@@ -63,6 +64,7 @@ public static long getLastModifiedTime() {
6364
public static void start(Instrumentation instrumentation, URL bootstrapURL) {
6465
boolean success = false;
6566
Logger startupLogger = null;
67+
String version = SdkVersionFinder.readVersion();
6668
try {
6769
Path agentPath = new File(bootstrapURL.toURI()).toPath();
6870
DiagnosticsHelper.setAgentJarFile(agentPath);
@@ -74,7 +76,7 @@ public static void start(Instrumentation instrumentation, URL bootstrapURL) {
7476
ConfigurationBuilder.logConfigurationMessages();
7577
MDC.put(DiagnosticsHelper.MDC_PROP_OPERATION, "Startup");
7678
AgentInitializer.initialize(instrumentation, bootstrapURL, false);
77-
startupLogger.info("ApplicationInsights Java Agent started successfully");
79+
startupLogger.info("ApplicationInsights Java Agent {} started successfully", version);
7880
success = true;
7981
LoggerFactory.getLogger(DiagnosticsHelper.DIAGNOSTICS_LOGGER_NAME)
8082
.info("Application Insights Codeless Agent Attach Successful");
@@ -83,10 +85,11 @@ public static void start(Instrumentation instrumentation, URL bootstrapURL) {
8385
} catch (Throwable t) {
8486

8587
FriendlyException friendlyException = getFriendlyException(t);
88+
String banner = "ApplicationInsights Java Agent " + version + " failed to start";
8689
if (friendlyException != null) {
87-
logErrorMessage(startupLogger, friendlyException.getMessage(), true, t);
90+
logErrorMessage(startupLogger, friendlyException.getMessageWithBanner(banner), true, t);
8891
} else {
89-
logErrorMessage(startupLogger, "ApplicationInsights Java Agent failed to start", false, t);
92+
logErrorMessage(startupLogger, banner, false, t);
9093
}
9194

9295
} finally {
@@ -188,6 +191,10 @@ private static Logger configureLogging(SelfDiagnostics selfDiagnostics, Path age
188191

189192
Level otherLibsLevel = level == Level.INFO ? Level.WARN : level;
190193

194+
// TODO need something more reliable, currently will log too much WARN if "muzzleMatcher" logger name changes
195+
// muzzleMatcher logs at WARN level in order to make them visible, but really should only be enabled when debugging
196+
Level muzzleMatcherLevel = level.levelInt <= Level.DEBUG.levelInt ? level : getMaxLevel(level, Level.WARN);
197+
191198
try {
192199
System.setProperty("applicationinsights.logback.configurationFile", configurationFile.toString());
193200

@@ -196,10 +203,10 @@ private static Logger configureLogging(SelfDiagnostics selfDiagnostics, Path age
196203
System.setProperty("applicationinsights.logback.file.maxSize", selfDiagnostics.file.maxSizeMb + "MB");
197204
System.setProperty("applicationinsights.logback.file.maxIndex", Integer.toString(selfDiagnostics.file.maxHistory));
198205

199-
System.setProperty("applicationinsights.logback.level.other", otherLibsLevel.toString());
200206
System.setProperty("applicationinsights.logback.level", level.levelStr);
201-
207+
System.setProperty("applicationinsights.logback.level.other", otherLibsLevel.toString());
202208
System.setProperty("applicationinsights.logback.level.atLeastInfo", atLeastInfoLevel.levelStr);
209+
System.setProperty("applicationinsights.logback.level.muzzleMatcher", muzzleMatcherLevel.levelStr);
203210

204211
return LoggerFactory.getLogger("com.microsoft.applicationinsights.agent");
205212
} finally {
@@ -209,7 +216,9 @@ private static Logger configureLogging(SelfDiagnostics selfDiagnostics, Path age
209216
System.clearProperty("applicationinsights.logback.file.maxSize");
210217
System.clearProperty("applicationinsights.logback.file.maxIndex");
211218
System.clearProperty("applicationinsights.logback.level");
212-
System.clearProperty("applicationinsights.logback.level.org.apache.http");
219+
System.clearProperty("applicationinsights.logback.level.other");
220+
System.clearProperty("applicationinsights.logback.level.atLeastInfo");
221+
System.clearProperty("applicationinsights.logback.level.muzzleMatcher");
213222
}
214223
}
215224

agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/configuration/Configuration.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,15 @@ private static void isValidRegex(String value) throws FriendlyException {
126126
try {
127127
Pattern.compile(value);
128128
} catch (PatternSyntaxException exception) {
129-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
130-
"Telemetry processor configuration does not have valid regex:" + value,
129+
throw new FriendlyException("Telemetry processor configuration does not have valid regex:" + value,
131130
"Please provide a valid regex in the telemetry processors configuration. " +
132131
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
133132
}
134133
}
135134

136135
public void validate() throws FriendlyException {
137136
if (type == null) {
138-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
139-
"Telemetry processor configuration has a processor with no type!!!",
137+
throw new FriendlyException("Telemetry processor configuration has a processor with no type!!!",
140138
"Please provide a type in the telemetry processors configuration. " +
141139
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
142140
}
@@ -153,8 +151,7 @@ public void validate() throws FriendlyException {
153151
public void validateAttributeProcessorConfig() throws FriendlyException {
154152
if (type == ProcessorType.attribute) {
155153
if (actions == null || actions.isEmpty()) {
156-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
157-
"Telemetry processor configuration has invalid attribute processor configuration with empty actions!!!",
154+
throw new FriendlyException("Telemetry processor configuration has invalid attribute processor configuration with empty actions!!!",
158155
"Please provide at least one action in the attribute processors configuration. " +
159156
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
160157
}
@@ -167,8 +164,7 @@ public void validateAttributeProcessorConfig() throws FriendlyException {
167164
public void validateLogOrSpanProcessorConfig() throws FriendlyException {
168165
if (type == ProcessorType.log || type == ProcessorType.span) {
169166
if (name == null) {
170-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
171-
"Telemetry processor configuration has invalid span/log processor configuration with empty name object!!!",
167+
throw new FriendlyException("Telemetry processor configuration has invalid span/log processor configuration with empty name object!!!",
172168
"Please provide name in the span/log processor configuration. " +
173169
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
174170
}
@@ -184,8 +180,7 @@ public static class NameConfig {
184180

185181
public void validate() throws FriendlyException {
186182
if (fromAttributes == null && toAttributes == null) {
187-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
188-
"Telemetry processor configuration has invalid name object with no fromAttributes or no toAttributes!!!",
183+
throw new FriendlyException("Telemetry processor configuration has invalid name object with no fromAttributes or no toAttributes!!!",
189184
"Please provide at least one of fromAttributes or toAttributes in the processor configuration. " +
190185
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
191186
}
@@ -198,8 +193,7 @@ public static class ToAttributeConfig {
198193

199194
public void validate() throws FriendlyException {
200195
if(rules==null || rules.isEmpty()) {
201-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
202-
"Telemetry processor configuration has invalid toAttribute value with no rules!!!",
196+
throw new FriendlyException("Telemetry processor configuration has invalid toAttribute value with no rules!!!",
203197
"Please provide at least one rule under the toAttribute section of processor configuration. " +
204198
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
205199
}
@@ -218,16 +212,14 @@ public static class ProcessorIncludeExclude {
218212

219213
public void validate (ProcessorType processorType) throws FriendlyException {
220214
if (this.matchType == null) {
221-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
222-
"Telemetry processor configuration has invalid include/exclude value with no matchType!!!",
215+
throw new FriendlyException("Telemetry processor configuration has invalid include/exclude value with no matchType!!!",
223216
"Please provide matchType under the include/exclude section of processor configuration. " +
224217
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
225218
}
226219
if (this.attributes != null) {
227220
for (ProcessorAttribute attribute : this.attributes) {
228221
if (attribute.key == null || attribute.key.isEmpty()) {
229-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
230-
"Telemetry processor configuration has invalid include/exclude value with attribute which has empty key!!!",
222+
throw new FriendlyException("Telemetry processor configuration has invalid include/exclude value with attribute which has empty key!!!",
231223
"Please provide valid key with value under the include/exclude's attribute section of processor configuration. " +
232224
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
233225
}
@@ -248,8 +240,7 @@ public void validate (ProcessorType processorType) throws FriendlyException {
248240

249241
private void validAttributeProcessorIncludeExclude() throws FriendlyException {
250242
if (spanNames == null && attributes == null) {
251-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
252-
"Telemetry processor configuration has invalid include/exclude value with no spanNames or no attributes!!!",
243+
throw new FriendlyException("Telemetry processor configuration has invalid include/exclude value with no spanNames or no attributes!!!",
253244
"Please provide at least one of spanNames or attributes under the include/exclude section of processor configuration. " +
254245
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
255246
}
@@ -262,8 +253,7 @@ private void validAttributeProcessorIncludeExclude() throws FriendlyException {
262253

263254
private void validateLogProcessorIncludeExclude() throws FriendlyException {
264255
if (logNames == null && attributes == null) {
265-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
266-
"Telemetry processor configuration has invalid include/exclude value with no logNames or no attributes!!!",
256+
throw new FriendlyException("Telemetry processor configuration has invalid include/exclude value with no logNames or no attributes!!!",
267257
"Please provide at least one of logNames or attributes under the include/exclude section of processor configuration. " +
268258
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
269259
}
@@ -276,8 +266,7 @@ private void validateLogProcessorIncludeExclude() throws FriendlyException {
276266

277267
private void validateSpanProcessorIncludeExclude() throws FriendlyException {
278268
if (spanNames == null && attributes == null) {
279-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
280-
"Telemetry processor configuration has invalid include/exclude value with no spanNames or no attributes!!!",
269+
throw new FriendlyException("Telemetry processor configuration has invalid include/exclude value with no spanNames or no attributes!!!",
281270
"Please provide at least one of spanNames or attributes under the include/exclude section of processor configuration. " +
282271
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
283272
}
@@ -305,21 +294,18 @@ public static class ProcessorAction {
305294
public void validate() throws FriendlyException {
306295

307296
if (this.key == null || this.key.isEmpty()) {
308-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
309-
"Telemetry processor configuration has invalid action with empty key!!!",
297+
throw new FriendlyException("Telemetry processor configuration has invalid action with empty key!!!",
310298
"Please provide a valid key with value under each action section of processor configuration. " +
311299
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
312300
}
313301
if (this.action == null) {
314-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
315-
"Telemetry processor configuration has invalid config with empty action!!!",
302+
throw new FriendlyException("Telemetry processor configuration has invalid config with empty action!!!",
316303
"Please provide a valid action. Telemetry processors cannot have empty or no actions. " +
317304
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
318305
}
319306
if (this.action == ProcessorActionType.insert || this.action == ProcessorActionType.update) {
320307
if(this.value == null && this.fromAttribute == null) {
321-
throw new FriendlyException("ApplicationInsights Java Agent failed to start.",
322-
"Telemetry processor configuration has invalid action with empty value or empty fromAttribute!!!",
308+
throw new FriendlyException("Telemetry processor configuration has invalid action with empty value or empty fromAttribute!!!",
323309
"Please provide a valid action with value under each action section of processor configuration. " +
324310
"Learn more about telemetry processors here: https://go.microsoft.com/fwlink/?linkid=2151557");
325311
}

0 commit comments

Comments
 (0)