Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
chenlujjj committed Jan 8, 2025
1 parent 7781c8c commit b859165
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 37 deletions.
1 change: 0 additions & 1 deletion instrumentation/jsonrpc4j-1.6/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies {
testImplementation(project(":instrumentation:jsonrpc4j-1.6:testing"))
}


tasks {
test {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -37,8 +42,8 @@ public ElementMatcher<TypeDescription> 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")))
Expand All @@ -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();
}
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,7 +23,6 @@ public List<TypeInstrumentation> typeInstrumentations() {
return asList(
new JsonRpcServerBuilderInstrumentation(),
new JsonServiceExporterBuilderInstrumentation(),
new JsonRpcClientBuilderInstrumentation()
);
new JsonRpcClientBuilderInstrumentation());
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
/*
* 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.isConstructor;
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<ClassLoader> classLoaderOptimization() {
return hasClassesNamed("com.googlecode.jsonrpc4j.JsonRpcBasicServer");
Expand All @@ -29,8 +33,7 @@ public ElementMatcher<TypeDescription> typeMatcher() {
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isConstructor(),
this.getClass().getName() + "$ConstructorAdvice");
isConstructor(), this.getClass().getName() + "$ConstructorAdvice");
}

@SuppressWarnings("unused")
Expand All @@ -48,5 +51,4 @@ public static void setInvocationListener(
}
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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() {}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ClassLoader> classLoaderOptimization() {
Expand All @@ -28,8 +32,7 @@ public ElementMatcher<TypeDescription> 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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,11 +13,9 @@

public class AgentJsonRpcTest extends AbstractJsonRpcTest {


@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();


@Override
protected InstrumentationExtension testing() {
return testing;
Expand All @@ -22,8 +25,4 @@ protected InstrumentationExtension testing() {
protected JsonRpcBasicServer configureServer(JsonRpcBasicServer server) {
return server;
}




}

0 comments on commit b859165

Please sign in to comment.