Search in sources :

Example 6 with InboundHeaders

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

the class TransactionInboundHeadersTest method testEmptyInstrumentationProvidedHeaders.

@Test
public void testEmptyInstrumentationProvidedHeaders() {
    Transaction tx = Transaction.getTransaction();
    InboundHeaders headers = createEmptyHTTPInboundHeaders();
    tx.provideHeaders(headers);
    InboundHeaderState inboundHeaderState = tx.getInboundHeaderState();
    Assert.assertTrue(inboundHeaderState != null);
    Assert.assertNull(inboundHeaderState.getClientCrossProcessId());
    Assert.assertNull(inboundHeaderState.getUnparsedSyntheticsHeader());
    Assert.assertNull(inboundHeaderState.getReferrerGuid());
}
Also used : InboundHeaders(com.newrelic.api.agent.InboundHeaders) Test(org.junit.Test)

Example 7 with InboundHeaders

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

the class CrossProcessTransactionStateImpl method processResponseMetadata.

@Override
public void processResponseMetadata(String responseMetadata, URI uri) {
    if (tx.getAgentConfig().getDistributedTracingConfig().isEnabled()) {
        Agent.LOG.log(Level.FINEST, "Distributed tracing is enabled. Ignoring processResponseMetadata call.");
        return;
    }
    if (!tx.getCrossProcessConfig().isCrossApplicationTracing()) {
        return;
    }
    if (responseMetadata == null) {
        return;
    }
    Tracer lastTracer = tx.getTransactionActivity().getLastTracer();
    if (lastTracer == null) {
        return;
    }
    InboundHeaders NRHeaders = decodeMetadata(responseMetadata);
    if (NRHeaders != null) {
        /*
              One of our public APIs doesn't have a URI parameter, so we may not know the host or URI.

              See {@link com.newrelic.api.agent.Transaction#processResponseMetadata(String)}
             */
        String host = (uri == null || uri.getHost() == null) ? UNKNOWN_HOST : uri.getHost();
        String uriString = (uri == null) ? null : uri.toString();
        String decodedAppData = HeadersUtil.getAppDataHeader(NRHeaders);
        CrossProcessNameFormat crossProcessFormat = CrossProcessNameFormat.create(host, uriString, decodedAppData);
        doProcessInboundResponseHeaders(lastTracer, crossProcessFormat, host, true);
        MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_PROCESS_RESPONSE_METADATA);
    }
}
Also used : CrossProcessNameFormat(com.newrelic.agent.tracers.CrossProcessNameFormat) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) InboundHeaders(com.newrelic.api.agent.InboundHeaders)

Example 8 with InboundHeaders

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

the class CrossProcessTransactionStateImpl method processRequestMetadata.

@Override
public void processRequestMetadata(String requestMetadata) {
    if (tx.getAgentConfig().getDistributedTracingConfig().isEnabled()) {
        Agent.LOG.log(Level.FINEST, "Distributed tracing is enabled. Ignoring processRequestMetadata call.");
        return;
    }
    InboundHeaders headers = decodeMetadata(requestMetadata);
    Transaction currentTxn = Transaction.getTransaction(false);
    if (currentTxn != null) {
        currentTxn.provideRawHeaders(headers);
    }
    MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_PROCESS_REQUEST_METADATA);
}
Also used : InboundHeaders(com.newrelic.api.agent.InboundHeaders)

Example 9 with InboundHeaders

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

the class DefaultTracer method reportAsExternal.

@Override
public void reportAsExternal(ExternalParameters externalParameters) {
    if (Agent.LOG.isFineEnabled()) {
        Agent.LOG.log(Level.FINE, "Setting externalParameters to: " + externalParameters);
    }
    MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_REPORT_AS_EXTERNAL);
    this.externalParameters = externalParameters;
    if (this.externalParameters instanceof HttpParameters) {
        // URI validity check and logging
        HttpParameters httpParameters = (HttpParameters) this.externalParameters;
        URI uri = httpParameters.getUri();
        if (uri == null || uri.getScheme() == null || uri.getHost() == null || uri.getPort() == -1) {
            Agent.LOG.log(Level.FINE, "URI parameter passed to HttpParameters should include a valid scheme, host, and port.");
        }
        InboundHeaders headers = httpParameters.getInboundResponseHeaders();
        if (null != headers) {
            readInboundResponseHeaders(headers);
        }
    } else if (this.externalParameters instanceof MessageProduceParameters) {
        catForMessaging(((MessageProduceParameters) this.externalParameters));
    } else if (this.externalParameters instanceof MessageConsumeParameters) {
        catForMessaging(((MessageConsumeParameters) this.externalParameters));
    }
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) InboundHeaders(com.newrelic.api.agent.InboundHeaders) MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) URI(java.net.URI)

Example 10 with InboundHeaders

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

the class DefaultTracer method catForMessaging.

private void catForMessaging(MessageConsumeParameters consumeParameters) {
    InboundHeaders headers = consumeParameters.getInboundHeaders();
    if (headers == null) {
        return;
    }
    // In amqp we don't know if we're sending a request or a response.
    DestinationType destinationType = consumeParameters.getDestinationType();
    if (destinationType == DestinationType.EXCHANGE) {
        getTransaction().provideHeaders(headers);
    } else // 2. Consuming a message from a temporary queue, it is processing a response (inbound response).
    if (destinationType == DestinationType.NAMED_QUEUE || destinationType == DestinationType.NAMED_TOPIC) {
        getTransaction().provideHeaders(headers);
    } else if (destinationType == DestinationType.TEMP_QUEUE || destinationType == DestinationType.TEMP_TOPIC) {
        // Do not replace with recordInboundResponseHeaders.
        // recordInboundResponseHeaders assumes we do CAT request/response in the same tracer.
        Transaction transaction = getTransactionActivity().getTransaction();
        transaction.getCrossProcessState().processInboundResponseHeaders(headers, this, "Unknown", null, true);
    } else {
        Agent.LOG.log(Level.FINE, "Unexpected destination type when reporting external metrics for message consume.");
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) InboundHeaders(com.newrelic.api.agent.InboundHeaders) DestinationType(com.newrelic.api.agent.DestinationType)

Aggregations

InboundHeaders (com.newrelic.api.agent.InboundHeaders)10 Test (org.junit.Test)4 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)3 Transaction (com.newrelic.agent.Transaction)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 CrossProcessConfig (com.newrelic.agent.config.CrossProcessConfig)1 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 CrossProcessNameFormat (com.newrelic.agent.tracers.CrossProcessNameFormat)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1 TransactionCounts (com.newrelic.agent.transaction.TransactionCounts)1 DestinationType (com.newrelic.api.agent.DestinationType)1 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)1 HttpParameters (com.newrelic.api.agent.HttpParameters)1 MessageConsumeParameters (com.newrelic.api.agent.MessageConsumeParameters)1