Skip to content

Commit 3bcf70c

Browse files
committed
extract url template in onStart
1 parent 6dbb413 commit 3bcf70c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/http/HttpExperimentalAttributesExtractor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ private HttpExperimentalAttributesExtractor(
4848
}
4949

5050
@Override
51-
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {}
51+
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
52+
if (getter instanceof HttpClientAttributesGetter) {
53+
HttpClientAttributesGetter<REQUEST, RESPONSE> clientGetter =
54+
(HttpClientAttributesGetter<REQUEST, RESPONSE>) getter;
55+
String urlTemplate =
56+
HttpClientUrlTemplateUtil.getUrlTemplate(parentContext, request, clientGetter);
57+
internalSet(attributes, URL_TEMPLATE, urlTemplate);
58+
}
59+
}
5260

5361
@Override
5462
public void onEnd(
@@ -65,13 +73,6 @@ public void onEnd(
6573
Long responseBodySize = responseBodySize(request, response);
6674
internalSet(attributes, HTTP_RESPONSE_BODY_SIZE, responseBodySize);
6775
}
68-
69-
if (getter instanceof HttpClientAttributesGetter) {
70-
HttpClientAttributesGetter<REQUEST, RESPONSE> clientGetter =
71-
(HttpClientAttributesGetter<REQUEST, RESPONSE>) getter;
72-
String urlTemplate = HttpClientUrlTemplateUtil.getUrlTemplate(context, request, clientGetter);
73-
internalSet(attributes, URL_TEMPLATE, urlTemplate);
74-
}
7576
}
7677

7778
@Nullable

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/http/HttpExperimentalAttributesExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void runTest(
6060

6161
AttributesBuilder attributes = Attributes.builder();
6262
extractor.onStart(attributes, Context.root(), "request");
63-
assertThat(attributes.build()).isEmpty();
63+
assertThat(attributes.build().asMap()).containsExactlyInAnyOrderEntriesOf(expected);
6464

6565
extractor.onEnd(attributes, Context.root(), "request", "response", null);
6666
Map<AttributeKey<?>, Object> expectedAttributes = new HashMap<>(expected);

0 commit comments

Comments
 (0)