-
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
Open
pepeshore
wants to merge
39
commits into
open-telemetry:main
Choose a base branch
from
pepeshore:feat/support-jfinal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add support for JFinal #15216
Changes from all 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
Some comments aren't visible on the classic Files Changed page.
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
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,31 @@ | ||
| plugins { | ||
| id("otel.javaagent-instrumentation") | ||
| } | ||
|
|
||
| muzzle { | ||
| pass { | ||
| group.set("com.jfinal") | ||
| module.set("jfinal") | ||
| versions.set("[3.2,)") | ||
| assertInverse.set(true) | ||
| } | ||
| } | ||
|
|
||
| if (!(findProperty("testLatestDeps") as Boolean)) { | ||
| otelJava { | ||
| // jfinal 3.2 doesn't work with Java 9+ | ||
| maxJavaVersionForTests.set(JavaVersion.VERSION_1_8) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| library("com.jfinal:jfinal:3.2") | ||
| 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") | ||
| } |
38 changes: 38 additions & 0 deletions
38
.../io/opentelemetry/javaagent/instrumentation/jfinal/v3_2/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,38 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_2; | ||
|
|
||
| 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<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.updateRoute(action); | ||
| } | ||
| } | ||
| } |
92 changes: 92 additions & 0 deletions
92
...ava/io/opentelemetry/javaagent/instrumentation/jfinal/v3_2/InvocationInstrumentation.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,92 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_2; | ||
|
|
||
| import static io.opentelemetry.javaagent.instrumentation.jfinal.v3_2.JFinalSingletons.instrumenter; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; | ||
|
|
||
| import com.jfinal.aop.Invocation; | ||
| import com.jfinal.core.Action; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.Scope; | ||
| import io.opentelemetry.instrumentation.api.incubator.semconv.util.ClassAndMethod; | ||
| import io.opentelemetry.javaagent.bootstrap.CallDepth; | ||
| 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 InvocationInstrumentation implements TypeInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return named("com.jfinal.aop.Invocation"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| named("invoke").and(takesNoArguments()), this.getClass().getName() + "$InvokeAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class InvokeAdvice { | ||
|
|
||
| public static class AdviceScope { | ||
| private final CallDepth callDepth; | ||
| private final ClassAndMethod request; | ||
| private final Context context; | ||
| private final Scope scope; | ||
|
|
||
| public AdviceScope( | ||
| CallDepth callDepth, ClassAndMethod request, Context context, Scope scope) { | ||
| this.callDepth = callDepth; | ||
| this.request = request; | ||
| this.context = context; | ||
| this.scope = scope; | ||
| } | ||
|
|
||
| public static AdviceScope start(CallDepth callDepth, Action action) { | ||
| if (callDepth.getAndIncrement() > 0 || action == null) { | ||
| return new AdviceScope(callDepth, null, null, null); | ||
| } | ||
|
|
||
| Context parentContext = Context.current(); | ||
| ClassAndMethod request = | ||
| ClassAndMethod.create(action.getControllerClass(), action.getMethodName()); | ||
| if (!instrumenter().shouldStart(parentContext, request)) { | ||
| return new AdviceScope(callDepth, null, null, null); | ||
| } | ||
|
|
||
| Context context = instrumenter().start(parentContext, request); | ||
| return new AdviceScope(callDepth, request, context, context.makeCurrent()); | ||
| } | ||
|
|
||
| public void end(@Nullable Throwable throwable) { | ||
| if (callDepth.decrementAndGet() > 0 || scope == null) { | ||
| return; | ||
| } | ||
| scope.close(); | ||
| instrumenter().end(context, request, null, throwable); | ||
| } | ||
| } | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static AdviceScope onEnter(@Advice.FieldValue("action") Action action) { | ||
| CallDepth callDepth = CallDepth.forClass(Invocation.class); | ||
| return AdviceScope.start(callDepth, action); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void stopTraceOnResponse( | ||
| @Advice.Thrown @Nullable Throwable throwable, @Advice.Enter AdviceScope actionScope) { | ||
| actionScope.end(throwable); | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
...a/io/opentelemetry/javaagent/instrumentation/jfinal/v3_2/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,43 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_2; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
| import static java.util.Arrays.asList; | ||
| import static net.bytebuddy.matcher.ElementMatchers.not; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule; | ||
| import java.util.List; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| @AutoService(InstrumentationModule.class) | ||
| public class JFinalInstrumentationModule extends InstrumentationModule | ||
| implements ExperimentalInstrumentationModule { | ||
|
|
||
| public JFinalInstrumentationModule() { | ||
| super("jfinal", "jfinal-3.2"); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
| // In version 3.2, TypeConverter is moved from com.jfinal.core | ||
| // to com.jfinal.core.converter | ||
| return not(hasClassesNamed("com.jfinal.core.TypeConverter")); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isIndyReady() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return asList(new ActionMappingInstrumentation(), new InvocationInstrumentation()); | ||
| } | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
...rc/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/v3_2/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,65 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.jfinal.v3_2; | ||
|
|
||
| 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.incubator.semconv.code.CodeAttributesExtractor; | ||
| import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter; | ||
| import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeSpanNameExtractor; | ||
| import io.opentelemetry.instrumentation.api.incubator.semconv.util.ClassAndMethod; | ||
| 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; | ||
|
|
||
| public final class JFinalSingletons { | ||
|
|
||
| private static final Instrumenter<ClassAndMethod, Void> INSTRUMENTER; | ||
|
|
||
| static { | ||
| // see | ||
| // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/11465#issuecomment-2137294837 | ||
| excludeOtAttrs(); | ||
|
|
||
| CodeAttributesGetter<ClassAndMethod> codedAttributesGetter = | ||
| ClassAndMethod.codeAttributesGetter(); | ||
| INSTRUMENTER = | ||
| Instrumenter.<ClassAndMethod, Void>builder( | ||
| GlobalOpenTelemetry.get(), | ||
| "io.opentelemetry.jfinal-3.2", | ||
| CodeSpanNameExtractor.create(codedAttributesGetter)) | ||
| .setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled()) | ||
| .addAttributesExtractor(CodeAttributesExtractor.create(codedAttributesGetter)) | ||
| .buildInstrumenter(); | ||
| } | ||
|
|
||
| public static Instrumenter<ClassAndMethod, Void> instrumenter() { | ||
| return INSTRUMENTER; | ||
| } | ||
|
|
||
| public static void updateRoute(Action action) { | ||
| if (action == null) { | ||
| return; | ||
| } | ||
| String route = action.getActionKey(); | ||
| Context context = Context.current(); | ||
| if (route != null) { | ||
| HttpServerRoute.update(context, HttpServerRouteSource.CONTROLLER, route); | ||
| } | ||
| } | ||
|
|
||
| private static void excludeOtAttrs() { | ||
| JsonRender.addExcludedAttrs( | ||
| "io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.Context", | ||
| "trace_id", | ||
| "span_id"); | ||
| } | ||
|
|
||
| private JFinalSingletons() {} | ||
| } |
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.