use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.
the class TransactionTest method createDispatcherTracer.
// Create a Tracer for tests that require one.
private Tracer createDispatcherTracer(boolean createRequest) {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
if (createRequest) {
MockHttpRequest httpRequest = new MockHttpRequest();
MockHttpResponse httpResponse = new MockHttpResponse();
return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
} else {
return new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("thisismyname"));
}
}
use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method startDispatcherTracer.
private Tracer startDispatcherTracer(String appName, String uri) throws Exception {
Transaction tx = Transaction.getTransaction();
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setRequestURI(uri);
MockHttpResponse httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
BasicRequestRootTracer requestDispatcherTracer = new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
Dispatcher dispatcher = requestDispatcherTracer.createDispatcher();
tx.getTransactionActivity().tracerStarted(requestDispatcherTracer);
tx.setDispatcher(dispatcher);
tx.setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, appName);
return requestDispatcherTracer;
}
use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method createDispatcherTracer.
private BasicRequestRootTracer createDispatcherTracer() {
Transaction tx = Transaction.getTransaction();
MockHttpRequest httpRequest = new MockHttpRequest();
MockHttpResponse httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
}
use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method startDispatcherTracer.
private Tracer startDispatcherTracer(String appName) throws Exception {
Transaction tx = Transaction.getTransaction();
MockHttpRequest httpRequest = new MockHttpRequest();
MockHttpResponse httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
Tracer requestDispatcherTracer = new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
tx.getTransactionActivity().tracerStarted(requestDispatcherTracer);
tx.setApplicationName(ApplicationNamePriority.REQUEST_ATTRIBUTE, appName);
return requestDispatcherTracer;
}
use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.
the class W3CTraceContextCrossAgentTest method testTraceContext.
@Test
public void testTraceContext() throws Exception {
String testName = (String) testData.get("test_name");
String accountKey = (String) testData.get("trusted_account_key");
String accountId = (String) testData.get("account_id");
String transportType = (String) testData.get("transport_type");
Boolean webTransaction = (Boolean) testData.get("web_transaction");
Boolean raisesException = (Boolean) testData.get("raises_exception");
Boolean forceSampledTrue = (Boolean) testData.get("force_sampled_true");
Boolean spanEventsEnabled = (Boolean) testData.get("span_events_enabled");
replaceConfig(spanEventsEnabled);
System.out.println("Running test: " + testName);
JSONArray outbound_payloads = (JSONArray) testData.get("outbound_payloads");
JSONArray inbound_payloads = (JSONArray) testData.get("inbound_headers");
List expectedMetrics = (List) testData.get("expected_metrics");
Map<String, Object> intrinsics = (Map<String, Object>) testData.get("intrinsics");
Map<String, Object> commonAssertions = intrinsics == null ? Collections.<String, Object>emptyMap() : (Map<String, Object>) intrinsics.get("common");
List targetEvents = intrinsics == null ? Collections.emptyList() : (ArrayList) intrinsics.get("target_events");
Map<String, Object> transactionAssertions = intrinsics == null ? Collections.<String, Object>emptyMap() : (Map<String, Object>) intrinsics.get("Transaction");
Map<String, Object> spanAssertions = intrinsics == null ? Collections.<String, Object>emptyMap() : (Map<String, Object>) intrinsics.get("Span");
Map<String, Object> connectInfo = Maps.newHashMap();
connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, accountId);
connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, accountKey);
connectInfo.put(DistributedTracingConfig.PRIMARY_APPLICATION_ID, "2827902");
AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
distributedTraceService.connected(null, agentConfig);
Transaction.clearTransaction();
TransactionActivity.clear();
spanEventService.clearReservoir();
Transaction tx = Transaction.getTransaction();
TransactionData transactionData = new TransactionData(tx, 0);
TransactionStats transactionStats = transactionData.getTransaction().getTransactionActivity().getTransactionStats();
eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<String> parents = Lists.newArrayList();
List<String> states = Lists.newArrayList();
List<String> newrelic = Lists.newArrayList();
if (inbound_payloads != null) {
for (Object payload : inbound_payloads) {
JSONObject j = (JSONObject) payload;
if (j.get("traceparent") != null) {
parents.addAll(Lists.newArrayList(String.valueOf(j.get("traceparent"))));
}
if (j.get("tracestate") != null) {
states.addAll(Lists.newArrayList(String.valueOf(j.get("tracestate"))));
}
if (j.get("newrelic") != null) {
newrelic.addAll(Lists.newArrayList(String.valueOf(j.get("newrelic"))));
}
}
}
MockHttpRequest httpRequest = new MockHttpRequest();
for (String parent : parents) {
httpRequest.setHeader("traceparent", parent);
}
for (String state : states) {
httpRequest.setHeader("tracestate", state);
}
for (String header : newrelic) {
httpRequest.setHeader("newrelic", header);
}
Tracer rootTracer;
if (webTransaction) {
rootTracer = TransactionAsyncUtility.createAndStartDispatcherTracer(this, "WebTransaction", httpRequest);
} else {
rootTracer = TransactionAsyncUtility.createOtherTracer("OtherTransaction");
tx.getTransactionActivity().tracerStarted(rootTracer);
tx.provideRawHeaders(httpRequest);
}
if (raisesException) {
tx.setThrowable(new Throwable(), TransactionErrorPriority.API, false);
}
setTransportType(tx, transportType);
if (forceSampledTrue && tx.getPriority() < 1) {
tx.setPriorityIfNotNull(new Random().nextFloat() + 1.0f);
}
if (outbound_payloads != null) {
for (Object assertion : outbound_payloads) {
MockHttpResponse mockHttpResponse = new MockHttpResponse();
tx.getCrossProcessState().processOutboundRequestHeaders(mockHttpResponse);
JSONObject payloadAssertions = (JSONObject) assertion;
String traceparent = mockHttpResponse.getHeader("traceparent");
String tracestate = mockHttpResponse.getHeader("tracestate");
if (traceparent != null) {
W3CTraceParent traceParent = W3CTraceParentParser.parseHeaders(Collections.singletonList(traceparent));
assertOutboundTraceParentPayload(payloadAssertions, traceParent);
} else {
assertOutboundTraceParentPayload(payloadAssertions, null);
}
if (tracestate != null) {
assertOutboundTraceStatePayload(payloadAssertions, W3CTraceStateSupport.parseHeaders(Collections.singletonList(mockHttpResponse.getHeader("tracestate"))));
} else {
assertOutboundTraceStatePayload(payloadAssertions, null);
}
}
}
rootTracer.finish(Opcodes.RETURN, 0);
List<SpanEvent> spans = eventPool.asList();
TransactionEvent transactionEvent = serviceManager.getTransactionEventsService().createEvent(transactionData, transactionStats, "wat");
JSONObject txnEvents = serializeAndParseEvents(transactionEvent);
StatsEngine statsEngine = statsService.getStatsEngineForHarvest(APP_NAME);
assertExpectedMetrics(expectedMetrics, statsEngine);
for (Object event : targetEvents) {
if (event.toString().startsWith("Transaction") && transactionAssertions != null) {
assertTransactionEvents(transactionAssertions, txnEvents);
assertTransactionEvents(commonAssertions, txnEvents);
} else if (event.toString().startsWith("Span") && spanAssertions != null) {
assertSpanEvents(spanAssertions, spans);
assertSpanEvents(commonAssertions, spans);
}
}
}
Aggregations