From b859165160e7d4674ff0d97a84404bc2fb67b265 Mon Sep 17 00:00:00 2001 From: chenlujjj <953546398@qq.com> Date: Wed, 8 Jan 2025 10:33:30 +0800 Subject: [PATCH] fix style --- .../jsonrpc4j-1.6/javaagent/build.gradle.kts | 1 - .../JsonRpcClientBuilderInstrumentation.java | 26 ++++++++++++------- .../v1_6/JsonRpcInstrumentationModule.java | 8 ++++-- .../JsonRpcServerBuilderInstrumentation.java | 16 +++++++----- .../jsonrpc4j/v1_6/JsonRpcSingletons.java | 11 ++++---- ...ServiceExporterBuilderInstrumentation.java | 17 +++++++----- .../jsonrpc4j/v1_6/AgentJsonRpcTest.java | 11 ++++---- 7 files changed, 53 insertions(+), 37 deletions(-) diff --git a/instrumentation/jsonrpc4j-1.6/javaagent/build.gradle.kts b/instrumentation/jsonrpc4j-1.6/javaagent/build.gradle.kts index 77b5ef767523..72ca19de8a32 100644 --- a/instrumentation/jsonrpc4j-1.6/javaagent/build.gradle.kts +++ b/instrumentation/jsonrpc4j-1.6/javaagent/build.gradle.kts @@ -19,7 +19,6 @@ dependencies { testImplementation(project(":instrumentation:jsonrpc4j-1.6:testing")) } - tasks { test { systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) diff --git a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcClientBuilderInstrumentation.java b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcClientBuilderInstrumentation.java index e55a6214102d..4f54ab1e0a6f 100644 --- a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcClientBuilderInstrumentation.java +++ b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcClientBuilderInstrumentation.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_6; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; @@ -15,10 +20,10 @@ import io.opentelemetry.instrumentation.jsonrpc4j.v1_6.SimpleJsonRpcResponse; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import java.util.Map; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; -import java.util.Map; public class JsonRpcClientBuilderInstrumentation implements TypeInstrumentation { @@ -37,8 +42,8 @@ public ElementMatcher typeMatcher() { public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( isMethod() - .and(named("invoke")) - .and(takesArguments(4)) + .and(named("invoke")) + .and(takesArguments(4)) .and(takesArgument(0, String.class)) .and(takesArgument(1, Object.class)) .and(takesArgument(2, named("java.lang.reflect.Type"))) @@ -58,16 +63,15 @@ public static void onEnter( @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { Context parentContext = Context.current(); - SimpleJsonRpcRequest request = new SimpleJsonRpcRequest( - methodName, - argument - ); + SimpleJsonRpcRequest request = new SimpleJsonRpcRequest(methodName, argument); if (!JsonRpcSingletons.CLIENT_INSTRUMENTER.shouldStart(parentContext, request)) { return; } context = JsonRpcSingletons.CLIENT_INSTRUMENTER.start(parentContext, request); - JsonRpcSingletons.PROPAGATORS.getTextMapPropagator().inject(context, extraHeaders, HeadersSetter.INSTANCE); + JsonRpcSingletons.PROPAGATORS + .getTextMapPropagator() + .inject(context, extraHeaders, HeadersSetter.INSTANCE); scope = context.makeCurrent(); } @@ -86,7 +90,11 @@ public static void onExit( } scope.close(); - JsonRpcSingletons.CLIENT_INSTRUMENTER.end(context, new SimpleJsonRpcRequest(methodName, argument), new SimpleJsonRpcResponse(result), throwable); + JsonRpcSingletons.CLIENT_INSTRUMENTER.end( + context, + new SimpleJsonRpcRequest(methodName, argument), + new SimpleJsonRpcResponse(result), + throwable); System.out.println(extraHeaders); } } diff --git a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcInstrumentationModule.java b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcInstrumentationModule.java index a663dc8e0a15..4af2d29a8b80 100644 --- a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcInstrumentationModule.java +++ b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcInstrumentationModule.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_6; import static java.util.Arrays.asList; @@ -18,7 +23,6 @@ public List typeInstrumentations() { return asList( new JsonRpcServerBuilderInstrumentation(), new JsonServiceExporterBuilderInstrumentation(), - new JsonRpcClientBuilderInstrumentation() - ); + new JsonRpcClientBuilderInstrumentation()); } } diff --git a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcServerBuilderInstrumentation.java b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcServerBuilderInstrumentation.java index 677b951d8c5d..fbc00b2fad85 100644 --- a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcServerBuilderInstrumentation.java +++ b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcServerBuilderInstrumentation.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_6; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; @@ -5,17 +10,16 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import com.googlecode.jsonrpc4j.InvocationListener; +import com.googlecode.jsonrpc4j.JsonRpcBasicServer; +import io.opentelemetry.instrumentation.api.util.VirtualField; 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 io.opentelemetry.instrumentation.api.util.VirtualField; import net.bytebuddy.matcher.ElementMatcher; -import com.googlecode.jsonrpc4j.JsonRpcBasicServer; -import net.bytebuddy.asm.Advice; public class JsonRpcServerBuilderInstrumentation implements TypeInstrumentation { - @Override public ElementMatcher classLoaderOptimization() { return hasClassesNamed("com.googlecode.jsonrpc4j.JsonRpcBasicServer"); @@ -29,8 +33,7 @@ public ElementMatcher typeMatcher() { @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - isConstructor(), - this.getClass().getName() + "$ConstructorAdvice"); + isConstructor(), this.getClass().getName() + "$ConstructorAdvice"); } @SuppressWarnings("unused") @@ -48,5 +51,4 @@ public static void setInvocationListener( } } } - } diff --git a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcSingletons.java b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcSingletons.java index 633d0ba563c4..fd9885c2c8dd 100644 --- a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcSingletons.java +++ b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonRpcSingletons.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_6; import com.googlecode.jsonrpc4j.InvocationListener; @@ -8,7 +13,6 @@ import io.opentelemetry.instrumentation.jsonrpc4j.v1_6.SimpleJsonRpcRequest; import io.opentelemetry.instrumentation.jsonrpc4j.v1_6.SimpleJsonRpcResponse; - public final class JsonRpcSingletons { public static final InvocationListener SERVER_INVOCATION_LISTENER; @@ -18,15 +22,12 @@ public final class JsonRpcSingletons { public static final ContextPropagators PROPAGATORS; static { - JsonRpcTelemetry telemetry = - JsonRpcTelemetry.builder(GlobalOpenTelemetry.get()) - .build(); + JsonRpcTelemetry telemetry = JsonRpcTelemetry.builder(GlobalOpenTelemetry.get()).build(); SERVER_INVOCATION_LISTENER = telemetry.newServerInvocationListener(); CLIENT_INSTRUMENTER = telemetry.getClientInstrumenter(); PROPAGATORS = telemetry.getPropagators(); } - private JsonRpcSingletons() {} } diff --git a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonServiceExporterBuilderInstrumentation.java b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonServiceExporterBuilderInstrumentation.java index a69587bccc24..346a095e79f1 100644 --- a/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonServiceExporterBuilderInstrumentation.java +++ b/instrumentation/jsonrpc4j-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/JsonServiceExporterBuilderInstrumentation.java @@ -1,5 +1,14 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_6; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; +import static net.bytebuddy.matcher.ElementMatchers.isMethod; +import static net.bytebuddy.matcher.ElementMatchers.named; + import com.googlecode.jsonrpc4j.JsonRpcServer; import com.googlecode.jsonrpc4j.spring.JsonServiceExporter; import io.opentelemetry.instrumentation.api.util.VirtualField; @@ -9,11 +18,6 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; - -import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; -import static net.bytebuddy.matcher.ElementMatchers.isMethod; -import static net.bytebuddy.matcher.ElementMatchers.named; - public class JsonServiceExporterBuilderInstrumentation implements TypeInstrumentation { @Override public ElementMatcher classLoaderOptimization() { @@ -28,8 +32,7 @@ public ElementMatcher typeMatcher() { @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - isMethod().and(named("exportService")), - this.getClass().getName() + "$ExportAdvice"); + isMethod().and(named("exportService")), this.getClass().getName() + "$ExportAdvice"); } @SuppressWarnings("unused") diff --git a/instrumentation/jsonrpc4j-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/AgentJsonRpcTest.java b/instrumentation/jsonrpc4j-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/AgentJsonRpcTest.java index 0012d13dff88..26e85daf86dc 100644 --- a/instrumentation/jsonrpc4j-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/AgentJsonRpcTest.java +++ b/instrumentation/jsonrpc4j-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_6/AgentJsonRpcTest.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_6; import com.googlecode.jsonrpc4j.JsonRpcBasicServer; @@ -8,11 +13,9 @@ public class AgentJsonRpcTest extends AbstractJsonRpcTest { - @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); - @Override protected InstrumentationExtension testing() { return testing; @@ -22,8 +25,4 @@ protected InstrumentationExtension testing() { protected JsonRpcBasicServer configureServer(JsonRpcBasicServer server) { return server; } - - - - }