Skip to content

Conversation

@ehsavoie
Copy link
Collaborator

Adding support for OpenTelemetry

Fixes #388 🦕

@ehsavoie ehsavoie requested review from fjuma and kabir November 18, 2025 15:54
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ehsavoie, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates OpenTelemetry into the A2A Java SDK, providing robust distributed tracing capabilities. The changes enable automatic span creation for both client-initiated and server-processed A2A requests, offering deeper visibility into the flow of operations. This enhancement is crucial for monitoring, troubleshooting, and understanding the performance characteristics of applications built with the SDK.

Highlights

  • OpenTelemetry Module: Introduced a new Maven module, extras/opentelemetry, to encapsulate all OpenTelemetry integration logic for the A2A Java SDK.
  • Client-Side Tracing: Implemented dynamic wrapping of ClientTransport instances with OpenTelemetryClientTransport within the ClientBuilder. This allows for automatic tracing of client-side A2A interactions when an OpenTelemetry Tracer is provided in the ClientTransportConfig.
  • Server-Side Tracing Interceptors: Added a new @Trace annotation and SpanInterceptor mechanism to enable automatic distributed tracing for server-side request handler methods across gRPC, JSON-RPC, and REST protocols. Custom AttributeExtractor implementations are used to enrich spans with relevant request details.
  • Enhanced ClientTransportConfig: The ClientTransportConfig now includes a generic parameters map, facilitating the injection of arbitrary configuration, such as the OpenTelemetry Tracer instance, into transport implementations.
  • Example Application Updates: The helloworld example client and server applications have been updated to demonstrate the setup and usage of OpenTelemetry, including dependency additions and configuration for tracing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for OpenTelemetry, which is a great addition for observability. The implementation introduces a new opentelemetry extras module and integrates tracing on both the client and server sides. On the client side, it uses reflection for optional wrapping, and on the server side, it uses CDI interceptors with a new @Trace annotation. My review focuses on improving the robustness and maintainability of this new feature. I've found a few critical issues, such as a ClassCastException in an attribute extractor and silent exception swallowing that could make debugging difficult. I've also identified several opportunities for code cleanup, such as fixing typos, removing duplicated code, and improving the design of the CDI interceptor to better support dependency injection. Addressing these points will make the OpenTelemetry integration more solid and easier to maintain.

Copy link

@brunobat brunobat left a comment

Choose a reason for hiding this comment

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

I think you need to decide if you are creating your own instrumentation annotations and API or if you just reuse the ones provided by OTel.

Also, the attribute names, should follow these semantic conventions, as much as possible: https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-agent-spans/

@ehsavoie ehsavoie force-pushed the issue_388 branch 4 times, most recently from 7661dd6 to 893ce8b Compare November 20, 2025 13:57
@ehsavoie ehsavoie changed the title Issue 388 feat: Add telemetry support. Nov 20, 2025
@ehsavoie ehsavoie force-pushed the issue_388 branch 2 times, most recently from 22a2af4 to d35543a Compare November 20, 2025 14:46
@ehsavoie ehsavoie requested a review from brunobat November 20, 2025 20:41
Copy link
Collaborator

@kabir kabir left a comment

Choose a reason for hiding this comment

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

A few things which may or may not be needed :-)

private final List<BiConsumer<ClientEvent, AgentCard>> consumers = new ArrayList<>();
private @Nullable Consumer<Throwable> streamErrorHandler;
private @Nullable
Consumer<Throwable> streamErrorHandler;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks a bit strange :-)

The original looks better, but I think

@Nullable
private Consumer<Throwable> streamErrorHandler;

would look better. But I see we have private @Nullable .... 'everywhere' :-)

.extractor();

String name = jakartaContext.getTarget().getClass().getName();
if (name != null && name.endsWith("_Subclass")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

name cannot be null

return Map.of("request", parameters[0].toString(), "extensions", context.getActivatedExtensions().stream().collect(Collectors.joining(",")), "a2a.method", (String) context.getState().get("method"));
}
default -> {
return Collections.emptyMap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could log a warning here. Or if the intent is that all DefaultRequestHandler methods are handled, we could throw an error?

return Map.of("request", parameters[0].toString(), "extensions", GrpcContextKeys.EXTENSIONS_HEADER_KEY.get(), "a2a.method", GrpcContextKeys.GRPC_METHOD_NAME_KEY.get(currentContext));
}
default -> {
return Collections.emptyMap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

log warn/throw error as above

return Map.of("body", parameters[0].toString(), "extensions", context.getActivatedExtensions().stream().collect(Collectors.joining(",")), "a2a.method", (String) context.getState().get(METHOD_NAME_KEY));
}
default -> {
return Collections.emptyMap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warn/error

return Map.of("contextId", (String) parameters[0], "status", (String) parameters[1], "extensions", context.getActivatedExtensions().stream().collect(Collectors.joining(",")), "a2a.method", (String) context.getState().get(METHOD_NAME_KEY));
}
default -> {
return Collections.emptyMap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warn/error

Copy link
Collaborator

@kabir kabir left a comment

Choose a reason for hiding this comment

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

Actually, @ehsavoie it looks like you are adding Otel tracing to the example. But I don't know how to enable this etc.
Can you update the README with instructions?

Maybe we could also make this example testable in the CI, like we do for the cloud-deployment one?

Also, it would be good to have some tests in the extras module

* Adding an annotation that can be used by CDI interceptor to create
  spans on current exchanges.
* Adding support for client wrappers to be able to add client side
  spans.
* Updating the helloworld example to use opentelemetry.

Fixing issue a2aproject#388
Signed-off-by: Emmanuel Hugonnet <[email protected]>
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.

[Feat] Add telemetry support

3 participants