Skip to content
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

Investigate gap in instrumentation with Spring WebFlux/Reactor when using subscribeOn(Schedulers.boundedElastic()) #1450

Closed
jasonjkeller opened this issue Aug 11, 2023 · 2 comments · Fixed by #1883
Assignees
Labels
2 Story Point Estimate

Comments

@jasonjkeller
Copy link
Contributor

This is a side issue that was noticed during the course of working on #1073

Below is a Spring controller that repros the problem and here is a zip of a repro app: newrelic-trace-on-util.zip

The problem is that the Transaction is lost and thus not linked when calling the response method via the /does-not-work route. Specifically this seems to be a result of using subscribeOn(Schedulers.boundedElastic()). In the past, we've seen cases where an unexpected thread hop occurred due to the use of subscribeOn(Schedulers.boundedElastic()) which caused the token linking failures.

package com.example.newrelictraceonutil;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.Transaction;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

@RestController
public class ExampleController {

    @GetMapping(path = "/works")
    public Mono<String> works() {
        return Mono.fromCallable(() -> response("works"));
    }

    @GetMapping(path = "/does-not-work")
    public Mono<String> doesNotWork() {
        return Mono.fromCallable(() -> response("does-not-work"))
                .subscribeOn(Schedulers.boundedElastic());
    }

    /*
     * When hitting the /works route the transaction is properly renamed to works-custom-transaction-name as it
     * has reference to a valid TransactionApiImpl and DefaultTracer
     *
     * When hitting the /does-not-work route the transaction is NOT renamed as the Transaction context has been lost,
     * and it has reference to a NoOpTransaction and NoOpTracedMethod
     */
    private String response(String endpoint) {
        NewRelic.setTransactionName("custom", endpoint + "-custom-transaction-name");
        NewRelic.addCustomParameter("custom.param", endpoint);

        Transaction transaction = NewRelic.getAgent().getTransaction();
        TracedMethod tracedMethod = transaction.getTracedMethod();
        return endpoint
                + "\nTransaction:  " + transaction
                + "\nTracedMethod: " + tracedMethod;
    }

}

Run the repro app and hit http://localhost:8080/does-not-work. The response output will indicate that a NoOpTransaction was present when response was called. Also the transaction will remain named does-not-work (GET).

does-not-work Transaction: com.newrelic.agent.bridge.NoOpTransaction@65fbde12 TracedMethod: com.newrelic.agent.bridge.NoOpTracedMethod@46a1dc43

Compare this to the working route http://localhost:8080/works. The response output will indicate that a TransactionApiImpl was present when response was called. The transaction is renamed to works-custom-transaction-name as expected.

works Transaction: com.newrelic.agent.TransactionApiImpl@ec51b31 TracedMethod: com.newrelic.agent.tracers.DefaultTracer@5745ebc4
txn-naming
@workato-integration
Copy link

workato-integration bot commented Aug 11, 2023

@kford-newrelic kford-newrelic added estimate Issue needing estimation oct-dec qtr Represents proposed work item for the Oct-Dec quarter labels Aug 14, 2023
@kford-newrelic kford-newrelic added jan-mar qtr Represents proposed work item for the Jan-Mar quarter and removed oct-dec qtr Represents proposed work item for the Oct-Dec quarter estimate Issue needing estimation labels Sep 20, 2023
@kford-newrelic kford-newrelic removed the jan-mar qtr Represents proposed work item for the Jan-Mar quarter label Jan 10, 2024
@meiao
Copy link
Contributor

meiao commented Apr 26, 2024

The solution for this ticket should also be ported to the reactor-3.3.0 instrumentation module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 Story Point Estimate
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants