Skip to content

Commit 2719ab6

Browse files
authored
Support for WildFly version detection (#57)
* Support for WildFly version detection * Format * Better test name * Instrument ServerEnvironment
1 parent 97aa445 commit 2719ab6

File tree

6 files changed

+169
-1
lines changed

6 files changed

+169
-1
lines changed

instrumentation/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ subprojects {
1212
dependencies {
1313
compileOnly("io.opentelemetry:opentelemetry-sdk:${versions.opentelemetry}")
1414
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagent}")
15+
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-api:${versions.opentelemetryJavaagent}")
1516
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-spi:${versions.opentelemetryJavaagent}")
1617
compileOnly("net.bytebuddy:byte-buddy:1.10.10")
1718
annotationProcessor("com.google.auto.service:auto-service:1.0-rc3")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id "java"
3+
}
4+
5+
dependencies {
6+
compileOnly('org.wildfly.core:wildfly-version:13.0.0.Final')
7+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright Splunk Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.splunk.opentelemetry.middleware;
18+
19+
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
20+
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
21+
import static net.bytebuddy.matcher.ElementMatchers.named;
22+
23+
import com.google.auto.service.AutoService;
24+
import com.splunk.opentelemetry.javaagent.bootstrap.MiddlewareHolder;
25+
import io.opentelemetry.javaagent.instrumentation.api.CallDepthThreadLocalMap;
26+
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
27+
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
28+
import java.util.Collections;
29+
import java.util.List;
30+
import java.util.Map;
31+
import net.bytebuddy.asm.Advice;
32+
import net.bytebuddy.description.method.MethodDescription;
33+
import net.bytebuddy.description.type.TypeDescription;
34+
import net.bytebuddy.matcher.ElementMatcher;
35+
import org.jboss.as.version.ProductConfig;
36+
37+
@AutoService(InstrumentationModule.class)
38+
public class WildFlyAttributesInstrumentationModule extends InstrumentationModule {
39+
40+
public WildFlyAttributesInstrumentationModule() {
41+
super("wildfly");
42+
}
43+
44+
@Override
45+
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
46+
return hasClassesNamed("org.jboss.as.version.ProductConfig");
47+
}
48+
49+
@Override
50+
public List<TypeInstrumentation> typeInstrumentations() {
51+
return Collections.singletonList(new Instrumentation());
52+
}
53+
54+
public static class Instrumentation implements TypeInstrumentation {
55+
56+
@Override
57+
public ElementMatcher<? super TypeDescription> typeMatcher() {
58+
return named("org.jboss.as.server.ServerEnvironment");
59+
}
60+
61+
@Override
62+
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
63+
return Collections.singletonMap(
64+
isConstructor(),
65+
WildFlyAttributesInstrumentationModule.class.getName() + "$MiddlewareInitializedAdvice");
66+
}
67+
}
68+
69+
@SuppressWarnings("unused")
70+
public static class MiddlewareInitializedAdvice {
71+
@Advice.OnMethodEnter
72+
public static void onEnter() {
73+
CallDepthThreadLocalMap.incrementCallDepth(ProductConfig.class);
74+
}
75+
76+
@Advice.OnMethodExit(suppress = Throwable.class)
77+
public static void onExit(@Advice.FieldValue("productConfig") ProductConfig productConfig) {
78+
if (CallDepthThreadLocalMap.decrementCallDepth(ProductConfig.class) == 0
79+
&& productConfig != null) {
80+
MiddlewareHolder.trySetName(productConfig.resolveName());
81+
MiddlewareHolder.trySetVersion(productConfig.resolveVersion());
82+
}
83+
}
84+
}
85+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ include("agent",
1818
"instrumentation:glassfish",
1919
"instrumentation:liberty",
2020
"instrumentation:tomcat",
21+
"instrumentation:wildfly",
2122
"smoke-tests",
2223
"matrix")

smoke-tests/src/test/java/com/splunk/opentelemetry/GlassFishSmokeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected Map<String, String> getExtraEnv() {
5454
@Override
5555
protected WaitStrategy getWaitStrategy() {
5656
return Wait.forLogMessage(".*app was successfully deployed.*", 1)
57-
.withStartupTimeout(Duration.ofMinutes(15));
57+
.withStartupTimeout(Duration.ofMinutes(5));
5858
}
5959

6060
@ParameterizedTest
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright Splunk Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.splunk.opentelemetry;
18+
19+
import static org.junit.jupiter.params.provider.Arguments.arguments;
20+
21+
import java.io.IOException;
22+
import java.util.stream.Stream;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.Arguments;
25+
import org.junit.jupiter.params.provider.MethodSource;
26+
27+
public class WildFlySmokeTest extends AppServerTest {
28+
29+
public static final ExpectedServerAttributes WILDFLY_13_SERVER_ATTRIBUTES =
30+
new ExpectedServerAttributes(
31+
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless",
32+
"WildFly Full",
33+
"13.0.0.Final");
34+
public static final ExpectedServerAttributes WILDFLY_17_SERVER_ATTRIBUTES =
35+
new ExpectedServerAttributes(
36+
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless",
37+
"WildFly Full",
38+
"17.0.1.Final");
39+
public static final ExpectedServerAttributes WILDFLY_21_SERVER_ATTRIBUTES =
40+
new ExpectedServerAttributes(
41+
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless",
42+
"WildFly Full",
43+
"21.0.0.Final");
44+
45+
private static Stream<Arguments> supportedConfigurations() {
46+
return Stream.of(
47+
arguments(
48+
"ghcr.io/open-telemetry/java-test-containers:wildfly-13.0.0.Final-jdk8-20201207.405832649",
49+
WILDFLY_13_SERVER_ATTRIBUTES),
50+
arguments(
51+
"ghcr.io/open-telemetry/java-test-containers:wildfly-17.0.1.Final-jdk8-20201207.405832649",
52+
WILDFLY_17_SERVER_ATTRIBUTES),
53+
arguments(
54+
"ghcr.io/open-telemetry/java-test-containers:wildfly-17.0.1.Final-jdk11-20201207.405832649",
55+
WILDFLY_17_SERVER_ATTRIBUTES),
56+
arguments(
57+
"ghcr.io/open-telemetry/java-test-containers:wildfly-21.0.0.Final-jdk8-20201207.405832649",
58+
WILDFLY_21_SERVER_ATTRIBUTES),
59+
arguments(
60+
"ghcr.io/open-telemetry/java-test-containers:wildfly-21.0.0.Final-jdk11-20201207.405832649",
61+
WILDFLY_21_SERVER_ATTRIBUTES));
62+
}
63+
64+
@ParameterizedTest(name = "[{index}] {0}")
65+
@MethodSource("supportedConfigurations")
66+
void wildflySmokeTest(String imageName, ExpectedServerAttributes expectedServerAttributes)
67+
throws IOException, InterruptedException {
68+
startTarget(imageName);
69+
70+
// TODO support 404
71+
// assertServerHandler(expectedServerAttributes);
72+
assertWebAppTrace(expectedServerAttributes);
73+
}
74+
}

0 commit comments

Comments
 (0)