-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #618 from jsubirat/instrument_emitted_logs
Adds logback-classic-1.2 instrumentation
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.logback-classic-1.2' } | ||
} | ||
|
||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
implementation("ch.qos.logback:logback-classic:1.2.6") | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly("ch.qos.logback:logback-classic:[0.9.3,)") | ||
excludeRegex '.*(alpha|groovyless).*' | ||
excludeRegex 'ch.qos.logback:logback-classic:0.9.6' | ||
} | ||
|
||
site { | ||
title 'Logback' | ||
type 'Framework' | ||
} |
19 changes: 19 additions & 0 deletions
19
...2/src/main/java/com/nr/agent/instrumentation/logbackclassic12/Logger_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.nr.agent.instrumentation.logbackclassic12; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import org.slf4j.Marker; | ||
|
||
@Weave(originalName = "ch.qos.logback.classic.Logger", type = MatchType.Interface) | ||
public abstract class Logger_Instrumentation { | ||
|
||
private void buildLoggingEventAndAppend(final String localFQCN, final Marker marker, final Level level, final String msg, final Object[] params, | ||
final Throwable t) { | ||
NewRelic.incrementCounter("Logging/lines"); | ||
NewRelic.incrementCounter("Logging/lines/" + level); | ||
Weaver.callOriginal(); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...c/test/java/com/nr/agent/instrumentation/logbackclassic12/Logger_InstrumentationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.nr.agent.instrumentation.logbackclassic12; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import com.newrelic.agent.introspec.InstrumentationTestConfig; | ||
import com.newrelic.agent.introspec.InstrumentationTestRunner; | ||
import com.newrelic.agent.introspec.MetricsHelper; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@RunWith(InstrumentationTestRunner.class) | ||
@InstrumentationTestConfig(includePrefixes = { "com.nr.agent.instrumentation.logbackclassic12" }) | ||
public class Logger_InstrumentationTest { | ||
|
||
private static final String CAPTURED = "This log message should be captured"; | ||
private static final String NOT_CAPTURED = "This message should NOT be captured"; | ||
|
||
@Test | ||
public void shouldIncrementEmittedLogsCountersIndependentlyIfLogLevelEnabled() { | ||
// Given | ||
final Logger logger = (Logger) LoggerFactory.getLogger(Logger_InstrumentationTest.class); | ||
logger.setLevel(Level.INFO); | ||
|
||
// When | ||
logger.trace(NOT_CAPTURED); | ||
logger.debug(NOT_CAPTURED); | ||
logger.info(CAPTURED); | ||
logger.info(CAPTURED); | ||
logger.info(CAPTURED); | ||
logger.warn(CAPTURED); | ||
logger.warn(CAPTURED); | ||
logger.warn(CAPTURED); | ||
logger.warn(CAPTURED); | ||
logger.error(CAPTURED); | ||
|
||
// Then | ||
Assert.assertEquals(8, MetricsHelper.getUnscopedMetricCount("Logging/lines")); | ||
Assert.assertEquals(0, MetricsHelper.getUnscopedMetricCount("Logging/lines/TRACE")); | ||
Assert.assertEquals(0, MetricsHelper.getUnscopedMetricCount("Logging/lines/DEBUG")); | ||
Assert.assertEquals(3, MetricsHelper.getUnscopedMetricCount("Logging/lines/INFO")); | ||
Assert.assertEquals(4, MetricsHelper.getUnscopedMetricCount("Logging/lines/WARN")); | ||
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("Logging/lines/ERROR")); | ||
} | ||
|
||
@Test | ||
public void shouldIncrementAllEmittedLogCountersIfLogLevelIsSetToTrace() { | ||
// Given | ||
final Logger logger = (Logger) LoggerFactory.getLogger(Logger_InstrumentationTest.class); | ||
logger.setLevel(Level.TRACE); | ||
|
||
// When | ||
logger.trace(CAPTURED); | ||
logger.debug(CAPTURED); | ||
logger.info(CAPTURED); | ||
logger.warn(CAPTURED); | ||
logger.error(CAPTURED); | ||
|
||
// Then | ||
Assert.assertEquals(5, MetricsHelper.getUnscopedMetricCount("Logging/lines")); | ||
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("Logging/lines/TRACE")); | ||
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("Logging/lines/DEBUG")); | ||
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("Logging/lines/INFO")); | ||
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("Logging/lines/WARN")); | ||
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("Logging/lines/ERROR")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters