Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging capture threshold #1026

Merged
merged 4 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plugins {
apply from: "$buildScriptsDir/common-java.gradle"
apply from: "$buildScriptsDir/publishing.gradle"

def instrumentationVersion = '0.14.2'
def instrumentationVersion = '0.14.3'

def shadowPrefix = 'com.microsoft.applicationinsights.agent.shadow'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,19 @@ static Map<String, Map<String, Object>> getInstrumentationConfig(BuiltInInstrume
jdbcConfiguration.put("captureGetConnection", false);
jdbcConfiguration.put("explainPlanThresholdMillis", builtInConfiguration.getQueryPlanThresholdInMS());

// must be one of trace, debug, info, warn, error (which are supported by both log4j and logback)
String loggingThreshold = builtInConfiguration.getLoggingThreshold();

Map<String, Object> log4jConfiguration = new HashMap<>();
log4jConfiguration.put("threshold", loggingThreshold);

Map<String, Object> logbackConfiguration = new HashMap<>();
logbackConfiguration.put("threshold", loggingThreshold);

instrumentationConfiguration.put("servlet", servletConfiguration);
instrumentationConfiguration.put("jdbc", jdbcConfiguration);
instrumentationConfiguration.put("log4j", log4jConfiguration);
instrumentationConfiguration.put("logback", logbackConfiguration);

return instrumentationConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private static void start(Instrumentation instrumentation, File agentJarFile) th
AIAgentXmlLoader.getInstrumentationConfig(builtInInstrumentation));

EngineModule.createWithSomeDefaults(instrumentation, tmpDir, Global.getThreadContextThreadLocal(),
instrumentationDescriptors, configServiceFactory, new AgentImpl(),
instrumentationDescriptors, configServiceFactory, new AgentImpl(), false,
Collections.singletonList("com.microsoft.applicationinsights.agent"),
Collections.singletonList("com.microsoft.applicationinsights.agent"), agentJarFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class BuiltInInstrumentation {
private final boolean jdbcEnabled;

private final boolean loggingEnabled;
private final String loggingThreshold;

private final boolean jedisEnabled;

Expand All @@ -43,6 +44,7 @@ public BuiltInInstrumentation(boolean enabled,
boolean w3cBackCompatEnabled,
boolean jdbcEnabled,
boolean loggingEnabled,
String loggingThreshold,
boolean jedisEnabled,
long queryPlanThresholdInMS) {
this.enabled = enabled;
Expand All @@ -51,6 +53,7 @@ public BuiltInInstrumentation(boolean enabled,
this.w3cBackCompatEnabled = w3cBackCompatEnabled;
this.jdbcEnabled = jdbcEnabled;
this.loggingEnabled = loggingEnabled;
this.loggingThreshold = loggingThreshold;
this.jedisEnabled = jedisEnabled;
this.queryPlanThresholdInMS = queryPlanThresholdInMS;
}
Expand All @@ -75,6 +78,10 @@ public boolean isJdbcEnabled() {
return jdbcEnabled;
}

public String getLoggingThreshold() {
return loggingThreshold;
}

public boolean isLoggingEnabled() {
return loggingEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class BuiltInInstrumentationBuilder {
private boolean jdbcEnabled;

private boolean loggingEnabled;
private String loggingThreshold;

private boolean jedisEnabled;

Expand All @@ -54,6 +55,7 @@ public BuiltInInstrumentation create() {
w3cBackCompatEnabled && enabled,
jdbcEnabled && enabled,
loggingEnabled && enabled,
loggingThreshold,
jedisEnabled && enabled,
queryPlanThresholdInMS
);
Expand All @@ -73,8 +75,9 @@ public void setJdbcEnabled(boolean jdbcEnabled) {
this.jdbcEnabled = jdbcEnabled;
}

public void setLoggingEnabled(boolean loggingEnabled) {
public void setLoggingEnabled(boolean loggingEnabled, String loggingThreshold) {
this.loggingEnabled = loggingEnabled;
this.loggingThreshold = loggingThreshold;
}

public void setJedisEnabled(boolean jedisEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ private void setBuiltInInstrumentation(AgentConfiguration agentConfiguration,
builtInConfigurationBuilder.setJdbcEnabled(XmlParserUtils.getEnabled(XmlParserUtils.getFirst(nodes), JDBC_TAG));

nodes = builtInElement.getElementsByTagName(LOGGING_TAG);
builtInConfigurationBuilder
.setLoggingEnabled(XmlParserUtils.getEnabled(XmlParserUtils.getFirst(nodes), LOGGING_TAG));
builtInConfigurationBuilder.setLoggingEnabled(
XmlParserUtils.getEnabled(XmlParserUtils.getFirst(nodes), LOGGING_TAG),
XmlParserUtils.getStringAttribute(XmlParserUtils.getFirst(nodes), "threshold", "warn"));

nodes = builtInElement.getElementsByTagName(JEDIS_TAG);
Element element = XmlParserUtils.getFirst(nodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Element getFirst(NodeList nodes) {
return (Element) node;
}

public static boolean getEnabled(Element element, String attributeName) {
public static boolean getEnabled(Element element, String elementName) {
if (element == null) {
return true;
}
Expand All @@ -57,7 +57,7 @@ public static boolean getEnabled(Element element, String attributeName) {
return true;
} catch (Exception e) {
logger.error("Failed to parse attribute '{}' of '{}', default value ({}) will be used.", ENABLED_ATTRIBUTE,
attributeName, true);
elementName, true);
}
return true;
}
Expand Down Expand Up @@ -98,6 +98,17 @@ public static long getLongAttribute(Element element, String attributeName, long
return defaultValue;
}

public static String getStringAttribute(Element element, String attributeName, String defaultValue) {
if (element == null) {
return defaultValue;
}
String strValue = element.getAttribute(attributeName);
if (!Strings.isNullOrEmpty(strValue)) {
return strValue;
}
return defaultValue;
}

public static Long getLong(Element element, String elementName) {
if (element == null) {
return null;
Expand All @@ -113,7 +124,7 @@ public static Long getLong(Element element, String elementName) {
}
return null;
} catch (Exception e) {
logger.error("Failed to parse attribute '{}' of '{}'", ENABLED_ATTRIBUTE, elementName);
logger.error("Failed to parse value of '{}'", elementName);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ archivesBaseName = 'applicationinsights-core'

dependencies {
compileOnly (project(':agent')) { transitive = false }
compileOnly ([group: 'org.glowroot.instrumentation', name: 'instrumentation-api', version: '0.14.2']) { transitive = false }
compileOnly ([group: 'org.glowroot.instrumentation', name: 'instrumentation-api', version: '0.14.3']) { transitive = false }
compile(project(':ApplicationInsightsInternalLogger'))
compile ([group: 'eu.infomas', name: 'annotation-detector', version: '3.0.5'])
compile ([group: 'commons-io', name: 'commons-io', version: '2.6' ])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,26 @@ public class TraceLog4j1_2Test extends AiSmokeTest {
@TargetUri("/traceLog4j1_2")
public void testTraceLog4j1_2() {

assertEquals(6, mockedIngestion.getCountForType("MessageData"));
assertEquals(3, mockedIngestion.getCountForType("MessageData"));

MessageData md1 = getTelemetryDataForType(0, "MessageData");
assertEquals("This is log4j1.2 trace.", md1.getMessage());
assertEquals(SeverityLevel.Verbose, md1.getSeverityLevel());
assertEquals("This is log4j1.2 warn.", md1.getMessage());
assertEquals(SeverityLevel.Warning, md1.getSeverityLevel());
assertEquals("Logger", md1.getProperties().get("SourceType"));
assertEquals("TRACE", md1.getProperties().get("LoggingLevel"));
assertEquals("WARN", md1.getProperties().get("LoggingLevel"));


MessageData md2 = getTelemetryDataForType(1, "MessageData");
assertEquals("This is log4j1.2 debug.", md2.getMessage());
assertEquals(SeverityLevel.Verbose, md2.getSeverityLevel());
assertEquals("This is log4j1.2 error.", md2.getMessage());
assertEquals(SeverityLevel.Error, md2.getSeverityLevel());
assertEquals("Logger", md2.getProperties().get("SourceType"));
assertEquals("DEBUG", md2.getProperties().get("LoggingLevel"));
assertEquals("ERROR", md2.getProperties().get("LoggingLevel"));

MessageData md3 = getTelemetryDataForType(2, "MessageData");
assertEquals("This is log4j1.2 info.", md3.getMessage());
assertEquals(SeverityLevel.Information, md3.getSeverityLevel());
assertEquals("This is log4j1.2 fatal.", md3.getMessage());
assertEquals(SeverityLevel.Critical, md3.getSeverityLevel());
assertEquals("Logger", md3.getProperties().get("SourceType"));
assertEquals("INFO", md3.getProperties().get("LoggingLevel"));

MessageData md4 = getTelemetryDataForType(3, "MessageData");
assertEquals("This is log4j1.2 warn.", md4.getMessage());
assertEquals(SeverityLevel.Warning, md4.getSeverityLevel());
assertEquals("Logger", md4.getProperties().get("SourceType"));
assertEquals("WARN", md4.getProperties().get("LoggingLevel"));


MessageData md5 = getTelemetryDataForType(4, "MessageData");
assertEquals("This is log4j1.2 error.", md5.getMessage());
assertEquals(SeverityLevel.Error, md5.getSeverityLevel());
assertEquals("Logger", md5.getProperties().get("SourceType"));
assertEquals("ERROR", md5.getProperties().get("LoggingLevel"));

MessageData md6 = getTelemetryDataForType(5, "MessageData");
assertEquals("This is log4j1.2 fatal.", md6.getMessage());
assertEquals(SeverityLevel.Critical, md6.getSeverityLevel());
assertEquals("Logger", md6.getProperties().get("SourceType"));
assertEquals("FATAL", md6.getProperties().get("LoggingLevel"));
assertEquals("FATAL", md3.getProperties().get("LoggingLevel"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,25 @@ public class TraceLog4j2Test extends AiSmokeTest {
@Test
@TargetUri("/traceLog4j2")
public void testTraceLog4j2() {
assertEquals(6, mockedIngestion.getCountForType("MessageData"));
assertEquals(3, mockedIngestion.getCountForType("MessageData"));

MessageData md1 = getTelemetryDataForType(0, "MessageData");
assertEquals("This is log4j2 trace.", md1.getMessage());
assertEquals(SeverityLevel.Verbose, md1.getSeverityLevel());
assertEquals("This is log4j2 warn.", md1.getMessage());
assertEquals(SeverityLevel.Warning, md1.getSeverityLevel());
assertEquals("Logger", md1.getProperties().get("SourceType"));
assertEquals("TRACE", md1.getProperties().get("LoggingLevel"));
assertEquals("WARN", md1.getProperties().get("LoggingLevel"));

MessageData md2 = getTelemetryDataForType(1, "MessageData");
assertEquals("This is log4j2 debug.", md2.getMessage());
assertEquals(SeverityLevel.Verbose, md2.getSeverityLevel());
assertEquals("This is log4j2 error.", md2.getMessage());
assertEquals(SeverityLevel.Error, md2.getSeverityLevel());
assertEquals("Logger", md2.getProperties().get("SourceType"));
assertEquals("DEBUG", md2.getProperties().get("LoggingLevel"));
assertEquals("ERROR", md2.getProperties().get("LoggingLevel"));

MessageData md3 = getTelemetryDataForType(2, "MessageData");
assertEquals("This is log4j2 info.", md3.getMessage());
assertEquals(SeverityLevel.Information, md3.getSeverityLevel());
assertEquals("This is log4j2 fatal.", md3.getMessage());
assertEquals(SeverityLevel.Critical, md3.getSeverityLevel());
assertEquals("Logger", md3.getProperties().get("SourceType"));
assertEquals("INFO", md3.getProperties().get("LoggingLevel"));

MessageData md4 = getTelemetryDataForType(3, "MessageData");
assertEquals("This is log4j2 warn.", md4.getMessage());
assertEquals(SeverityLevel.Warning, md4.getSeverityLevel());
assertEquals("Logger", md4.getProperties().get("SourceType"));
assertEquals("WARN", md4.getProperties().get("LoggingLevel"));


MessageData md5 = getTelemetryDataForType(4, "MessageData");
assertEquals("This is log4j2 error.", md5.getMessage());
assertEquals(SeverityLevel.Error, md5.getSeverityLevel());
assertEquals("Logger", md5.getProperties().get("SourceType"));
assertEquals("ERROR", md5.getProperties().get("LoggingLevel"));

MessageData md6 = getTelemetryDataForType(5, "MessageData");
assertEquals("This is log4j2 fatal.", md6.getMessage());
assertEquals(SeverityLevel.Critical, md6.getSeverityLevel());
assertEquals("Logger", md6.getProperties().get("SourceType"));
assertEquals("FATAL", md6.getProperties().get("LoggingLevel"));
assertEquals("FATAL", md3.getProperties().get("LoggingLevel"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,19 @@ public void skipJbosseap6AndJbosseap7Image() {
@Test
@TargetUri("/traceLogBack")
public void testTraceLogBack() {
assertEquals(5, mockedIngestion.getCountForType("MessageData"));
assertEquals(2, mockedIngestion.getCountForType("MessageData"));

MessageData md1 = getTelemetryDataForType(0, "MessageData");
assertEquals("This is logback trace.", md1.getMessage());
assertEquals(SeverityLevel.Verbose, md1.getSeverityLevel());
assertEquals("This is logback warn.", md1.getMessage());
assertEquals(SeverityLevel.Warning, md1.getSeverityLevel());
assertEquals("Logger", md1.getProperties().get("SourceType"));
assertEquals("TRACE", md1.getProperties().get("LoggingLevel"));
assertEquals("WARN", md1.getProperties().get("LoggingLevel"));

MessageData md2 = getTelemetryDataForType(1, "MessageData");
assertEquals("This is logback debug.", md2.getMessage());
assertEquals(SeverityLevel.Verbose, md2.getSeverityLevel());
assertEquals("This is logback error.", md2.getMessage());
assertEquals(SeverityLevel.Error, md2.getSeverityLevel());
assertEquals("Logger", md2.getProperties().get("SourceType"));
assertEquals("DEBUG", md2.getProperties().get("LoggingLevel"));

MessageData md3 = getTelemetryDataForType(2, "MessageData");
assertEquals("This is logback info.", md3.getMessage());
assertEquals(SeverityLevel.Information, md3.getSeverityLevel());
assertEquals("Logger", md3.getProperties().get("SourceType"));
assertEquals("INFO", md3.getProperties().get("LoggingLevel"));

MessageData md4 = getTelemetryDataForType(3, "MessageData");
assertEquals("This is logback warn.", md4.getMessage());
assertEquals(SeverityLevel.Warning, md4.getSeverityLevel());
assertEquals("Logger", md4.getProperties().get("SourceType"));
assertEquals("WARN", md4.getProperties().get("LoggingLevel"));

MessageData md5 = getTelemetryDataForType(4, "MessageData");
assertEquals("This is logback error.", md5.getMessage());
assertEquals(SeverityLevel.Error, md5.getSeverityLevel());
assertEquals("Logger", md5.getProperties().get("SourceType"));
assertEquals("ERROR", md5.getProperties().get("LoggingLevel"));
assertEquals("ERROR", md2.getProperties().get("LoggingLevel"));
}

@Test
Expand Down