Skip to content

Commit 7ab2d87

Browse files
committed
./gradlew spotlessApply
1 parent 3bd593a commit 7ab2d87

File tree

7 files changed

+115
-77
lines changed

7 files changed

+115
-77
lines changed

instrumentation/jfinal-3.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/ActionHandlerInstrumentation.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.javaagent.instrumentation.jfinal;
27

8+
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
9+
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
10+
import static io.opentelemetry.javaagent.instrumentation.jfinal.JFinalSingletons.instrumenter;
11+
import static net.bytebuddy.matcher.ElementMatchers.named;
12+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
13+
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
14+
315
import io.opentelemetry.context.Context;
416
import io.opentelemetry.context.Scope;
517
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
618
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
19+
import javax.annotation.Nullable;
720
import net.bytebuddy.asm.Advice;
821
import net.bytebuddy.description.type.TypeDescription;
922
import net.bytebuddy.matcher.ElementMatcher;
1023

11-
12-
import javax.annotation.Nullable;
13-
14-
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
15-
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
16-
import static io.opentelemetry.javaagent.instrumentation.jfinal.JFinalSingletons.instrumenter;
17-
import static net.bytebuddy.matcher.ElementMatchers.named;
18-
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
19-
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
20-
2124
public class ActionHandlerInstrumentation implements TypeInstrumentation {
2225
@Override
2326
public ElementMatcher<ClassLoader> classLoaderOptimization() {
@@ -32,11 +35,13 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3235
@Override
3336
public void transform(TypeTransformer transformer) {
3437
transformer.applyAdviceToMethod(
35-
named("handle").and(takesArguments(4)
36-
.and(takesArgument(0, String.class))
37-
.and(takesArgument(1, named("javax.servlet.http.HttpServletRequest")))
38-
.and(takesArgument(2, named("javax.servlet.http.HttpServletResponse")))
39-
.and(takesArgument(3, boolean[].class))),
38+
named("handle")
39+
.and(
40+
takesArguments(4)
41+
.and(takesArgument(0, String.class))
42+
.and(takesArgument(1, named("javax.servlet.http.HttpServletRequest")))
43+
.and(takesArgument(2, named("javax.servlet.http.HttpServletResponse")))
44+
.and(takesArgument(3, boolean[].class))),
4045
this.getClass().getName() + "$HandleAdvice");
4146
}
4247

@@ -62,23 +67,20 @@ public static AdviceScope start(Context parentContext) {
6267
return new AdviceScope(context, context.makeCurrent());
6368
}
6469

65-
public void end(
66-
@Nullable Throwable throwable) {
70+
public void end(@Nullable Throwable throwable) {
6771
scope.close();
6872
instrumenter().end(context, null, null, throwable);
6973
}
7074
}
7175

72-
7376
@Advice.OnMethodEnter(suppress = Throwable.class)
7477
public static HandleAdvice.AdviceScope onEnter() {
7578
return HandleAdvice.AdviceScope.start(currentContext());
7679
}
7780

7881
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
7982
public static void stopTraceOnResponse(
80-
@Advice.Thrown Throwable throwable,
81-
@Advice.Enter @Nullable AdviceScope actionScope) {
83+
@Advice.Thrown Throwable throwable, @Advice.Enter @Nullable AdviceScope actionScope) {
8284
if (actionScope == null) {
8385
return;
8486
}

instrumentation/jfinal-3.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/ActionMappingInstrumentation.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
package io.opentelemetry.javaagent.instrumentation.jfinal;
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
25

6+
package io.opentelemetry.javaagent.instrumentation.jfinal;
37

48
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
59
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -11,7 +15,6 @@
1115
import net.bytebuddy.description.type.TypeDescription;
1216
import net.bytebuddy.matcher.ElementMatcher;
1317

14-
1518
public class ActionMappingInstrumentation implements TypeInstrumentation {
1619
@Override
1720
public ElementMatcher<ClassLoader> classLoaderOptimization() {
@@ -26,16 +29,14 @@ public ElementMatcher<TypeDescription> typeMatcher() {
2629
@Override
2730
public void transform(TypeTransformer transformer) {
2831
transformer.applyAdviceToMethod(
29-
named("getAction"),
30-
this.getClass().getName() + "$GetActionAdvice");
32+
named("getAction"), this.getClass().getName() + "$GetActionAdvice");
3133
}
3234

3335
@SuppressWarnings("unused")
3436
public static class GetActionAdvice {
3537

3638
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
37-
public static void existGetAction(
38-
@Advice.Return(readOnly = false) Action action) {
39+
public static void existGetAction(@Advice.Return(readOnly = false) Action action) {
3940
JFinalSingletons.updateSpan(action);
4041
}
4142
}

instrumentation/jfinal-3.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/JFinalInstrumentationModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.javaagent.instrumentation.jfinal;
27

38
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;

instrumentation/jfinal-3.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/JFinalSingletons.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.javaagent.instrumentation.jfinal;
27

38
import com.jfinal.core.Action;
@@ -23,7 +28,7 @@ public final class JFinalSingletons {
2328
.buildInstrumenter();
2429

2530
static {
26-
//see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/11465
31+
// see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/11465
2732
excludeOtAttrs();
2833
}
2934

instrumentation/jfinal-3.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jfinal/JFinalTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.javaagent.instrumentation.jfinal;
27

38
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
@@ -62,13 +67,13 @@ protected void configure(HttpServerTestOptions options) {
6267
protected Server setupServer() throws Exception {
6368
Server server = new Server(port);
6469

65-
ServletContextHandler context = new ServletContextHandler(
66-
ServletContextHandler.SESSIONS);
70+
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
6771
context.setContextPath("/");
6872
ServletHandler handler = new ServletHandler();
6973

70-
FilterHolder fh = handler.addFilterWithMapping(
71-
JFinalFilter.class.getName(), "/*", EnumSet.of(DispatcherType.REQUEST));
74+
FilterHolder fh =
75+
handler.addFilterWithMapping(
76+
JFinalFilter.class.getName(), "/*", EnumSet.of(DispatcherType.REQUEST));
7277
fh.setInitParameter("configClass", TestConfig.class.getName());
7378

7479
context.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST));
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.javaagent.instrumentation.jfinal;
27

38
import com.jfinal.config.Constants;
@@ -8,7 +13,7 @@
813
import com.jfinal.config.Routes;
914
import com.jfinal.template.Engine;
1015

11-
public class TestConfig extends JFinalConfig {
16+
public class TestConfig extends JFinalConfig {
1217
// 配置常量值
1318
@Override
1419
public void configConstant(Constants me) {
@@ -22,18 +27,14 @@ public void configRoute(Routes me) {
2227
}
2328

2429
@Override
25-
public void configEngine(Engine me) {
26-
}
30+
public void configEngine(Engine me) {}
2731

2832
@Override
29-
public void configPlugin(Plugins me) {
30-
}
33+
public void configPlugin(Plugins me) {}
3134

3235
@Override
33-
public void configInterceptor(Interceptors me) {
34-
}
36+
public void configInterceptor(Interceptors me) {}
3537

3638
@Override
37-
public void configHandler(Handlers me) {
38-
}
39+
public void configHandler(Handlers me) {}
3940
}
Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.javaagent.instrumentation.jfinal;
27

8+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
9+
310
import com.jfinal.core.ActionKey;
411
import com.jfinal.core.Controller;
512
import com.jfinal.render.TextRender;
613
import io.opentelemetry.api.trace.Span;
714
import io.opentelemetry.instrumentation.testing.GlobalTraceUtil;
815
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
916

10-
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
11-
1217
public class TestController extends Controller {
1318

1419
public void success() {
@@ -21,62 +26,74 @@ public void redirect() {
2126

2227
@ActionKey("error-status")
2328
public void error() throws Exception {
24-
GlobalTraceUtil.runWithSpan("controller",
25-
() -> renderError(500, new TextRender(ServerEndpoint.ERROR.getBody())));
29+
GlobalTraceUtil.runWithSpan(
30+
"controller", () -> renderError(500, new TextRender(ServerEndpoint.ERROR.getBody())));
2631
}
2732

2833
public void exception() throws Throwable {
2934
try {
30-
GlobalTraceUtil.runWithSpan("controller", () -> {
31-
// renderError(500, new TextRender(ServerEndpoint.EXCEPTION.getBody()));
32-
throw new IllegalStateException(EXCEPTION.getBody());
33-
});
35+
GlobalTraceUtil.runWithSpan(
36+
"controller",
37+
() -> {
38+
// renderError(500, new TextRender(ServerEndpoint.EXCEPTION.getBody()));
39+
throw new IllegalStateException(EXCEPTION.getBody());
40+
});
3441
} catch (Throwable t) {
3542
Span.current().recordException(t);
3643
throw t;
3744
}
3845
}
3946

4047
public void captureHeaders() {
41-
GlobalTraceUtil.runWithSpan("controller", () -> {
42-
String header = getHeader("X-Test-Request");
43-
getResponse().setHeader("X-Test-Response", header);
44-
renderText(ServerEndpoint.CAPTURE_HEADERS.getBody());
45-
});
48+
GlobalTraceUtil.runWithSpan(
49+
"controller",
50+
() -> {
51+
String header = getHeader("X-Test-Request");
52+
getResponse().setHeader("X-Test-Response", header);
53+
renderText(ServerEndpoint.CAPTURE_HEADERS.getBody());
54+
});
4655
}
4756

4857
public void captureParameters() {
49-
GlobalTraceUtil.runWithSpan("controller", () -> {
50-
renderText(ServerEndpoint.CAPTURE_PARAMETERS.getBody());
51-
});
58+
GlobalTraceUtil.runWithSpan(
59+
"controller",
60+
() -> {
61+
renderText(ServerEndpoint.CAPTURE_PARAMETERS.getBody());
62+
});
5263
}
5364

5465
public void query() {
5566

56-
GlobalTraceUtil.runWithSpan("controller", () -> {
57-
renderText(ServerEndpoint.QUERY_PARAM.getBody());
58-
});
67+
GlobalTraceUtil.runWithSpan(
68+
"controller",
69+
() -> {
70+
renderText(ServerEndpoint.QUERY_PARAM.getBody());
71+
});
5972
}
6073

6174
@ActionKey("path/123/param")
6275
public void pathVar() {
63-
GlobalTraceUtil.runWithSpan("controller", () -> {
64-
renderText(ServerEndpoint.PATH_PARAM.getBody());
65-
});
66-
76+
GlobalTraceUtil.runWithSpan(
77+
"controller",
78+
() -> {
79+
renderText(ServerEndpoint.PATH_PARAM.getBody());
80+
});
6781
}
6882

69-
7083
public void authRequired() {
71-
GlobalTraceUtil.runWithSpan("controller", () -> {
72-
renderText(ServerEndpoint.AUTH_REQUIRED.getBody());
73-
});
84+
GlobalTraceUtil.runWithSpan(
85+
"controller",
86+
() -> {
87+
renderText(ServerEndpoint.AUTH_REQUIRED.getBody());
88+
});
7489
}
7590

7691
public void login() {
77-
GlobalTraceUtil.runWithSpan("controller", () -> {
78-
redirect(ServerEndpoint.LOGIN.getBody());
79-
});
92+
GlobalTraceUtil.runWithSpan(
93+
"controller",
94+
() -> {
95+
redirect(ServerEndpoint.LOGIN.getBody());
96+
});
8097
}
8198

8299
@ActionKey("basicsecured/endpoint(")
@@ -85,12 +102,14 @@ public void basicsecured_endpoint() {
85102
}
86103

87104
public void child() {
88-
GlobalTraceUtil.runWithSpan("controller", () -> {
89-
ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(name -> {
90-
return getPara(name);
91-
});
92-
renderText(ServerEndpoint.INDEXED_CHILD.getBody());
93-
});
105+
GlobalTraceUtil.runWithSpan(
106+
"controller",
107+
() -> {
108+
ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(
109+
name -> {
110+
return getPara(name);
111+
});
112+
renderText(ServerEndpoint.INDEXED_CHILD.getBody());
113+
});
94114
}
95-
96115
}

0 commit comments

Comments
 (0)