use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class TelemetryChannelTest method dualIkeyBatchTest.
@Test
public void dualIkeyBatchTest() 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);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class TelemetryChannelTest method dualIkeyTest.
@Test
public void dualIkeyTest() throws MalformedURLException {
// given
List<TelemetryItem> telemetryItems = new ArrayList<>();
telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 1, 1, INSTRUMENTATION_KEY));
telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 2, 2, REDIRECT_INSTRUMENTATION_KEY));
TelemetryChannel telemetryChannel = getTelemetryChannel();
// when
CompletableResultCode completableResultCode = telemetryChannel.send(telemetryItems);
// then
assertThat(completableResultCode.isSuccess()).isEqualTo(true);
assertThat(recordingHttpClient.getCount()).isEqualTo(3);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class BytecodeUtilImpl method trackException.
@Override
public void trackException(Date timestamp, Exception exception, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
if (exception == null) {
return;
}
TelemetryItem telemetry = new TelemetryItem();
TelemetryExceptionData data = new TelemetryExceptionData();
TelemetryClient.getActive().initExceptionTelemetry(telemetry, data);
data.setExceptions(TelemetryUtil.getExceptions(exception));
data.setSeverityLevel(SeverityLevel.ERROR);
data.setMeasurements(metrics);
if (!properties.isEmpty()) {
Map<String, String> existingProperties = data.getProperties();
if (existingProperties == null) {
data.setProperties(properties);
} else {
existingProperties.putAll(properties);
}
}
if (timestamp != null) {
telemetry.setTime(FormattedTime.offSetDateTimeFromDate(timestamp));
} else {
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
}
selectivelySetTags(telemetry, tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
}
track(telemetry, true);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class BytecodeUtilImpl method trackMetric.
// TODO do not track if perf counter (?)
@Override
public void trackMetric(Date timestamp, String name, double value, Integer count, Double min, Double max, Double stdDev, Map<String, String> properties, Map<String, String> tags, String instrumentationKey) {
if (Strings.isNullOrEmpty(name)) {
return;
}
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
TelemetryClient.getActive().initMetricTelemetry(telemetry, data, point);
point.setName(name);
point.setValue(value);
point.setCount(count);
point.setMin(min);
point.setMax(max);
point.setStdDev(stdDev);
if (count != null || min != null || max != null || stdDev != null) {
point.setDataPointType(DataPointType.AGGREGATION);
} else {
point.setDataPointType(DataPointType.MEASUREMENT);
}
if (!properties.isEmpty()) {
Map<String, String> existingProperties = data.getProperties();
if (existingProperties == null) {
data.setProperties(properties);
} else {
existingProperties.putAll(properties);
}
}
if (timestamp != null) {
telemetry.setTime(FormattedTime.offSetDateTimeFromDate(timestamp));
} else {
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
}
selectivelySetTags(telemetry, tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
}
track(telemetry, false);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class BytecodeUtilImpl method trackDependency.
@Override
public void trackDependency(Date timestamp, String name, String id, String resultCode, @Nullable Long totalMillis, boolean success, String commandName, String type, String target, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
if (Strings.isNullOrEmpty(name)) {
return;
}
TelemetryItem telemetry = new TelemetryItem();
RemoteDependencyData data = new RemoteDependencyData();
TelemetryClient.getActive().initRemoteDependencyTelemetry(telemetry, data);
data.setName(name);
if (id == null) {
data.setId(AiLegacyPropagator.generateSpanId());
} else {
data.setId(id);
}
data.setResultCode(resultCode);
if (totalMillis != null) {
data.setDuration(FormattedDuration.fromMillis(totalMillis));
}
data.setSuccess(success);
data.setData(commandName);
data.setType(type);
data.setTarget(target);
data.setMeasurements(metrics);
if (!properties.isEmpty()) {
Map<String, String> existingProperties = data.getProperties();
if (existingProperties == null) {
data.setProperties(properties);
} else {
existingProperties.putAll(properties);
}
}
if (timestamp != null) {
telemetry.setTime(FormattedTime.offSetDateTimeFromDate(timestamp));
} else {
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
}
selectivelySetTags(telemetry, tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
}
track(telemetry, true);
}
Aggregations