-
Notifications
You must be signed in to change notification settings - Fork 879
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
Put http.route
attribute onto http.server.duration
on Play framework request processing
#7801
Put http.route
attribute onto http.server.duration
on Play framework request processing
#7801
Conversation
…ork request processing Basically, `akka-http` instrumenter has the responsibility to instrument the `http_server_duration`, but the current implementation has not marked the `http_route` attribute. ref: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/8e8161cb2e5b27d78b8afb7872df17cfa25a2f74/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerAttributesGetter.java#L59 Actually, it's hard to record that attribute by only the akka-http layer because that library's request object doesn't hold the route information, e.g. placeholder. So this patch delegates that job to the `play` instrumenter and when that has been able to get the route info, the instrumenter puts `http_route` attribute onto `http_server_duration`. For example, when the routes configuration of the Play is like the following: ``` GET /foo/:bar controllers.HomeController.doSomething(bar: String) ``` and when it tries to access that API, then OTEL instruments like so: ```prometheus http_server_duration_count{otel_scope_name="io.opentelemetry.akka-http-10.0",otel_scope_version="1.23.0-alpha-SNAPSHOT",http_flavor="1.1",http_method="GET",http_route="/foo/$bar<[^/]+>",http_scheme="http",http_status_code="200",net_host_name="localhost",net_host_port="9000"} 1.0 1676078079798 http_server_duration_sum{otel_scope_name="io.opentelemetry.akka-http-10.0",otel_scope_version="1.23.0-alpha-SNAPSHOT",http_flavor="1.1",http_method="GET",http_route="/foo/$bar<[^/]+>",http_scheme="http",http_status_code="200",net_host_name="localhost",net_host_port="9000"} 12183.558843 1676078079798 http_server_duration_bucket{otel_scope_name="io.opentelemetry.akka-http-10.0",otel_scope_version="1.23.0-alpha-SNAPSHOT",http_flavor="1.1",http_method="GET",http_route="/foo/$bar<[^/]+>",http_scheme="http",http_status_code="200",net_host_name="localhost",net_host_port="9000",le="0.0"} 0.0 1676078079798 ... http_server_duration_bucket{otel_scope_name="io.opentelemetry.akka-http-10.0",otel_scope_version="1.23.0-alpha-SNAPSHOT",http_flavor="1.1",http_method="GET",http_route="/foo/$bar<[^/]+>",http_scheme="http",http_status_code="200",net_host_name="localhost",net_host_port="9000",le="+Inf"} 1.0 1676078079798 ``` Rel: open-telemetry#1415 Signed-off-by: moznion <[email protected]>
|
…bute Signed-off-by: moznion <[email protected]>
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.
thx @moznion!
can you see if you can add a test that shows http.route
now getting collected on the spans?
@trask sure, I'll add some test cases for this. |
…in a server span with Play framework Signed-off-by: moznion <[email protected]>
@trask I added the test case for this patch to the smoke test @ 5151da5. Essentially, this test case should be in the individual instrumentation subproject (i.e. |
Signed-off-by: moznion <[email protected]>
http_route
attribute onto http_server_duration
on Play framework request processinghttp.route
attribute onto http.server.duration
on Play framework request processing
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.
Thanks @moznion !
// set the span name on the upstream akka/netty span | ||
Span serverSpan = LocalRootSpan.fromContextOrNull(context); |
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.
Can you remove the code that handles the serverSpan
below? The HttpRouteHolder
does that already
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.
Thank you for pointing out it. I removed them at ff97ca1.
@@ -66,6 +73,10 @@ public static void updateSpanNames(Context context, Request<?> request) { | |||
} | |||
} | |||
|
|||
private static void updateHttpRoute(Context context, String route) { |
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.
Nit: this method is so simple that it could be inlined.
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.
Yeah, actually this was an intentional thing to try making the aim of the procedure obvious by the method name, but as you mentioned this has already been enough self-descriptive and ff97ca1 removed extra lines, so I changed them to be inlined.
def httpRouteAttributes = extractRouteAttributesFrom(traces) | ||
httpRouteAttributes.size() == 1 | ||
httpRouteAttributes.get(0).value.stringValue == "/welcome" |
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.
Nit: you could use TraceInspector
and countFilteredAttributes
instead.
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.
That's good to know! I simplified that at 5be95b8.
@@ -52,12 +54,17 @@ public static Instrumenter<Void, Void> instrumenter() { | |||
return INSTRUMENTER; | |||
} | |||
|
|||
public static void updateSpanNames(Context context, Request<?> request) { | |||
public static void updateContext(Context context, Request<?> request) { |
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.
would it be possible to do the same changes in play 2.4 instrumentation?
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.
Good point. I applied the same change for Play 2.4 MVC at 6109ae3.
rel: - open-telemetry#7801 (comment) - open-telemetry#7801 (comment) Signed-off-by: moznion <[email protected]>
rel: open-telemetry#7801 (comment) Signed-off-by: moznion <[email protected]>
Signed-off-by: moznion <[email protected]>
@@ -37,6 +38,8 @@ class PlaySmokeTest extends SmokeTest { | |||
//One internal, one SERVER | |||
countSpansByName(traces, '/welcome') == 2 | |||
|
|||
new TraceInspector(traces).countFilteredAttributes(SemanticAttributes.HTTP_ROUTE.key, "/welcome") == 1 |
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.
❤️ this is good enough for me, thx!
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.
Thanks @moznion !
Basically,
akka-http
instrumenter has the responsibility to instrument thehttp.server.duration
for the Play framework application, but the current implementation has not marked thehttp.route
attribute.ref:
opentelemetry-java-instrumentation/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerAttributesGetter.java
Line 59 in 8e8161c
Actually, it's hard to record that attribute by only the akka-http layer because that library's request object doesn't hold the route information, e.g. placeholder.
So this patch delegates that job to the
play-mvc
instrumenter and when that has been able to get the route info, the instrumenter putshttp.route
attribute ontohttp.server.duration
.For example, when the routes configuration of the Play is like the following:
and when it tries to access that API, then OTEL instruments like so:
Rel: #1415