Search in sources :

Example 1 with Token

use of com.newrelic.api.agent.Token in project ab2d by CMSgov.

the class PatientClaimsProcessorImpl method process.

/**
 * Process the retrieval of patient explanation of benefit objects and return the result
 * for further post-processing
 */
@Async("patientProcessorThreadPool")
public Future<ProgressTrackerUpdate> process(PatientClaimsRequest request) {
    ProgressTrackerUpdate update = new ProgressTrackerUpdate();
    final Token token = request.getToken();
    token.link();
    FhirVersion fhirVersion = request.getVersion();
    try {
        String anyErrors = writeOutData(request, fhirVersion, update);
        if (anyErrors != null && anyErrors.length() > 0) {
            writeOutErrors(anyErrors, request);
        }
    } catch (Exception ex) {
        return AsyncResult.forExecutionException(ex);
    } finally {
        token.expire();
    }
    return AsyncResult.forValue(update);
}
Also used : FhirVersion(gov.cms.ab2d.fhir.FhirVersion) Token(com.newrelic.api.agent.Token) ParseException(java.text.ParseException) IOException(java.io.IOException) Async(org.springframework.scheduling.annotation.Async)

Example 2 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class MuleUtils method handleException.

/**
 * If a flow terminates due to an exception, check if there was a listener or an async token associated with it and
 * clean them up. If a listener was registered, it might not receive the processing complete notification, so we
 * have to loop through every one and check if its one of our custom listeners, pull out its mule event, and check
 * its event id to see if it matches the event id of the event that caused the exception.
 */
public static void handleException(MuleEvent muleEvent) {
    if (muleEvent != null) {
        FlowKey key = new FlowKey(muleEvent.getFlowConstruct().getName(), muleEvent.getId());
        Token token = MuleUtils.removeToken(key);
        if (token != null) {
            token.expire();
            Set<ListenerSubscriptionPair> listeners = muleEvent.getMuleContext().getNotificationManager().getListeners();
            Set<ServerNotificationListener> removals = new HashSet<>();
            for (ListenerSubscriptionPair lsp : listeners) {
                if (lsp.getListener() instanceof NRPipelineMessageNotificationListener) {
                    NRPipelineMessageNotificationListener nrlistener = (NRPipelineMessageNotificationListener) lsp.getListener();
                    if (nrlistener.getMuleEvent().getId() == muleEvent.getId()) {
                        NewRelic.getAgent().getLogger().log(Level.FINEST, "MuleUtils#handleException unregistering listener = {0} due to exception", lsp);
                        removals.add(lsp.getListener());
                    }
                }
            }
            muleEvent.getMuleContext().getNotificationManager().removeAllListeners(removals);
        }
    }
}
Also used : ServerNotificationListener(org.mule.api.context.notification.ServerNotificationListener) Token(com.newrelic.api.agent.Token) ListenerSubscriptionPair(org.mule.context.notification.ListenerSubscriptionPair) HashSet(java.util.HashSet)

Example 3 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class ChannelOperations_Instrumentation method applyHandler.

/**
 * Currently misses the majority of the work inside applyHandler because it only does:
 * Mono.fromDirect(handler.apply((INBOUND) this, (OUTBOUND) this)).subscribe(this);
 *
 * And we aren't instrumenting Mono
 */
@Trace(async = true)
protected final void applyHandler() {
    // not an interface method
    Token token = channel.pipeline().reactiveLayerToken;
    if (token != null) {
        token.linkAndExpire();
        channel.pipeline().reactiveLayerToken = null;
    }
    Weaver.callOriginal();
}
Also used : Token(com.newrelic.api.agent.Token) Trace(com.newrelic.api.agent.Trace)

Example 4 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class LambdaSubscriber_Instrumentation method onError.

public final void onError(Throwable t) {
    Token token = this.currentContext().getOrDefault("newrelic-token", null);
    if (token != null) {
        token.expire();
        this.nrContext = null;
    }
    Weaver.callOriginal();
}
Also used : Token(com.newrelic.api.agent.Token)

Example 5 with Token

use of com.newrelic.api.agent.Token in project newrelic-java-agent by newrelic.

the class HttpClientRequestBase_Instrumentation method handleResponse.

@Trace(async = true)
void handleResponse(HttpClientResponse resp) {
    if (segment != null) {
        reportExternal(resp, segment);
        final Token token = segment.getTransaction().getToken();
        segment.end();
        token.linkAndExpire();
    }
    Weaver.callOriginal();
}
Also used : Token(com.newrelic.api.agent.Token) Trace(com.newrelic.api.agent.Trace)

Aggregations

Token (com.newrelic.api.agent.Token)24 Trace (com.newrelic.api.agent.Trace)8 Transaction (com.newrelic.agent.Transaction)4 Tracer (com.newrelic.agent.tracers.Tracer)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 TransactionActivity (com.newrelic.agent.TransactionActivity)1 NoOpToken (com.newrelic.agent.bridge.NoOpToken)1 Transaction (com.newrelic.agent.bridge.Transaction)1 WeavePackageType (com.newrelic.api.agent.weaver.internal.WeavePackageType)1 MuleUtils (com.nr.agent.instrumentation.mule3.MuleUtils)1 Job (gov.cms.ab2d.common.model.Job)1 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)1 FhirVersion (gov.cms.ab2d.fhir.FhirVersion)1 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1