use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class Exporter method trackMessage.
private void trackMessage(SpanData span) {
TelemetryItem telemetry = new TelemetryItem();
MessageData data = new MessageData();
telemetryClient.initMessageTelemetry(telemetry, data);
Attributes attributes = span.getAttributes();
// set standard properties
setTime(telemetry, span.getStartEpochNanos());
setOperationTags(telemetry, span);
setSampleRate(telemetry, span);
setExtraAttributes(telemetry, data, attributes);
// set message-specific properties
String level = attributes.get(AI_LOG_LEVEL_KEY);
String loggerName = attributes.get(AI_LOGGER_NAME_KEY);
String threadName = attributes.get(SemanticAttributes.THREAD_NAME);
data.setVersion(2);
data.setSeverityLevel(toSeverityLevel(level));
data.setMessage(span.getName());
setLoggerProperties(data, level, loggerName, threadName);
// export
telemetryClient.trackAsync(telemetry);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class QuickPulseIntegrationTests method testPostRequest.
@Test
public void testPostRequest() throws InterruptedException {
ArrayBlockingQueue<HttpRequest> sendQueue = new ArrayBlockingQueue<>(256, true);
CountDownLatch pingCountDown = new CountDownLatch(1);
CountDownLatch postCountDown = new CountDownLatch(1);
Date currDate = new Date();
String expectedPingRequestBody = "\\{\"Documents\":null,\"InstrumentationKey\":null,\"Metrics\":null,\"InvariantVersion\":1,\"Timestamp\":\"\\\\/Date\\(\\d+\\)\\\\/\",\"Version\":\"\\(unknown\\)\",\"StreamId\":\"qpid123\",\"MachineName\":\"machine1\",\"Instance\":\"instance1\",\"RoleName\":null\\}";
String expectedPostRequestBody = "\\[\\{\"Documents\":\\[\\{\"__type\":\"RequestTelemetryDocument\",\"DocumentType\":\"Request\",\"Version\":\"1.0\",\"OperationId\":null,\"Properties\":\\{\"customProperty\":\"customValue\"\\},\"Name\":\"request-test\",\"Success\":true,\"Duration\":\"PT.*S\",\"ResponseCode\":\"200\",\"OperationName\":null,\"Url\":\"foo\"\\},\\{\"__type\":\"DependencyTelemetryDocument\",\"DocumentType\":\"RemoteDependency\",\"Version\":\"1.0\",\"OperationId\":null,\"Properties\":\\{\"customProperty\":\"customValue\"\\},\"Name\":\"dep-test\",\"Target\":null,\"Success\":true,\"Duration\":\"PT.*S\",\"ResultCode\":null,\"CommandName\":\"dep-test-cmd\",\"DependencyTypeName\":null,\"OperationName\":null\\},\\{\"__type\":\"ExceptionTelemetryDocument\",\"DocumentType\":\"Exception\",\"Version\":\"1.0\",\"OperationId\":null,\"Properties\":null,\"Exception\":\"\",\"ExceptionMessage\":\"test\",\"ExceptionType\":\"java.lang.Exception\"\\}\\],\"InstrumentationKey\":\"" + instrumentationKey + "\",\"Metrics\":\\[\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Requests\\\\\\/Sec\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Request Duration\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Requests Failed\\\\\\/Sec\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Requests Succeeded\\\\\\/Sec\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Dependency Calls\\\\\\/Sec\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Dependency Call Duration\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Dependency Calls Failed\\\\\\/Sec\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Dependency Calls Succeeded\\\\\\/Sec\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\ApplicationInsights\\\\\\\\Exceptions\\\\\\/Sec\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\Memory\\\\\\\\Committed Bytes\",\"Value\":\\d+,\"Weight\":\\d+\\},\\{\"Name\":\"\\\\\\\\Processor\\(_Total\\)\\\\\\\\% Processor Time\",\"Value\":-?\\d+,\"Weight\":\\d+\\}\\],\"InvariantVersion\":1,\"Timestamp\":\"\\\\\\/Date\\(\\d+\\)\\\\\\/\",\"Version\":\"[^\"]*\",\"StreamId\":null,\"MachineName\":\"machine1\",\"Instance\":\"instance1\",\"RoleName\":null\\}\\]";
QuickPulsePingSender pingSender = getQuickPulsePingSenderWithValidator(new ValidationPolicy(pingCountDown, expectedPingRequestBody));
QuickPulseHeaderInfo quickPulseHeaderInfo = pingSender.ping(null);
QuickPulseDataSender dataSender = new QuickPulseDataSender(getHttpPipeline(new ValidationPolicy(postCountDown, expectedPostRequestBody)), sendQueue);
TelemetryClient telemetryClient = TelemetryClient.createForTest();
telemetryClient.setConnectionString(connectionString);
QuickPulseDataFetcher dataFetcher = new QuickPulseDataFetcher(sendQueue, telemetryClient, "machine1", "instance1", null);
QuickPulseDataCollector.INSTANCE.setQuickPulseStatus(QuickPulseStatus.QP_IS_ON);
QuickPulseDataCollector.INSTANCE.enable(telemetryClient);
final long duration = 112233L;
// Request Telemetry
TelemetryItem requestTelemetry = createRequestTelemetry("request-test", currDate, duration, "200", true);
requestTelemetry.setInstrumentationKey(instrumentationKey);
QuickPulseDataCollector.INSTANCE.add(requestTelemetry);
// Dependency Telemetry
TelemetryItem dependencyTelemetry = createRemoteDependencyTelemetry("dep-test", "dep-test-cmd", duration, true);
dependencyTelemetry.setInstrumentationKey(instrumentationKey);
QuickPulseDataCollector.INSTANCE.add(dependencyTelemetry);
// Exception Telemetry
TelemetryItem exceptionTelemetry = createExceptionTelemetry(new Exception("test"));
exceptionTelemetry.setInstrumentationKey(instrumentationKey);
QuickPulseDataCollector.INSTANCE.add(exceptionTelemetry);
QuickPulseCoordinatorInitData initData = new QuickPulseCoordinatorInitDataBuilder().withDataFetcher(dataFetcher).withDataSender(dataSender).withPingSender(pingSender).withWaitBetweenPingsInMillis(10L).withWaitBetweenPostsInMillis(10L).withWaitOnErrorInMillis(10L).build();
QuickPulseCoordinator coordinator = new QuickPulseCoordinator(initData);
Thread coordinatorThread = new Thread(coordinator, QuickPulseCoordinator.class.getSimpleName());
coordinatorThread.setDaemon(true);
coordinatorThread.start();
Thread senderThread = new Thread(dataSender, QuickPulseDataSender.class.getSimpleName());
senderThread.setDaemon(true);
senderThread.start();
Thread.sleep(50);
assertTrue(pingCountDown.await(1, TimeUnit.SECONDS));
assertThat(quickPulseHeaderInfo.getQuickPulseStatus()).isEqualTo(QuickPulseStatus.QP_IS_ON);
assertThat(QuickPulseDataCollector.INSTANCE.getQuickPulseStatus()).isEqualTo(QuickPulseStatus.QP_IS_ON);
assertTrue(postCountDown.await(1, TimeUnit.SECONDS));
senderThread.interrupt();
coordinatorThread.interrupt();
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class QuickPulseTestBase method createExceptionTelemetry.
public static TelemetryItem createExceptionTelemetry(Exception exception) {
TelemetryItem telemetry = new TelemetryItem();
TelemetryExceptionData data = new TelemetryExceptionData();
TelemetryClient.createForTest().initExceptionTelemetry(telemetry, data);
data.setExceptions(getExceptions(exception));
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class QuickPulseTestBase method createRequestTelemetry.
public static TelemetryItem createRequestTelemetry(String name, Date timestamp, long durationMillis, String responseCode, boolean success) {
TelemetryItem telemetry = new TelemetryItem();
RequestData data = new RequestData();
TelemetryClient.createForTest().initRequestTelemetry(telemetry, data);
Map<String, String> properties = new HashMap<>();
properties.put("customProperty", "customValue");
data.setProperties(properties);
data.setName(name);
data.setDuration(FormattedDuration.fromMillis(durationMillis));
data.setResponseCode(responseCode);
data.setSuccess(success);
data.setUrl("foo");
telemetry.setTime(FormattedTime.offSetDateTimeFromDate(timestamp));
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class TelemetryChannelTest method dualIkeyBatchWithDelayTest.
@Test
public void dualIkeyBatchWithDelayTest() throws MalformedURLException {
// given
List<TelemetryItem> telemetryItems = new ArrayList<>();
telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 1, 1, INSTRUMENTATION_KEY));
telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 2, 2, INSTRUMENTATION_KEY));
telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 3, 3, REDIRECT_INSTRUMENTATION_KEY));
telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 4, 4, REDIRECT_INSTRUMENTATION_KEY));
TelemetryChannel telemetryChannel = getTelemetryChannel();
// when
CompletableResultCode completableResultCode = telemetryChannel.send(telemetryItems);
// then
assertThat(completableResultCode.isSuccess()).isEqualTo(true);
assertThat(recordingHttpClient.getCount()).isEqualTo(3);
completableResultCode = telemetryChannel.send(telemetryItems);
// then
// the redirect url should be cached and should not invoke another redirect.
assertThat(completableResultCode.isSuccess()).isEqualTo(true);
assertThat(recordingHttpClient.getCount()).isEqualTo(5);
}
Aggregations