-
Notifications
You must be signed in to change notification settings - Fork 935
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
add url.template
to client spans
#13572
Changes from 4 commits
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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
Comparing source compatibility of opentelemetry-instrumentation-api-2.15.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.14.0.jar | ||
No changes. | ||
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
GENERIC TEMPLATES: === REQUEST:java.lang.Object, === RESPONSE:java.lang.Object | ||
+++ NEW INTERFACE: io.opentelemetry.instrumentation.api.semconv.url.UrlAttributesGetter | ||
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.instrumentation.api.semconv.url.UrlAttributesGetter (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
GENERIC TEMPLATES: === REQUEST:java.lang.Object | ||
+++ NEW METHOD: PUBLIC(+) java.lang.String getUrlTemplate(java.lang.Object) | ||
+++ NEW ANNOTATION: javax.annotation.Nullable |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,14 @@ default String getUrlPath(REQUEST request) { | |
default String getUrlQuery(REQUEST request) { | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the template used to build the full URL (if available) | ||
* | ||
* <p>Examples: {@code /users/{id}}; {@code /users?q={query}} | ||
*/ | ||
@Nullable | ||
default String getUrlTemplate(REQUEST request) { | ||
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. Since |
||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import io.opentelemetry.instrumentation.api.semconv.url.UrlAttributesGetter; | ||
import io.opentelemetry.semconv.UrlAttributes; | ||
|
@@ -31,10 +32,12 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { | |
String urlScheme = getUrlScheme(request); | ||
String urlPath = getter.getUrlPath(request); | ||
String urlQuery = getter.getUrlQuery(request); | ||
String urlTemplate = getter.getUrlTemplate(request); | ||
|
||
internalSet(attributes, UrlAttributes.URL_SCHEME, urlScheme); | ||
internalSet(attributes, UrlAttributes.URL_PATH, urlPath); | ||
internalSet(attributes, UrlAttributes.URL_QUERY, urlQuery); | ||
internalSet(attributes, AttributeKey.stringKey("url.template"), urlTemplate); | ||
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. This constant is in the 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. I could not find any policies on stability, but I suspect you're right. (perhaps there is an expectation that things like this will be put behind a flag?) 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 guidance is that incubating attribute classes such as |
||
} | ||
|
||
private String getUrlScheme(REQUEST request) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.ktor.v2_0.common | |
|
||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.util.AttributeKey | ||
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter | ||
|
||
internal object KtorHttpClientAttributesGetter : HttpClientAttributesGetter<HttpRequestData, HttpResponse> { | ||
|
@@ -34,4 +35,7 @@ internal object KtorHttpClientAttributesGetter : HttpClientAttributesGetter<Http | |
override fun getServerAddress(request: HttpRequestData) = request.url.host | ||
|
||
override fun getServerPort(request: HttpRequestData) = request.url.port | ||
|
||
private val urlTemplateAttributeKey = AttributeKey<String>("URL_TEMPLATE") | ||
override fun getUrlTemplate(request: HttpRequestData): String? = request.attributes.getOrNull(urlTemplateAttributeKey) | ||
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. I'd suggest you to remove the ktor changes until there is a version of ktor that would support this. Once there is a version where this works you could add it back along with a test. |
||
} |
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.
UrlAttributesGetter
is for server instrumentations. Http client semantic conventions https://github.com/open-telemetry/semantic-conventions/blob/5816d4bb099b69eba1cb45084d7cceb51ad6bbfe/docs/http/http-spans.md#http-client don't list all of the attributes thatUrlAttributesGetter
provides.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.
so can I add getUrlTemplate to the
HttpClientAttributesGetter
interface directly?does this cause issues with incubating vs stable?
I don't see a way to add it similar to
http.request.body.size
because the template would not reside in the headers and would instead be pretty instrumentation specificThere 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.
As far as I understand, no you can't. You could if that attribute was declared stable in the semantic conventions. For now you'll have to approach it in a roundabout way.
HttpClientAttributesGetter
is part of the stable api. You could introduce an interface to theinstrumentation-api-incubator
module that either extends theHttpClientAttributesGetter
or just provides thegetUrlTemplate
method. In the extractor you could test the getter with instanceof. Probably the most tricky one will be handling the span name inHttpSpanNameExtractor
. For that you could register a callback in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/Experimental.java so thatinstrumentation-api
could call intoinstrumentation-api-incubator
.