Skip to content

Commit a9005e1

Browse files
authored
added preventing the shade plugin from relocating org.slf4j.Logger to *.shaded.slf4j.Logger (#1049)
1 parent b09e711 commit a9005e1

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ endif::[]
3737
[float]
3838
===== Bug fixes
3939
* When JAX-RS-annotated method delegates to another JAX-RS-annotated method, transaction name should include method A - {pull}1062[#1062]
40+
* Fixed bug that prevented an APM Error from being created when calling `org.slf4j.Logger#error` - {pull}1049[#1049]
4041
4142
[[release-notes-1.x]]
4243
=== Java Agent version 1.x

apm-agent-plugins/apm-error-logging-plugin/src/main/java/co/elastic/apm/agent/error/logging/Log4jLoggingInstrumentation.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* the Apache License, Version 2.0 (the "License"); you may
1212
* not use this file except in compliance with the License.
1313
* You may obtain a copy of the License at
14-
*
14+
*
1515
* http://www.apache.org/licenses/LICENSE-2.0
16-
*
16+
*
1717
* Unless required by applicable law or agreed to in writing,
1818
* software distributed under the License is distributed on an
1919
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -35,9 +35,12 @@
3535

3636
public class Log4jLoggingInstrumentation extends AbstractLoggingInstrumentation {
3737

38+
// prevents the shade plugin from relocating org.slf4j.Logger to co.elastic.apm.agent.shaded.slf4j.Logger
39+
private static final String SLF4J_LOGGER = "org!slf4j!Logger".replace('!', '.');
40+
3841
@Override
3942
public ElementMatcher<? super TypeDescription> getTypeMatcher() {
40-
return hasSuperType(named("org.apache.logging.log4j.Logger")).and(not(hasSuperType(named("org.slf4j.Logger"))));
43+
return hasSuperType(named("org.apache.logging.log4j.Logger")).and(not(hasSuperType(named(SLF4J_LOGGER))));
4144
}
4245

4346
@Override

apm-agent-plugins/apm-error-logging-plugin/src/main/java/co/elastic/apm/agent/error/logging/Slf4jLoggingInstrumentation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* the Apache License, Version 2.0 (the "License"); you may
1212
* not use this file except in compliance with the License.
1313
* You may obtain a copy of the License at
14-
*
14+
*
1515
* http://www.apache.org/licenses/LICENSE-2.0
16-
*
16+
*
1717
* Unless required by applicable law or agreed to in writing,
1818
* software distributed under the License is distributed on an
1919
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -35,9 +35,13 @@
3535

3636
public class Slf4jLoggingInstrumentation extends AbstractLoggingInstrumentation {
3737

38+
// prevents the shade plugin from relocating org.slf4j.Logger to co.elastic.apm.agent.shaded.slf4j.Logger
39+
private static final String SLF4J_LOGGER = "org!slf4j!Logger".replace('!', '.');
40+
3841
@Override
3942
public ElementMatcher<? super TypeDescription> getTypeMatcher() {
40-
return hasSuperType(named("org.slf4j.Logger")).and(not(hasSuperType(named("org.apache.logging.log4j.Logger"))));
43+
return hasSuperType(named(SLF4J_LOGGER)
44+
.and(not(hasSuperType(named("org.apache.logging.log4j.Logger")))));
4145
}
4246

4347
@Override

apm-agent-plugins/apm-error-logging-plugin/src/test/java/co/elastic/apm/agent/error/logging/Slf4jLoggingInstrumentationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* the Apache License, Version 2.0 (the "License"); you may
1212
* not use this file except in compliance with the License.
1313
* You may obtain a copy of the License at
14-
*
14+
*
1515
* http://www.apache.org/licenses/LICENSE-2.0
16-
*
16+
*
1717
* Unless required by applicable law or agreed to in writing,
1818
* software distributed under the License is distributed on an
1919
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

0 commit comments

Comments
 (0)