-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java Phase 1, Tomcat support and test. (#50)
Java Phase 1, Tomcat support and test.
- Loading branch information
Showing
8 changed files
with
156 additions
and
7 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
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
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,7 @@ | ||
plugins { | ||
id "java" | ||
} | ||
|
||
dependencies { | ||
compileOnly('org.apache.tomcat:tomcat-catalina:9.0.40') | ||
} |
78 changes: 78 additions & 0 deletions
78
.../main/java/com/splunk/opentelemetry/middleware/TomcatAttributesInstrumentationModule.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,78 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.opentelemetry.middleware; | ||
|
||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.splunk.opentelemetry.javaagent.bootstrap.MiddlewareHolder; | ||
import io.opentelemetry.javaagent.tooling.InstrumentationModule; | ||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.apache.catalina.util.ServerInfo; | ||
|
||
@AutoService(InstrumentationModule.class) | ||
public class TomcatAttributesInstrumentationModule extends InstrumentationModule { | ||
|
||
public TomcatAttributesInstrumentationModule() { | ||
super("tomcat"); | ||
} | ||
|
||
@Override | ||
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
return hasClassesNamed( | ||
"org.apache.catalina.startup.Catalina", "org.apache.catalina.util.ServerInfo"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return Collections.singletonList(new Instrumentation()); | ||
} | ||
|
||
public static class Instrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<? super TypeDescription> typeMatcher() { | ||
return named("org.apache.catalina.startup.Catalina"); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return Collections.singletonMap( | ||
isMethod().and(isPublic()).and(named("start")), | ||
TomcatAttributesInstrumentationModule.class.getName() + "$MiddlewareInitializedAdvice"); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class MiddlewareInitializedAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter() { | ||
MiddlewareHolder.trySetVersion(ServerInfo.getServerNumber()); | ||
MiddlewareHolder.trySetName("tomcat"); | ||
} | ||
} | ||
} |
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
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
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
63 changes: 63 additions & 0 deletions
63
smoke-tests/src/test/java/com/splunk/opentelemetry/TomcatSmokeTest.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,63 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.opentelemetry; | ||
|
||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import java.io.IOException; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class TomcatSmokeTest extends AppServerTest { | ||
|
||
public static final ExpectedServerAttributes TOMCAT7_SERVER_ATTRIBUTES = | ||
new TomcatAttributes("7.0.107.0"); | ||
public static final ExpectedServerAttributes TOMCAT8_SERVER_ATTRIBUTES = | ||
new TomcatAttributes("8.5.60.0"); | ||
public static final ExpectedServerAttributes TOMCAT9_SERVER_ATTRIBUTES = | ||
new TomcatAttributes("9.0.40.0"); | ||
|
||
private static Stream<Arguments> supportedConfigurations() { | ||
return Stream.of( | ||
arguments("splunk-tomcat:7-jdk8", TOMCAT7_SERVER_ATTRIBUTES), | ||
arguments("splunk-tomcat:8-jdk8", TOMCAT8_SERVER_ATTRIBUTES), | ||
arguments("splunk-tomcat:8-jdk11", TOMCAT8_SERVER_ATTRIBUTES), | ||
arguments("splunk-tomcat:9-jdk8", TOMCAT9_SERVER_ATTRIBUTES), | ||
arguments("splunk-tomcat:9-jdk11", TOMCAT9_SERVER_ATTRIBUTES)); | ||
} | ||
|
||
@ParameterizedTest(name = "[{index}] {0}") | ||
@MethodSource("supportedConfigurations") | ||
void jettySmokeTest(String imageName, ExpectedServerAttributes expectedServerAttributes) | ||
throws IOException, InterruptedException { | ||
startTarget(imageName); | ||
|
||
assertServerHandler(expectedServerAttributes); | ||
assertWebAppTrace(expectedServerAttributes); | ||
} | ||
|
||
public static class TomcatAttributes extends ExpectedServerAttributes { | ||
public TomcatAttributes(String version) { | ||
super( | ||
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless", | ||
"tomcat", | ||
version); | ||
} | ||
} | ||
} |