-
Notifications
You must be signed in to change notification settings - Fork 73
feat(o11y): introduce server.port attribute #4128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9e08c8f
0bccfec
820bc4b
235fa2b
24a2af1
816d263
dda8251
14d3b87
50667c3
c307c5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import com.google.api.core.InternalApi; | ||
| import com.google.api.gax.rpc.LibraryMetadata; | ||
| import com.google.auto.value.AutoValue; | ||
| import com.google.common.base.Strings; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
|
|
@@ -49,20 +50,26 @@ public abstract class ApiTracerContext { | |
| @Nullable | ||
| public abstract String serverAddress(); | ||
|
|
||
| @Nullable | ||
| public abstract Integer serverPort(); | ||
|
|
||
| public abstract LibraryMetadata libraryMetadata(); | ||
|
|
||
| /** | ||
| * @return a map of attributes to be included in attempt-level spans | ||
| */ | ||
| public Map<String, String> getAttemptAttributes() { | ||
| Map<String, String> attributes = new HashMap<>(); | ||
| if (serverAddress() != null) { | ||
| public Map<String, Object> getAttemptAttributes() { | ||
| Map<String, Object> attributes = new HashMap<>(); | ||
| if (!Strings.isNullOrEmpty(serverAddress())) { | ||
| attributes.put(ObservabilityAttributes.SERVER_ADDRESS_ATTRIBUTE, serverAddress()); | ||
| } | ||
| if (libraryMetadata().repository() != null) { | ||
| if (serverPort() != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try to check both null and empty, this applies to all attributes too. We can use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the check for the other if-statements, but |
||
| attributes.put(ObservabilityAttributes.SERVER_PORT_ATTRIBUTE, serverPort()); | ||
| } | ||
| if (!Strings.isNullOrEmpty(libraryMetadata().repository())) { | ||
| attributes.put(ObservabilityAttributes.REPO_ATTRIBUTE, libraryMetadata().repository()); | ||
| } | ||
| if (libraryMetadata().artifactName() != null) { | ||
| if (!Strings.isNullOrEmpty(libraryMetadata().artifactName())) { | ||
| attributes.put(ObservabilityAttributes.ARTIFACT_ATTRIBUTE, libraryMetadata().artifactName()); | ||
| } | ||
| return attributes; | ||
|
|
@@ -82,6 +89,8 @@ public abstract static class Builder { | |
|
|
||
| public abstract Builder setLibraryMetadata(LibraryMetadata gapicProperties); | ||
|
|
||
| public abstract Builder setServerPort(Integer serverPort); | ||
|
|
||
| public abstract ApiTracerContext build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,14 +51,21 @@ | |
| } | ||
|
|
||
| @Override | ||
| public Span createSpan(String name, Map<String, String> attributes) { | ||
| public Span createSpan(String name, Map<String, Object> attributes) { | ||
| SpanBuilder spanBuilder = tracer.spanBuilder(name); | ||
|
|
||
| // Attempt spans are of the CLIENT kind | ||
| spanBuilder.setSpanKind(SpanKind.CLIENT); | ||
|
|
||
| if (attributes != null) { | ||
| attributes.forEach((k, v) -> spanBuilder.setAttribute(k, v)); | ||
| attributes.forEach( | ||
| (k, v) -> { | ||
| if (v instanceof String) { | ||
| spanBuilder.setAttribute(k, (String) v); | ||
| } else if (v instanceof Integer) { | ||
| spanBuilder.setAttribute(k, (long) (Integer) v); | ||
|
Check warning on line 66 in gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTraceManager.java
|
||
| } | ||
|
Comment on lines
+62
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation for setting attributes on the span only handles (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);
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the type matter? Would it cause any differences in the UI? If not, can we just use String?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Offline discussion: let's conform to SemConv and keep port as an Integer. |
||
| }); | ||
diegomarquezp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| io.opentelemetry.api.trace.Span span = spanBuilder.startSpan(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.