Skip to content

Conversation

@fangxiu-wf
Copy link

@fangxiu-wf fangxiu-wf commented Dec 10, 2025

This PR adds instrumentation support for SOFARPC framework, including:

  • Javaagent instrumentation module
  • Library autoconfigure module
  • Testing utilities and test cases
  • Support for SOFARPC 5.4.0+

Fixes #15496

This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0 through 5.12.0+

Fixes open-telemetry#15496
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 10, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: fangxiu-wf / name: fangxiu-wf (5d2c68a)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive instrumentation support for the SOFARPC framework, enabling distributed tracing for RPC calls. The implementation includes both javaagent-based auto-instrumentation and library-based manual instrumentation approaches, with full support for synchronous, asynchronous, and generic invocations.

Key changes:

  • Adds javaagent instrumentation module with automatic filter injection via SPI
  • Adds library autoconfigure module with manual instrumentation API
  • Implements comprehensive test coverage including chain tracing, error handling, async calls, and local call detection
  • Supports SOFARPC versions 5.4.0 through 5.12.0+

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
settings.gradle.kts Adds three new subprojects for SOFARPC instrumentation (javaagent, library-autoconfigure, testing)
instrumentation/sofa-rpc/metadata.yaml Defines instrumentation metadata including supported versions, semantic conventions, and configuration options
instrumentation/sofa-rpc/testing/build.gradle.kts Configures test dependencies and runtime classpath with SOFARPC 5.4.0 and compatible logging dependencies
instrumentation/sofa-rpc/testing/src/main/java/.../api/* Defines test service interfaces (HelloService, MiddleService, ErrorService) for testing RPC scenarios
instrumentation/sofa-rpc/testing/src/main/java/.../impl/* Implements test services including error handling, chaining, and timeout scenarios
instrumentation/sofa-rpc/testing/src/main/java/.../AbstractSofaRpcTest.java Provides base test class for synchronous, asynchronous, and error handling test scenarios
instrumentation/sofa-rpc/testing/src/main/java/.../AbstractSofaRpcTraceChainTest.java Tests trace propagation through chained RPC calls and local call filtering
instrumentation/sofa-rpc/library-autoconfigure/src/main/java/.../* Core library instrumentation including telemetry builder, filters, attribute extractors, and context propagation
instrumentation/sofa-rpc/library-autoconfigure/src/test/java/.../* Library instrumentation tests extending abstract test classes
instrumentation/sofa-rpc/library-autoconfigure/build.gradle.kts Configures library dependencies with SOFARPC 5.4.0 and AutoValue for code generation
instrumentation/sofa-rpc/library-autoconfigure/src/main/resources/META-INF/services/* SPI configuration for auto-registering OpenTelemetry filters with SOFARPC
instrumentation/sofa-rpc/javaagent/src/main/java/.../* Javaagent instrumentation module with resource injection and filter delegation
instrumentation/sofa-rpc/javaagent/src/testSofaRpc/java/.../* Javaagent-specific tests with peer service attribute support
instrumentation/sofa-rpc/javaagent/build.gradle.kts Configures javaagent build with muzzle checks for version 5.0.0+ and test suites
instrumentation/sofa-rpc/javaagent/src/main/resources/* SPI configuration for javaagent filter registration

fangxiu-wf and others added 3 commits December 11, 2025 17:19
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0 through 5.12.0+

Fixes open-telemetry#15496
…va/io/opentelemetry/instrumentation/sofarpc/v5_4/SofaRpcTelemetryBuilder.java

Co-authored-by: Copilot <[email protected]>
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0 through 5.12.0+

Fixes open-telemetry#15496
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0+

Fixes open-telemetry#15496
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0+

Fixes open-telemetry#15496
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0+

Fixes open-telemetry#15496
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0+

Fixes open-telemetry#15496
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0+

Fixes open-telemetry#15496
This PR adds instrumentation support for SOFARPC framework, including:
- Javaagent instrumentation module
- Library autoconfigure module
- Testing utilities and test cases
- Support for SOFARPC 5.4.0+

Fixes open-telemetry#15496
@fangxiu-wf fangxiu-wf marked this pull request as ready for review December 17, 2025 12:16
@fangxiu-wf fangxiu-wf requested a review from a team as a code owner December 17, 2025 12:16
| [RxJava](https://github.com/ReactiveX/RxJava) | 1.0+ | [opentelemetry-rxjava-1.0](../instrumentation/rxjava/rxjava-1.0/library),<br>[opentelemetry-rxjava-2.0](../instrumentation/rxjava/rxjava-2.0/library),<br>[opentelemetry-rxjava-3.0](../instrumentation/rxjava/rxjava-3.0/library),<br>[opentelemetry-rxjava-3.1.1](../instrumentation/rxjava/rxjava-3.1.1/library) | Context propagation |
| [Scala ForkJoinPool](https://www.scala-lang.org/api/2.12.0/scala/concurrent/forkjoin/package$$ForkJoinPool$.html) | 2.8+ | N/A | Context propagation |
| [Servlet](https://javaee.github.io/javaee-spec/javadocs/javax/servlet/package-summary.html) | 2.2+ | [opentelemetry-servlet-3.0](../instrumentation/servlet/servlet-3.0/library) | [HTTP Server Spans], [HTTP Server Metrics] |
| [SOFARPC](https://github.com/sofastack/sofa-rpc/) | 5.4.0+ | [opentelemetry-sofa-rpc-5.4](../instrumentation/sofa-rpc-5.4/library-autoconfigure) | [RPC Client Spans], [RPC Server Spans] |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| [SOFARPC](https://github.com/sofastack/sofa-rpc/) | 5.4.0+ | [opentelemetry-sofa-rpc-5.4](../instrumentation/sofa-rpc-5.4/library-autoconfigure) | [RPC Client Spans], [RPC Server Spans] |
| [SOFARPC](https://github.com/sofastack/sofa-rpc/) | 5.4+ | [opentelemetry-sofa-rpc-5.4](../instrumentation/sofa-rpc-5.4/library-autoconfigure) | [RPC Client Spans], [RPC Client Metrics], [RPC Server Spans], [RPC Server Metrics] |

target: ':instrumentation:sofa-rpc-5.4:javaagent'
- type: gradle
path: ./
target: ':instrumentation:sofa-rpc-5.4:library-autoconfigure'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name autoconfigure here doesn't follow the normal pattern. Seems like it should just be library ? I see that this is also the case in the dubbo module, which is maybe where you copied from, but I'm not sure it's correct there either

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

library-autoconfigure is used by library instrumentations that are automatically enabled when the library instrumentation jar is added to the project as opposed to library instrumentations where user has to write code to enable the instrumentation. Typically the library-autoconfigure use some sort of spi that is automatically picked up by the instrumented framework. Often it makes sense for instrumentation to provide both library and library-autoconfigure modules (for example see aws2.2 instrumentation) since library-autoconfigure instrumentations can't often be configured.

}

// A type instrumentation is needed to trigger resource injection.
public static class ResourceInjectingTypeInstrumentation implements TypeInstrumentation {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to put this in a separate file? we don't typically include instrumentations in the InstrumentationModule itself

String errorMsg = response.getErrorMsg();
if (errorMsg != null) {
return new SofaRpcException(
com.alipay.sofa.rpc.core.exception.RpcErrorType.SERVER_UNDECLARED_ERROR, errorMsg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is having the FQCN useful in this case or could we import?

Suggested change
com.alipay.sofa.rpc.core.exception.RpcErrorType.SERVER_UNDECLARED_ERROR, errorMsg);
RpcErrorType.SERVER_UNDECLARED_ERROR, errorMsg);

Comment on lines +57 to +61
@BeforeAll
static void setUp() {}

@AfterAll
static void tearDown() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@BeforeAll
static void setUp() {}
@AfterAll
static void tearDown() {}

return consumer;
}

ConsumerConfig<GenericService> configureGenericClient(int port) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like it is unused?

"io.opentelemetry.instrumentation.sofarpc.v5_4.api.HelloService/hello")
.hasKind(SpanKind.SERVER)
.hasParent(trace.getSpan(1))
.hasAttributesSatisfying(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A handful of the server spans in this test don't use the exactly flavor of this assertion, is that intentional?

Suggested change
.hasAttributesSatisfying(
.hasAttributesSatisfyingExactly(

Comment on lines +45 to +49
@BeforeAll
static void setUp() {}

@AfterAll
static void tearDown() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@BeforeAll
static void setUp() {}
@AfterAll
static void tearDown() {}

"io.opentelemetry.instrumentation.sofarpc.v5_4.api.MiddleService/hello")
.hasKind(SpanKind.SERVER)
.hasParent(trace.getSpan(1))
.hasAttributesSatisfying(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as other test, is there a reason we can't use the strict version?

Suggested change
.hasAttributesSatisfying(
.hasAttributesSatisfyingExactly(

return;
}
Throwable error = exception != null ? exception : extractException(response);
instrumenter.end(context, SofaRpcRequest.create(request), response, error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in some of our other similar instrumentations, we clear the virtual field after we grab it to avoid memory leaks. See jaxrs, and asynchttpclient and kafka as examples

Suggested change
instrumenter.end(context, SofaRpcRequest.create(request), response, error);
instrumenter.end(context, SofaRpcRequest.create(request), response, error);
ASYNC_CONTEXT.set(request, null); // Clear to prevent memory leak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for SOFARPC framework

4 participants