feat(o11y): introduce server.port attribute#4128
Conversation
Summary of ChangesHello, 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 enhances the observability features by introducing a Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces the server.port attribute for observability, which is a valuable addition for tracing. The changes are consistently applied across the codebase, from endpoint parsing in EndpointContext to the OpenTelemetryTraceManager. The necessary API changes, like updating attribute maps to Map<String, Object>, are handled correctly. The tests, including unit and integration tests, are updated to cover the new functionality. I have one suggestion to improve the robustness of attribute handling in OpenTelemetryTraceManager for future maintainability.
| (k, v) -> { | ||
| if (v instanceof String) { | ||
| spanBuilder.setAttribute(k, (String) v); | ||
| } else if (v instanceof Integer) { | ||
| spanBuilder.setAttribute(k, (long) (Integer) v); | ||
| } |
There was a problem hiding this comment.
The current implementation for setting attributes on the span only handles String and Integer types. While this is sufficient for the current changes, it makes the code brittle. If other attribute types (like Long, Double, or Boolean) are added in the future, they will be silently ignored. To improve future maintainability, it would be more robust to handle all primitive types supported by OpenTelemetry attributes.
(k, v) -> {
if (v instanceof String) {
spanBuilder.setAttribute(k, (String) v);
} else if (v instanceof Integer) {
spanBuilder.setAttribute(k, (long) (Integer) v);
} else if (v instanceof Long) {
spanBuilder.setAttribute(k, (Long) v);
} else if (v instanceof Double) {
spanBuilder.setAttribute(k, (Double) v);
} else if (v instanceof Boolean) {
spanBuilder.setAttribute(k, (Boolean) v);
}There was a problem hiding this comment.
/gemini I think it's worth to restrict it to only types we are introducing for now. New types are not expected and expanding this list will also imply additional testing (maintenance) for adding only one more type.
There was a problem hiding this comment.
Does the type matter? Would it cause any differences in the UI? If not, can we just use String?
…-attr/server.port
|
|
| } | ||
| try { | ||
| HostAndPort parsedHostPort = HostAndPort.fromString(hostPort); | ||
| if (parsedHostPort.hasPort()) { |
There was a problem hiding this comment.
The logic in this method is pretty much identical to the last method parseServerAddress, can we merge these two?
| (k, v) -> { | ||
| if (v instanceof String) { | ||
| spanBuilder.setAttribute(k, (String) v); | ||
| } else if (v instanceof Integer) { | ||
| spanBuilder.setAttribute(k, (long) (Integer) v); | ||
| } |
There was a problem hiding this comment.
Does the type matter? Would it cause any differences in the UI? If not, can we just use String?
| .setTransportChannelProviderEndpoint(null) | ||
| .build(); | ||
| Truth.assertThat(endpointContext.resolvedServerAddress()).isEqualTo("localhost"); | ||
| Truth.assertThat(endpointContext.resolvedServerPort()).isEqualTo(7469); |
There was a problem hiding this comment.
I might missed this in the first PR, it's better to split these test cases to one case per test.
| if (serverAddress() != null) { | ||
| attributes.put(ObservabilityAttributes.SERVER_ADDRESS_ATTRIBUTE, serverAddress()); | ||
| } | ||
| if (serverPort() != null) { |
There was a problem hiding this comment.
Let's try to check both null and empty, this applies to all attributes too. We can use Strings.isNullOrEmpty.


Uh oh!
There was an error while loading. Please reload this page.