use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class CustomDimensionsTest method testCustomDimensionsConfigShouldNotImpactStatsbeatCustomDimensions.
@Test
public void testCustomDimensionsConfigShouldNotImpactStatsbeatCustomDimensions() {
Configuration configuration = new Configuration();
configuration.customDimensions.put("firstTag", "abc");
configuration.customDimensions.put("secondTag", "def");
TelemetryClient telemetryClient = TelemetryClient.builder().setCustomDimensions(configuration.customDimensions).build();
NetworkStatsbeat networkStatsbeat = new NetworkStatsbeat();
TelemetryItem networkItem = networkStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-network", 0.0);
assertThat(networkItem.getTags()).doesNotContainKey("firstTag");
assertThat(networkItem.getTags()).doesNotContainKey("secondTag");
assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
AttachStatsbeat attachStatsbeat = new AttachStatsbeat(new CustomDimensions());
TelemetryItem attachItem = attachStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-attach", 0.0);
assertThat(attachItem.getTags()).doesNotContainKey("firstTag");
assertThat(attachItem.getTags()).doesNotContainKey("secondTag");
assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
FeatureStatsbeat featureStatsbeat = new FeatureStatsbeat(new CustomDimensions(), FeatureType.FEATURE);
TelemetryItem featureItem = featureStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-feature", 0.0);
assertThat(featureItem.getTags()).doesNotContainKey("firstTag");
assertThat(featureItem.getTags()).doesNotContainKey("secondTag");
assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class HeartBeatProvider method gatherData.
/**
* Creates and returns the heartbeat telemetry.
*
* @return Metric Telemetry which represent heartbeat.
*/
// visible for testing
TelemetryItem gatherData() {
Map<String, String> properties = new HashMap<>();
double numHealthy = 0;
for (Map.Entry<String, HeartBeatPropertyPayload> entry : heartbeatProperties.entrySet()) {
HeartBeatPropertyPayload payload = entry.getValue();
properties.put(entry.getKey(), payload.getPayloadValue());
numHealthy += payload.isHealthy() ? 0 : 1;
}
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
telemetryClient.initMetricTelemetry(telemetry, data, point);
point.setName(HEARTBEAT_SYNTHETIC_METRIC_NAME);
point.setValue(numHealthy);
point.setDataPointType(DataPointType.MEASUREMENT);
data.setProperties(properties);
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class TelemetryClient method trackAsync.
public void trackAsync(TelemetryItem telemetry) {
if (Strings.isNullOrEmpty(instrumentationKey)) {
return;
}
MonitorDomain data = telemetry.getData().getBaseData();
if (data instanceof MetricsData) {
MetricsData metricsData = (MetricsData) data;
if (metricsData.getMetrics().isEmpty()) {
throw new AssertionError("MetricsData has no metric point");
}
MetricDataPoint point = metricsData.getMetrics().get(0);
String metricName = point.getName();
if (!nonFilterableMetricNames.contains(metricName)) {
for (MetricFilter metricFilter : metricFilters) {
if (!metricFilter.matches(metricName)) {
// user configuration filtered out this metric name
return;
}
}
}
if (!Double.isFinite(point.getValue())) {
// breeze doesn't like these values
return;
}
}
if (telemetry.getTime() == null) {
// this is easy to forget when adding new telemetry
throw new AssertionError("telemetry item is missing time");
}
QuickPulseDataCollector.INSTANCE.add(telemetry);
TelemetryObservers.INSTANCE.getObservers().forEach(consumer -> consumer.accept(telemetry));
// only that it was successfully delivered to the next layer
if (data instanceof MetricsData) {
getMetricsChannelBatcher().trackAsync(telemetry);
} else {
getGeneralChannelBatcher().trackAsync(telemetry);
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class TelemetryUtil method getProperties.
// TODO (trask) Azure SDK: can we move getProperties up to MonitorDomain, or if not, a common
// interface?
public static Map<String, String> getProperties(MonitorDomain data) {
if (data instanceof AvailabilityData) {
AvailabilityData availabilityData = (AvailabilityData) data;
Map<String, String> properties = availabilityData.getProperties();
if (properties == null) {
properties = new HashMap<>();
availabilityData.setProperties(properties);
}
return properties;
} else if (data instanceof MessageData) {
MessageData messageData = (MessageData) data;
Map<String, String> properties = messageData.getProperties();
if (properties == null) {
properties = new HashMap<>();
messageData.setProperties(properties);
}
return properties;
} else if (data instanceof MetricsData) {
MetricsData metricsData = (MetricsData) data;
Map<String, String> properties = metricsData.getProperties();
if (properties == null) {
properties = new HashMap<>();
metricsData.setProperties(properties);
}
return properties;
} else if (data instanceof PageViewData) {
PageViewData pageViewData = (PageViewData) data;
Map<String, String> properties = pageViewData.getProperties();
if (properties == null) {
properties = new HashMap<>();
pageViewData.setProperties(properties);
}
return properties;
} else if (data instanceof PageViewPerfData) {
PageViewPerfData pageViewPerfData = (PageViewPerfData) data;
Map<String, String> properties = pageViewPerfData.getProperties();
if (properties == null) {
properties = new HashMap<>();
pageViewPerfData.setProperties(properties);
}
return properties;
} else if (data instanceof RemoteDependencyData) {
RemoteDependencyData remoteDependencyData = (RemoteDependencyData) data;
Map<String, String> properties = remoteDependencyData.getProperties();
if (properties == null) {
properties = new HashMap<>();
remoteDependencyData.setProperties(properties);
}
return properties;
} else if (data instanceof RequestData) {
RequestData requestData = (RequestData) data;
Map<String, String> properties = requestData.getProperties();
if (properties == null) {
properties = new HashMap<>();
requestData.setProperties(properties);
}
return properties;
} else if (data instanceof TelemetryEventData) {
TelemetryEventData eventData = (TelemetryEventData) data;
Map<String, String> properties = eventData.getProperties();
if (properties == null) {
properties = new HashMap<>();
eventData.setProperties(properties);
}
return properties;
} else if (data instanceof TelemetryExceptionData) {
TelemetryExceptionData exceptionData = (TelemetryExceptionData) data;
Map<String, String> properties = exceptionData.getProperties();
if (properties == null) {
properties = new HashMap<>();
exceptionData.setProperties(properties);
}
return properties;
} else {
throw new IllegalArgumentException("Unexpected type: " + data.getClass().getName());
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class HeartbeatTests method heartBeatPayloadContainsSpecificProperties.
@Test
void heartBeatPayloadContainsSpecificProperties() {
// given
HeartBeatProvider provider = new HeartBeatProvider();
provider.initialize(TelemetryClient.createForTest());
// then
assertThat(provider.addHeartBeatProperty("test", "testVal", true)).isTrue();
MetricsData t = (MetricsData) provider.gatherData().getData().getBaseData();
assertThat(t.getProperties().get("test")).isEqualTo("testVal");
}
Aggregations