Class NewRelicTelemetryMiddleware

All Implemented Interfaces:
Middleware, TelemetryMiddleware

public class NewRelicTelemetryMiddleware extends Object implements TelemetryMiddleware

The NewRelicTelemetry middleware can be used to report outgoing request to commercetools to NewRelic. It can be registered as TelemetryMiddleware to the ClientBuilder or the ApiRootBuilder.

ApiHttpClient client = ApiRootBuilder.of()
        .withTelemetryMiddleware(new NewRelicTelemetryMiddleware())

See the test code.

The middleware reads the NewRelicContext from the Request and restores the transaction using a Token The details of the request and response are then reported as Segment with HttpParameters

The Context has to be attached in your application either to a ContextApiHttpClient or the Request itself.

ContextApiHttpClient contextClient = ContextApiHttpClient.of(apiHttpClient,
    NewRelicContext.of(NewRelic.getAgent().getTransaction()), false // don't close the ApiHttpClient
ProjectApiRoot apiRoot = ProjectApiRoot.fromClient(projectKey, contextClient);

See the test code.

ProjectApiRoot apiRoot = ProjectApiRoot.withContext(projectKey, apiHttpClient,
    NewRelicContext.of(NewRelic.getAgent().getTransaction()), false // don't close the apiHttpClient

See the test code.

The NewRelicContextImpl will expire the Token when it's closed. Closing a Context is ensured by ContextApiHttpClient if it's implementing Closeable See also the Spring MVC example application in the examples folder for further details.