use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanEventHttp.
@Test
public void testSpanEventHttp() {
DefaultTracer tracer = prepareTracer();
tracer.reportAsExternal(HttpParameters.library("library").uri(URI.create("http://www.newrelic.com")).procedure("call").noInboundHeaders().build());
tracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertNull(spanEvent.getParentId());
assertEquals("library", spanEvent.getIntrinsics().get("component"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
assertEquals("http://www.newrelic.com", spanEvent.getAgentAttributes().get("http.url"));
assertEquals("call", spanEvent.getAgentAttributes().get("http.method"));
}
use of com.newrelic.agent.model.SpanEvent 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);
}
}
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class XmlRpcPointCutTest method externalTest.
@Test
public void externalTest() throws Exception {
EnvironmentHolderSettingsGenerator envHolderSettings = new EnvironmentHolderSettingsGenerator(CONFIG_FILE, "all_enabled_test", CLASS_LOADER);
EnvironmentHolder holder = new EnvironmentHolder(envHolderSettings);
holder.setupEnvironment();
try {
doCall();
SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
assertNotNull(spanEventsPool);
List<SpanEvent> spanEvents = spanEventsPool.asList();
assertNotNull(spanEvents);
assertEquals(2, spanEvents.size());
boolean java = false;
boolean external = false;
for (SpanEvent span : spanEvents) {
String name = (String) span.getIntrinsics().get("name");
if (name.equals("External/newrelic.com/XmlRpc/invoke")) {
external = true;
assertEquals("XmlRpc", span.getIntrinsics().get("component"));
assertEquals("http", span.getIntrinsics().get("category"));
assertEquals("http://newrelic.com", span.getAgentAttributes().get("http.url"));
} else if (name.equals("Java/com.newrelic.agent.instrumentation.pointcuts.javax.xml.rpc.XmlRpcPointCutTest/doCall")) {
java = true;
assertEquals("generic", span.getIntrinsics().get("category"));
}
}
assertTrue("Unexpected span events found", java && external);
} finally {
holder.close();
}
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class IntrospectorServiceManager method setup.
private void setup(Map<String, Object> config) {
configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), Collections.<String, Object>emptyMap());
ServiceFactory.setServiceManager(this);
coreService = new IntrospectorCoreService();
threadService = new ThreadService();
environmentService = new EnvironmentServiceImpl();
transactionService = new TransactionService();
rpmConnectionService = new IntrospectorRPMConnectService();
rpmServiceManager = new IntrospectorRPMServiceManager();
transactionTraceService = new IntrospectorTransactionTraceService();
asyncTxService = new AsyncTransactionService();
profilerService = new ProfilerService();
statsService = new IntrospectorStatsService();
harvestService = new IntrospectorHarvestService();
sqlTraceService = new SqlTraceServiceImpl();
insightsService = new IntrospectorInsightsService();
logSenderService = new IntrospectorLogSenderService();
expirationService = new ExpirationService();
dbService = new DatabaseService();
jarCollectorService = new IgnoringJarCollectorService();
distributedTraceService = new DistributedTraceServiceImpl();
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
transactionEventsService = new TransactionEventsService(transactionDataToDistributedTraceIntrinsics);
normalizationService = new NormalizationServiceImpl();
extensionService = new ExtensionService(configService, ExtensionsLoadedListener.NOOP);
tracerService = new TracerService();
commandParser = new CommandParser();
remoteInstrumentationService = new RemoteInstrumentationServiceImpl();
sourceLanguageService = new SourceLanguageService();
classTransformerService = new NoOpClassTransformerService();
jmxService = new JmxService(configService.getDefaultAgentConfig().getJmxConfig());
attributesService = new AttributesService();
circuitBreakerService = new CircuitBreakerService();
AgentConfig agentConfig = createAgentConfig(config, (Map) config.get("distributed_tracing"));
distributedTraceService.connected(null, agentConfig);
ReservoirManager<SpanEvent> reservoirManager = new CollectorSpanEventReservoirManager(configService);
ReservoirManager.EventSender<SpanEvent> collectorSender = new CollectorSpanEventSender(rpmServiceManager);
Consumer<SpanEvent> infiniteTracing = new Consumer<SpanEvent>() {
@Override
public void accept(SpanEvent spanEvent) {
}
};
SpanEventCreationDecider spanEventCreationDecider = new SpanEventCreationDecider(configService);
spanEventsService = new IntrospectorSpanEventService(agentConfig, reservoirManager, collectorSender, infiniteTracing, spanEventCreationDecider, environmentService, transactionDataToDistributedTraceIntrinsics);
configService.addIAgentConfigListener((IntrospectorSpanEventService) spanEventsService);
transactionService.addTransactionListener((IntrospectorSpanEventService) spanEventsService);
try {
transactionTraceService.start();
transactionEventsService.start();
transactionService.start();
} catch (Exception e) {
// fall through
}
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class SpanErrorsTest method checkSpans.
private void checkSpans(Map<String, List<String>> spanChecks, List<String> defaultChecks) {
SamplingPriorityQueue<SpanEvent> reservoir = ServiceFactory.getSpanEventService().getOrCreateDistributedSamplingReservoir(APP_NAME);
assertTrue(reservoir.asList().size() > 0);
for (SpanEvent event : reservoir.asList()) {
if (spanChecks.containsKey(event.getName())) {
assertEquals("wrong error.message for " + event.getName(), spanChecks.get(event.getName()).get(0), event.getAgentAttributes().get("error.message"));
assertEquals("wrong error.class for " + event.getName(), spanChecks.get(event.getName()).get(1), event.getAgentAttributes().get("error.class"));
} else {
assertEquals("wrong error.message for " + event.getName(), defaultChecks.get(0), event.getAgentAttributes().get("error.message"));
assertEquals("wrong error.class for " + event.getName(), defaultChecks.get(1), event.getAgentAttributes().get("error.class"));
}
assertNull("error.status should never be on " + event.getName(), event.getAgentAttributes().get("error.status"));
}
}
Aggregations