-
Notifications
You must be signed in to change notification settings - Fork 75
impl(o11y): introduce http.request.method and span name for HTTP requests #4127
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 52 commits
e5b927a
956ae29
dfe6216
0ee9f4a
3cddc1b
2880286
74f97f6
418b954
7189841
e648a63
6b679d5
6fbcc08
8b0a403
b45401e
a49828f
5ecf1b0
82cc227
d9c4d80
b831ef9
f97b742
ba634ea
6759836
401c7e8
ed58c7d
342f4e3
8a7dacd
5a845da
00060d8
fc679c9
945366a
726fbf1
6fb4ed6
f5cf4bf
6711aa2
aa2c2af
efd2841
cee771f
f5c2381
4ef3b31
3cb2149
68f8d43
97d1aac
1b47eb9
ea86930
e771036
ac77f0a
2817210
6c15fbd
62f017d
839469b
33b7584
5e4269b
9cade37
3a59f2d
dc58e35
f8989ff
a4a85b3
3dd4b3c
8f4bc45
db3ee56
92ebc36
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 |
|---|---|---|
|
|
@@ -136,6 +136,26 @@ String rpcSystemName() { | |
| @Nullable | ||
| public abstract OperationType operationType(); | ||
|
|
||
| /** | ||
| * Returns the HTTP method used for the RPC, in case the RPC is an HttpJson method. | ||
| * | ||
| * <p>Example: {@code PATCH}. | ||
| * | ||
| * @return the HTTP method, or {@code null} if not set | ||
| */ | ||
| @Nullable | ||
| abstract String httpMethod(); | ||
|
|
||
| /** | ||
| * Returns the HTTP path template used for the RPC, in case the RPC is an HttpJson method. | ||
| * | ||
| * <p>Example: {@code /users/{user_id}/get}. | ||
| * | ||
| * @return the HTTP path template, or {@code null} if not set | ||
| */ | ||
| @Nullable | ||
| abstract String httpPathTemplate(); | ||
|
|
||
| /** | ||
| * @return a map of attributes to be included in attempt-level spans | ||
| */ | ||
|
|
@@ -159,8 +179,16 @@ public Map<String, Object> getAttemptAttributes() { | |
| ObservabilityAttributes.ARTIFACT_ATTRIBUTE, libraryMetadata().artifactName()); | ||
| } | ||
| } | ||
| if (transport() == Transport.GRPC && !Strings.isNullOrEmpty(fullMethodName())) { | ||
| attributes.put(ObservabilityAttributes.GRPC_RPC_METHOD_ATTRIBUTE, fullMethodName()); | ||
| if (transport() == Transport.GRPC) { | ||
| if (!Strings.isNullOrEmpty(fullMethodName())) { | ||
| attributes.put(ObservabilityAttributes.GRPC_RPC_METHOD_ATTRIBUTE, fullMethodName()); | ||
| } | ||
| if (Strings.isNullOrEmpty(fullMethodName())) { | ||
|
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. Is this duplicated? |
||
| attributes.put(ObservabilityAttributes.GRPC_RPC_METHOD_ATTRIBUTE, fullMethodName()); | ||
| } | ||
| } | ||
| if (transport() == Transport.HTTP && !Strings.isNullOrEmpty(httpMethod())) { | ||
| attributes.put(ObservabilityAttributes.HTTP_METHOD_ATTRIBUTE, httpMethod()); | ||
| } | ||
| return attributes; | ||
| } | ||
|
|
@@ -188,6 +216,12 @@ ApiTracerContext merge(ApiTracerContext other) { | |
| if (other.transport() != null) { | ||
| builder.setTransport(other.transport()); | ||
| } | ||
| if (!Strings.isNullOrEmpty(other.httpMethod())) { | ||
| builder.setHttpMethod(other.httpMethod()); | ||
| } | ||
| if (!Strings.isNullOrEmpty(other.httpPathTemplate())) { | ||
| builder.setHttpPathTemplate(other.httpPathTemplate()); | ||
| } | ||
| if (other.operationType() != null) { | ||
| builder.setOperationType(other.operationType()); | ||
| } | ||
|
|
@@ -218,6 +252,10 @@ public abstract static class Builder { | |
|
|
||
| public abstract Builder setServerPort(@Nullable Integer serverPort); | ||
|
|
||
| public abstract Builder setHttpMethod(@Nullable String httpMethod); | ||
|
|
||
| public abstract Builder setHttpPathTemplate(@Nullable String rawString); | ||
|
|
||
| public abstract ApiTracerContext build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import com.google.api.core.BetaApi; | ||
| import com.google.api.core.InternalApi; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Preconditions; | ||
|
|
||
| /** | ||
| * A {@link ApiTracerFactory} to build instances of {@link SpanTracer}. | ||
|
|
@@ -77,19 +78,20 @@ public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType op | |
|
|
||
| @Override | ||
| public ApiTracer newTracer(ApiTracer parent, ApiTracerContext apiTracerContext) { | ||
| ApiTracerContext context = this.apiTracerContext.merge(apiTracerContext); | ||
| ApiTracerContext mergedContext = this.apiTracerContext.merge(apiTracerContext); | ||
|
|
||
| String attemptSpanName; | ||
| if (context.transport() == ApiTracerContext.Transport.GRPC) { | ||
| attemptSpanName = context.fullMethodName(); | ||
| if (mergedContext.transport() == ApiTracerContext.Transport.GRPC) { | ||
| attemptSpanName = mergedContext.fullMethodName(); | ||
| } else { | ||
| // TODO(diegomarquezp): this is a placeholder for the HTTP span name and will be adjusted as | ||
| // the | ||
| // feature is developed. | ||
| attemptSpanName = context.fullMethodName() + "/attempt"; | ||
| Preconditions.checkNotNull(mergedContext.httpMethod(), "HTTP method cannot be null"); | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
| Preconditions.checkNotNull( | ||
| mergedContext.httpPathTemplate(), "HTTP path template cannot be null"); | ||
| attemptSpanName = | ||
| String.format("%s %s", mergedContext.httpMethod(), mergedContext.httpPathTemplate()); | ||
|
Comment on lines
+91
to
+92
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. Using String httpMethod = mergedContext.httpMethod() != null ? mergedContext.httpMethod() : "";
String httpPathTemplate =
mergedContext.httpPathTemplate() != null ? mergedContext.httpPathTemplate() : "";
attemptSpanName = (httpMethod + " " + httpPathTemplate).trim();
if (attemptSpanName.isEmpty()) {
attemptSpanName = mergedContext.fullMethodName();
}References
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 null checks instead. We must have a span name in this factory. |
||
| } | ||
|
|
||
| return new SpanTracer(traceManager, context, attemptSpanName); | ||
| return new SpanTracer(traceManager, mergedContext, attemptSpanName); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is going to be used as
url.template?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added
url.template