-
Notifications
You must be signed in to change notification settings - Fork 1k
Add support for JFinal #15216
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
Merged
Merged
Add support for JFinal #15216
Changes from 22 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
8282947
feat: support parse oceanbase、lindorm、polardb、opentracing connection url
pepeshore d0acc07
Merge branch 'open-telemetry:main' into feature/additonal-jdbc-url-pa…
pepeshore 4251ef4
delete test main method
pepeshore 8d79717
./gradlew spotlessApply
otelbot[bot] a4a325f
fix:fix some code comments
pepeshore 28c2324
Merge remote-tracking branch 'origin/feature/additonal-jdbc-url-parse…
pepeshore e5d0f3c
Optimized the comments for OceanBase url parser
pepeshore ae6a467
./gradlew spotlessApply
otelbot[bot] 660f26b
delete url parameter
pepeshore 548e0df
Merge remote-tracking branch 'origin/feature/additonal-jdbc-url-parse…
pepeshore 73286f8
./gradlew spotlessApply
otelbot[bot] 87105b6
Merge branch 'main' into feature/additonal-jdbc-url-parser
laurit 92a0e4c
review
laurit 3bd593a
feat:support JFinal framework
pepeshore 7ab2d87
./gradlew spotlessApply
otelbot[bot] eebb74c
Merge branch 'main' into feat/support-jfinal
pepeshore de238a4
fix:fix failing check
pepeshore fed5680
Merge remote-tracking branch 'origin/feat/support-jfinal' into feat/s…
pepeshore 63b2d8f
refactor:update package name & remove useless dependency and code
pepeshore 85cc395
./gradlew spotlessApply
otelbot[bot] 5f55199
refactor:delete useless code
pepeshore f61ac70
Merge remote-tracking branch 'origin/feat/support-jfinal' into feat/s…
pepeshore 3602e5b
refactor: improve JFinal instrumentation implementation
pepeshore 2e9cf76
./gradlew spotlessApply
otelbot[bot] 85ce47f
refactor: optimize ActionHandlerInstrumentation implementation
pepeshore 8516299
refactor: rename jfinal-3.6 to jfinal-3.2 and update package references
pepeshore 98e6131
./gradlew spotlessApply
otelbot[bot] 59d8140
refactor: update JFinal instrumentation configuration
pepeshore 9e6f362
./gradlew spotlessApply
otelbot[bot] c233117
chore: update FOSSA configuration for JFinal instrumentation
pepeshore be1073e
Merge branch 'main' into feat/support-jfinal
steverao 47a29a7
docs: add comment explaining TypeConverter version check in JFinal in…
pepeshore 95f7b99
enable redirect test
laurit 64fb545
remove try catch
laurit 94def77
test with 3.2
laurit f4d8fc8
mark indy ready
laurit d381462
Record code attributes for the controller span
laurit 3338786
Merge branch 'main' into feat/support-jfinal
laurit d60533b
Apply suggestions from code review
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,29 @@ | ||
| plugins { | ||
| id("otel.javaagent-instrumentation") | ||
| } | ||
|
|
||
| muzzle { | ||
| pass { | ||
| group.set("com.jfinal") | ||
| module.set("jfinal") | ||
| versions.set("[3.6,)") | ||
| assertInverse.set(true) | ||
| } | ||
| } | ||
|
|
||
| otelJava { | ||
| // jfinal doesn't work with Java 9+ | ||
| maxJavaVersionForTests.set(JavaVersion.VERSION_1_8) | ||
| } | ||
|
|
||
| dependencies { | ||
| library("com.jfinal:jfinal:3.6") | ||
| testLibrary("com.jfinal:jetty-server:2019.3") | ||
| testInstrumentation(project(":instrumentation:jetty:jetty-8.0:javaagent")) | ||
| testInstrumentation(project(":instrumentation:jetty:jetty-11.0:javaagent")) | ||
| testInstrumentation(project(":instrumentation:jetty:jetty-common:javaagent")) | ||
| } | ||
|
|
||
| tasks.withType<Test>().configureEach { | ||
| jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true") | ||
| } | ||
90 changes: 90 additions & 0 deletions
90
.../io/opentelemetry/javaagent/instrumentation/jfinal/v3_6/ActionHandlerInstrumentation.java
This file contains hidden or 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,90 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_6; | ||
|
|
||
| import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; | ||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
| import static io.opentelemetry.javaagent.instrumentation.jfinal.v3_6.JFinalSingletons.instrumenter; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
|
||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.Scope; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import javax.annotation.Nullable; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| public class ActionHandlerInstrumentation implements TypeInstrumentation { | ||
| @Override | ||
| public ElementMatcher<ClassLoader> classLoaderOptimization() { | ||
| return hasClassesNamed("com.jfinal.core.ActionHandler"); | ||
| } | ||
pepeshore marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return named("com.jfinal.core.ActionHandler"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| named("handle") | ||
| .and( | ||
| takesArguments(4) | ||
| .and(takesArgument(0, String.class)) | ||
| .and(takesArgument(1, named("javax.servlet.http.HttpServletRequest"))) | ||
| .and(takesArgument(2, named("javax.servlet.http.HttpServletResponse"))) | ||
| .and(takesArgument(3, boolean[].class))), | ||
| this.getClass().getName() + "$HandleAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class HandleAdvice { | ||
|
|
||
| public static class AdviceScope { | ||
| private final Context context; | ||
| private final Scope scope; | ||
|
|
||
| public AdviceScope(Context context, Scope scope) { | ||
| this.context = context; | ||
| this.scope = scope; | ||
| } | ||
|
|
||
| @Nullable | ||
| public static AdviceScope start(Context parentContext) { | ||
| if (!instrumenter().shouldStart(parentContext, null)) { | ||
| return null; | ||
| } | ||
|
|
||
| Context context = instrumenter().start(parentContext, null); | ||
| return new AdviceScope(context, context.makeCurrent()); | ||
| } | ||
|
|
||
| public void end(@Nullable Throwable throwable) { | ||
| scope.close(); | ||
| instrumenter().end(context, null, null, throwable); | ||
| } | ||
| } | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static AdviceScope onEnter() { | ||
| return AdviceScope.start(currentContext()); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void stopTraceOnResponse( | ||
| @Advice.Thrown @Nullable Throwable throwable, | ||
| @Advice.Enter @Nullable AdviceScope actionScope) { | ||
| if (actionScope != null) { | ||
| actionScope.end(throwable); | ||
| } | ||
| } | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
.../io/opentelemetry/javaagent/instrumentation/jfinal/v3_6/ActionMappingInstrumentation.java
This file contains hidden or 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,43 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_6; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
|
||
| import com.jfinal.core.Action; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| public class ActionMappingInstrumentation implements TypeInstrumentation { | ||
| @Override | ||
| public ElementMatcher<ClassLoader> classLoaderOptimization() { | ||
| return hasClassesNamed("com.jfinal.core.ActionMapping"); | ||
| } | ||
pepeshore marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return named("com.jfinal.core.ActionMapping"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| named("getAction"), this.getClass().getName() + "$GetActionAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class GetActionAdvice { | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void exitGetAction(@Advice.Return Action action) { | ||
| JFinalSingletons.updateSpan(action); | ||
| } | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
...a/io/opentelemetry/javaagent/instrumentation/jfinal/v3_6/JFinalInstrumentationModule.java
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_6; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| @AutoService(InstrumentationModule.class) | ||
| public class JFinalInstrumentationModule extends InstrumentationModule { | ||
| public JFinalInstrumentationModule() { | ||
| super("jfinal", "jfinal-3.6"); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
| return hasClassesNamed("com.jfinal.core.ActionMapping"); | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return Arrays.asList(new ActionMappingInstrumentation(), new ActionHandlerInstrumentation()); | ||
pepeshore marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
...rc/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/v3_6/JFinalSingletons.java
This file contains hidden or 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,64 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_6; | ||
|
|
||
| import com.jfinal.core.Action; | ||
| import com.jfinal.render.JsonRender; | ||
| import io.opentelemetry.api.GlobalOpenTelemetry; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
| import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; | ||
| import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource; | ||
| import io.opentelemetry.javaagent.bootstrap.internal.ExperimentalConfig; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| public final class JFinalSingletons { | ||
|
|
||
| private static final Logger logger = Logger.getLogger(JFinalSingletons.class.getName()); | ||
|
|
||
| private static final String SPAN_NAME = "jfinal.handle"; | ||
| private static final Instrumenter<Void, Void> INSTRUMENTER = | ||
| Instrumenter.<Void, Void>builder( | ||
| GlobalOpenTelemetry.get(), "io.opentelemetry.jfinal-3.6", s -> SPAN_NAME) | ||
| .setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled()) | ||
| .buildInstrumenter(); | ||
|
|
||
| static { | ||
| // see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/11465 | ||
pepeshore marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| excludeOtAttrs(); | ||
| } | ||
|
|
||
| public static Instrumenter<Void, Void> instrumenter() { | ||
| return INSTRUMENTER; | ||
| } | ||
|
|
||
| public static void updateSpan(Action action) { | ||
| if (action == null) { | ||
| return; | ||
| } | ||
| String route = action.getActionKey(); | ||
| if (route == null) { | ||
| return; | ||
| } | ||
| Context context = Context.current(); | ||
| HttpServerRoute.update(context, HttpServerRouteSource.CONTROLLER, route); | ||
| } | ||
|
|
||
| private static void excludeOtAttrs() { | ||
| try { | ||
| JsonRender.addExcludedAttrs( | ||
| "io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.AsyncListenerResponse", | ||
pepeshore marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.Context", | ||
| "trace_id", | ||
| "span_id"); | ||
| } catch (Throwable t) { | ||
| logger.log(Level.INFO, "exclude failed", t); | ||
| } | ||
| } | ||
|
|
||
| private JFinalSingletons() {} | ||
| } | ||
107 changes: 107 additions & 0 deletions
107
...javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jfinal/JFinalTest.java
This file contains hidden or 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,107 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal; | ||
|
|
||
| import static io.opentelemetry.api.trace.SpanKind.INTERNAL; | ||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; | ||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.jfinal.core.JFinalFilter; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.trace.SpanKind; | ||
| import io.opentelemetry.instrumentation.api.internal.HttpConstants; | ||
| import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
| import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||
| import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; | ||
| import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; | ||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||
| import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; | ||
| import java.util.EnumSet; | ||
| import javax.servlet.DispatcherType; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.servlet.FilterHolder; | ||
| import org.eclipse.jetty.servlet.ServletContextHandler; | ||
| import org.eclipse.jetty.servlet.ServletHandler; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| public class JFinalTest extends AbstractHttpServerTest<Server> { | ||
|
|
||
| @RegisterExtension | ||
| static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent(); | ||
|
|
||
| @Override | ||
| protected void configure(HttpServerTestOptions options) { | ||
| // In the redirection scenario, the current test case fails to pass. | ||
| // Modifying the logic of AbstractHttpServerTest to address this would | ||
| // entail significant risk; therefore, we will temporarily skip validation | ||
| // for this scenario. | ||
| // | ||
| // actual span relationship: expecting span relationship | ||
| // GET /redirect GET /redirect | ||
| // |---jfinal.handle |---jfinal.handle | ||
| // |---controller |---controller | ||
| // |---Response.sendRedirect |---Response.sendRedirect | ||
| // | ||
| options.setTestRedirect(false); | ||
| options.setHasHandlerSpan(unused -> true); | ||
| options.setExpectedHttpRoute( | ||
| (endpoint, method) -> { | ||
| if (endpoint == ServerEndpoint.PATH_PARAM) { | ||
| return "/path/123/param"; | ||
| } | ||
| if (HttpConstants._OTHER.equals(method)) { | ||
| return endpoint.getPath(); | ||
| } | ||
| if (NOT_FOUND.equals(endpoint)) { | ||
| return "/*"; | ||
| } | ||
| return expectedHttpRoute(endpoint, method); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| protected Server setupServer() throws Exception { | ||
| Server server = new Server(port); | ||
|
|
||
| ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); | ||
| context.setContextPath("/"); | ||
| ServletHandler handler = new ServletHandler(); | ||
|
|
||
| FilterHolder fh = | ||
| handler.addFilterWithMapping( | ||
| JFinalFilter.class.getName(), "/*", EnumSet.of(DispatcherType.REQUEST)); | ||
| fh.setInitParameter("configClass", TestConfig.class.getName()); | ||
|
|
||
| context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST)); | ||
| context.insertHandler(handler); | ||
| server.setHandler(context); | ||
| server.start(); | ||
| return server; | ||
| } | ||
|
|
||
| @Override | ||
| protected void stopServer(Server server) throws Exception { | ||
| server.stop(); | ||
| } | ||
|
|
||
| @Override | ||
| protected SpanDataAssert assertResponseSpan( | ||
| SpanDataAssert span, String method, ServerEndpoint endpoint) { | ||
| if (endpoint == REDIRECT) { | ||
| span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect")); | ||
| } | ||
| span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty); | ||
| return span; | ||
| } | ||
|
|
||
| @Override | ||
| public SpanDataAssert assertHandlerSpan( | ||
| SpanDataAssert span, String method, ServerEndpoint endpoint) { | ||
| span.hasName("jfinal.handle").hasKind(INTERNAL); | ||
pepeshore marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return span; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.