DataDog / dd-trace-java

Datadog APM client for Java
https://docs.datadoghq.com/tracing/languages/java
Apache License 2.0
576 stars 286 forks source link

Traces "path group" is not transformed correctly #6421

Open aallou opened 9 months ago

aallou commented 9 months ago

Using Java 17 and APM agent :

For a specific endpoint, i have a strange behaviour :

Sometimes my traces are displayed like this : http.path_group : /films/actor_id/notes (with actor_id is different per actor) Examples : http.path_group : /films/paul/notes http.path_group : /films/paul/notes http.path_group : /films/paul/notes

And sometimes, they are displayed like : http.path_group : /films/?/notes (so the path variable is recognized)

So, logically, all traces should be displayed like : http.path_group : /films/?/notes

joni- commented 9 months ago

We are seeing similar issue with resource grouping under the Resource pane in APM. Our service defines a route with path variable but the calls are not grouped under single resource in APM. We are seeing most of them as separate resources when calling the endpoint with different parameters. Some calls are grouped correctly but very small portion of them (I ran a brief test and only 10 out of ~1000 requests got grouped correctly).

We use Kotlin, JDK 21 and Ktor with Netty. dd-java-agent version is 1.27.0.

Here's a simplified version of how we define our routing in Ktor. We'd expect to see all requests go under /v1/foo/? resource in APM.

embeddedServer(Netty, port = 8080) {
    routing {
        route("/v1") {
            get("/foo/{slug}") {
                call.respond(HttpStatusCode.OK)
            }
        }
    }
}.start(wait = true)
shedrach-deliverr commented 8 months ago

Seeing the issue using Java 8, Jetty 9.4, dd-java-agent v1.13.0

hoanghun commented 4 months ago

@joni- Was this issue fixed for you?

I am also seeing this issue, using Kotlin, Jetty 12.09 and dd-java-agent 1.34.0

joni- commented 4 months ago

@joni- Was this issue fixed for you?

I am also seeing this issue, using Kotlin, Jetty 12.09 and dd-java-agent 1.34.0

We ended up doing something like this to get the grouping work properly. Does the job for us.

    get("/foo/{slug}") {
        val span = GlobalTracer.get().activeSpan()
        span?.setTag("http.path_group", "/foo/{slug}")
        span?.setTag(DDTags.RESOURCE_NAME, "GET /foo/{slug}")
        ...
    }

This page describes the logic behind quantization in more detail: https://docs.datadoghq.com/tracing/troubleshooting/quantization/