Search in sources :

Example 16 with Token

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

the class AgentPostprocessorsTest method testApiTestClass.

private void testApiTestClass(Class<?> clazz, WeavePackageType weavePackageType) throws Exception {
    ThreadLocal<WeavePackageType> weavePackageTypeSpy = new ThreadLocal<WeavePackageType>() {

        @Override
        protected WeavePackageType initialValue() {
            return null;
        }
    };
    AgentBridge.currentApiSource = spy(weavePackageTypeSpy);
    ApiTestClass testClass = (ApiTestClass) clazz.newInstance();
    // Token API
    assertBeforeApi();
    Token token = testClass.getToken();
    assertNotNull(token);
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    com.newrelic.api.agent.Transaction transaction = testClass.getTransaction();
    assertNotNull(transaction);
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.getTokenNoReturn();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.getTokenNoReturnException();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.getTokenSeparateLinkExpireNoReturn();
    assertAfterApi(3, weavePackageType);
    assertBeforeApi();
    testClass.getTokenSeparateLinkExpireNoReturnException();
    assertAfterApi(3, weavePackageType);
    // Token API (Bridge)
    assertBeforeApi();
    com.newrelic.agent.bridge.Token tokenBridge = testClass.getTokenBridge();
    assertNotNull(tokenBridge);
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    Transaction transactionBridge = testClass.getTransactionBridge();
    assertNotNull(transactionBridge);
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.getTokenNoReturnBridge();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.getTokenNoReturnExceptionBridge();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.getTokenSeparateLinkExpireNoReturnBridge();
    assertAfterApi(3, weavePackageType);
    assertBeforeApi();
    testClass.getTokenSeparateLinkExpireNoReturnExceptionBridge();
    assertAfterApi(3, weavePackageType);
    // Segment API
    assertBeforeApi();
    testClass.startSegmentNoArgsWithTx(NewRelic.getAgent().getTransaction());
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentNoArgs();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentNoArgsNoReturn();
    assertAfterApi(3, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentNoArgsNoReturnException();
    assertAfterApi(3, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentArgs();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentArgsNoReturn();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentArgsNoReturnException();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentNoArgsWithGetToken();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentNoArgsNoReturnWithGetToken();
    assertAfterApi(3, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentNoArgsNoReturnExceptionWithGetToken();
    assertAfterApi(3, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentArgsWithGetToken();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentArgsNoReturnWithGetToken();
    assertAfterApi(4, weavePackageType);
    assertBeforeApi();
    testClass.startSegmentArgsNoReturnExceptionWithGetToken();
    assertAfterApi(3, weavePackageType);
    // TracedActivity API (Bridge)
    assertBeforeApi();
    testClass.createAndStartTracedActivity();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.createAndStartTracedActivityNoReturn();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.createAndStartTracedActivityNoReturnException();
    assertAfterApi(1, weavePackageType);
    // NewRelic API
    assertBeforeApi();
    testClass.noticeErrorWithStringAndEmptyMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.noticeErrorWithStringAndMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.noticeErrorWithThrowableAndEmptyMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.noticeErrorWithThrowableAndMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.noticeErrorExpectedWithStringAndEmptyMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.noticeErrorExpectedWithStringAndMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.noticeErrorExpectedWithThrowableAndEmptyMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.noticeErrorExpectedWithThrowableAndMap();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.addCustomParameter();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.ignoreApdexNewRelic();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.ignoreTransaction();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setAppServerPort();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setInstanceName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setServerInfo();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setTransactionNameNewRelic();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setUserName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setProductName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setAccountName();
    assertAfterApi(1, weavePackageType);
    // Transaction API
    assertBeforeApi();
    testClass.ignore();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.ignoreApdexTransaction();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.processRequestMetadata();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.processResponseMetadataWithURI();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.processResponseMetadata();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.setTransactionName();
    assertAfterApi(1, weavePackageType);
    // Transaction API (Bridge)
    assertBeforeApi();
    testClass.setTransactionNameBridge();
    assertAfterApi(1, weavePackageType);
    // TracedMethod API
    assertBeforeApi();
    testClass.reportAsExternal();
    assertAfterApi(1, weavePackageType);
    // TracedMethod API (Bridge)
    assertBeforeApi();
    testClass.reportAsExternalBridge();
    assertAfterApi(1, weavePackageType);
    // Insights API
    assertBeforeApi();
    testClass.recordCustomEvent();
    assertAfterApi(1, weavePackageType);
    // Public API
    assertBeforeApi();
    testClass.publicApiCustomParameter();
    assertAfterApi(2, weavePackageType);
    assertBeforeApi();
    testClass.publicApiBrowserHeaderFooter();
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.publicApiIgnoreApdex();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiIgnoreTransaction();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiNoticeError();
    assertAfterApi(8, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetAccountName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetAppServerPort();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetInstanceName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetProductName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetRequestAndResponse();
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetServerInfo();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetTransactionName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.publicApiSetUserName();
    assertAfterApi(1, weavePackageType);
    // Private API
    assertBeforeApi();
    testClass.privateApiCustomAttribute();
    assertAfterApi(3, weavePackageType);
    assertBeforeApi();
    testClass.privateApiMBeanServer();
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.privateApiSampler();
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.privateApiTracerParameter();
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.privateApiReportError();
    assertAfterApi(0, weavePackageType);
    assertBeforeApi();
    testClass.privateApiSetServerInfo();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.privateApiSetAppServerPort();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    testClass.privateApiSetInstanceName();
    assertAfterApi(1, weavePackageType);
    assertBeforeApi();
    boolean exceptionThrown = false;
    try {
        testClass.throwExceptionTest();
    } catch (IOException e) {
        exceptionThrown = true;
    }
    if (!exceptionThrown) {
        fail("Exception was expected but not thrown");
    }
    assertAfterApi(1, exceptionThrown ? 0 : 1, weavePackageType);
}
Also used : WeavePackageType(com.newrelic.api.agent.weaver.internal.WeavePackageType) Token(com.newrelic.api.agent.Token) IOException(java.io.IOException) Transaction(com.newrelic.agent.bridge.Transaction)

Example 17 with Token

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

the class HttpClientRequestImpl_Instrumentation method doHandleResponse.

@Trace(async = true)
protected void doHandleResponse(HttpClientResponseImpl resp) {
    if (segment != null) {
        VertxCoreUtil.processResponse(segment, resp, resp.request().host, port, ssl ? "https" : "http");
        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)

Example 18 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(HttpClientResponseImpl 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)

Example 19 with Token

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

the class MessageProcessor_Instrumentation method process.

/**
 * Invokes the MessageProcessor.
 */
@Trace(async = true, excludeFromTransactionTrace = true)
public MuleEvent process(MuleEvent event) {
    Object tokenKey = event.getFlowVariable(MuleUtils.MULE_EVENT_TOKEN_KEY);
    if (tokenKey != null) {
        MuleUtils.FlowKey key = (MuleUtils.FlowKey) tokenKey;
        Token token = MuleUtils.getToken(key);
        if (token != null) {
            token.link();
        }
    }
    return Weaver.callOriginal();
}
Also used : Token(com.newrelic.api.agent.Token) MuleUtils(com.nr.agent.instrumentation.mule3.MuleUtils) Trace(com.newrelic.api.agent.Trace)

Example 20 with Token

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

the class LambdaMonoSubscriber_Instrumentation method onComplete.

public final void onComplete() {
    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)

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