newrelic / newrelic-java-agent

The New Relic Java agent
Apache License 2.0
202 stars 143 forks source link

Transaction Name Incorrect with PATCH Verbs using Jersey #1893

Closed wdemis closed 4 months ago

wdemis commented 5 months ago

Transaction name does not seem to be set properly for PATCH requests when using Jersey

Description

We noticed that GET, PUT, POST, DELETE web request verbs will cause NewRelic to generate transactions with "name" set to: WebTransaction/RestWebService/v1/actions/{actionId} (GET) however the PATCH requests are being set to: WebTransaction/Servlet/jersey

Expected Behavior

The expectation is that all web requests return a consistent transaction name. For PATCH requests, we'd expect it to look similar to the other requests. In our case: WebTransaction/RestWebService/v1/actions/{actionId} (PATCH)

Troubleshooting

We setup two basic web request handlers in a controller. We setup NewRelic to run locally so that we could monitor the logs while debugging. Controller code was:

    @GET
    @Path("test/me")
    @Trace(metricName = "Endpoint - get")
    public Response testGet() {
        return Response.ok().entity(Map.of("result", "foo")).build();
    }

    @PATCH
    @Path("test/me")
    @Trace(metricName = "Endpoint - patch")
    public Response testPatch() {
        return Response.ok().entity(Map.of("result", "foo")).build();
    }

Hitting both endpoints produces the following logs:

PATCH <--------------
2024-05-14T14:59:44,695-0400 [7928 1] com.newrelic FINER: Setting transaction name to "Java/org.glassfish.jersey.servlet.ServletContainer/init" for transaction com.newrelic.agent.Transaction@a8f1719
2024-05-14T15:00:35,832-0400 [7928 464] com.newrelic FINER: Setting transaction name using filter name: characterEncodingFilter
2024-05-14T15:00:35,832-0400 [7928 464] com.newrelic FINER: Setting transaction name to "characterEncodingFilter" for transaction com.newrelic.agent.Transaction@5d82b511
2024-05-14T15:00:35,833-0400 [7928 464] com.newrelic FINER: Setting transaction name using filter name: formContentFilter
2024-05-14T15:00:35,833-0400 [7928 464] com.newrelic FINER: Setting transaction name using filter name: requestContextFilter
2024-05-14T15:00:35,836-0400 [7928 464] com.newrelic FINER: Setting transaction name using filter name: springLoggingFilter
2024-05-14T15:00:35,837-0400 [7928 464] com.newrelic FINER: Setting transaction name using filter name: healthCheckFilter
2024-05-14T15:00:35,837-0400 [7928 464] com.newrelic FINER: Setting transaction name using servlet name: jersey
2024-05-14T15:00:35,837-0400 [7928 464] com.newrelic FINER: Setting transaction name to "jersey" for transaction com.newrelic.agent.Transaction@5d82b511

GET <--------------
2024-05-14T15:00:45,409-0400 [7928 465] com.newrelic FINER: Setting transaction name using filter name: characterEncodingFilter
2024-05-14T15:00:45,409-0400 [7928 465] com.newrelic FINER: Setting transaction name to "characterEncodingFilter" for transaction com.newrelic.agent.Transaction@62eaec05
2024-05-14T15:00:45,409-0400 [7928 465] com.newrelic FINER: Setting transaction name using filter name: formContentFilter
2024-05-14T15:00:45,410-0400 [7928 465] com.newrelic FINER: Setting transaction name using filter name: requestContextFilter
2024-05-14T15:00:45,410-0400 [7928 465] com.newrelic FINER: Setting transaction name using filter name: springLoggingFilter
2024-05-14T15:00:45,410-0400 [7928 465] com.newrelic FINER: Setting transaction name using filter name: healthCheckFilter
2024-05-14T15:00:45,410-0400 [7928 465] com.newrelic FINER: Setting transaction name using servlet name: jersey
2024-05-14T15:00:45,410-0400 [7928 465] com.newrelic FINER: Setting transaction name to "jersey" for transaction com.newrelic.agent.Transaction@62eaec05
2024-05-14T15:00:45,414-0400 [7928 465] com.newrelic FINER: Setting transaction name to "/v1/actions/test/me (GET)" for transaction com.newrelic.agent.Transaction@62eaec05

Steps to Reproduce

Create a jersey controller with a PATCH request handler. Hit endpoint and check NewRelic logs or Transactions table for transaction name.

Your Environment

            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>2.35</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>com.newrelic.agent.java</groupId>
                <artifactId>newrelic-api</artifactId>
                <version>8.2.0</version>
            </dependency>

Additional context

This resolved issue sure seems very similar; perhaps this was addressed for Spring and not Jersey?

workato-integration[bot] commented 5 months ago

https://new-relic.atlassian.net/browse/NR-268907

jtduffy commented 5 months ago

Hi @wdemis I tried to repro the issue using the attached sample Jersey app (created from the maven archetype -DarchetypeArtifactId=jersey-quickstart-grizzly2) and the PATCH method was reporting properly as WebTransaction/RestWebService/myresource (PATCH)

Can you provide a simple repro? There's obviously something different in your project that's not part of my simple app. Thanks! simple-service.zip

kford-newrelic commented 4 months ago

Closing. We'll need to have a viable repro app in order to investigate this further.