use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class HeartBeatProvider method send.
/**
* Send the heartbeat item synchronously to application insights backend.
*/
private void send() {
try {
TelemetryItem telemetry = gatherData();
telemetry.getTags().put(ContextTagKeys.AI_OPERATION_SYNTHETIC_SOURCE.toString(), HEARTBEAT_SYNTHETIC_METRIC_NAME);
telemetryClient.trackAsync(telemetry);
logger.trace("No of heartbeats sent, {}", ++heartbeatsSent);
} catch (RuntimeException e) {
logger.warn("Error occured while sending heartbeat");
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class Exporter method exportRemoteDependency.
private void exportRemoteDependency(SpanData span, boolean inProc) {
TelemetryItem telemetry = new TelemetryItem();
RemoteDependencyData data = new RemoteDependencyData();
telemetryClient.initRemoteDependencyTelemetry(telemetry, data);
float samplingPercentage = getSamplingPercentage(span.getSpanContext().getTraceState());
// set standard properties
setOperationTags(telemetry, span);
setTime(telemetry, span.getStartEpochNanos());
setSampleRate(telemetry, samplingPercentage);
setExtraAttributes(telemetry, data, span.getAttributes());
addLinks(data, span.getLinks());
// set dependency-specific properties
data.setId(span.getSpanId());
data.setName(getDependencyName(span));
data.setDuration(FormattedDuration.fromNanos(span.getEndEpochNanos() - span.getStartEpochNanos()));
data.setSuccess(getSuccess(span));
if (inProc) {
data.setType("InProc");
} else {
applySemanticConventions(span, data);
}
// export
telemetryClient.trackAsync(telemetry);
exportEvents(span, null, samplingPercentage);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class Exporter method exportEvents.
private void exportEvents(SpanData span, @Nullable String operationName, float samplingPercentage) {
for (EventData event : span.getEvents()) {
String instrumentationLibraryName = span.getInstrumentationLibraryInfo().getName();
boolean lettuce51 = instrumentationLibraryName.equals("io.opentelemetry.lettuce-5.1");
if (lettuce51 && event.getName().startsWith("redis.encode.")) {
// special case as these are noisy and come from the underlying library itself
continue;
}
boolean grpc16 = instrumentationLibraryName.equals("io.opentelemetry.grpc-1.6");
if (grpc16 && event.getName().equals("message")) {
// we want to suppress these (at least by default)
continue;
}
if (event.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE) != null || event.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE) != null) {
// TODO (trask) map OpenTelemetry exception to Application Insights exception better
String stacktrace = event.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE);
if (stacktrace != null) {
trackException(stacktrace, span, operationName, samplingPercentage);
}
return;
}
TelemetryItem telemetry = new TelemetryItem();
MessageData data = new MessageData();
telemetryClient.initMessageTelemetry(telemetry, data);
// set standard properties
setOperationId(telemetry, span.getTraceId());
setOperationParentId(telemetry, span.getSpanId());
if (operationName != null) {
setOperationName(telemetry, operationName);
} else {
setOperationName(telemetry, span.getAttributes());
}
setTime(telemetry, event.getEpochNanos());
setExtraAttributes(telemetry, data, event.getAttributes());
setSampleRate(telemetry, samplingPercentage);
// set message-specific properties
data.setMessage(event.getName());
telemetryClient.trackAsync(telemetry);
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class TestUtils method createMetricTelemetry.
public static TelemetryItem createMetricTelemetry(String name, int value, String instrumentationKey) {
TelemetryItem telemetry = new TelemetryItem();
telemetry.setVersion(1);
telemetry.setName("Metric");
telemetry.setInstrumentationKey(instrumentationKey);
Map<String, String> tags = new HashMap<>();
tags.put("ai.internal.sdkVersion", "test_version");
tags.put("ai.internal.nodeName", "test_role_name");
tags.put("ai.cloud.roleInstance", "test_cloud_name");
telemetry.setTags(tags);
MetricsData data = new MetricsData();
List<MetricDataPoint> dataPoints = new ArrayList<>();
MetricDataPoint dataPoint = new MetricDataPoint();
dataPoint.setDataPointType(DataPointType.MEASUREMENT);
dataPoint.setName(name);
dataPoint.setValue(value);
dataPoint.setCount(1);
dataPoints.add(dataPoint);
Map<String, String> properties = new HashMap<>();
properties.put("state", "blocked");
data.setMetrics(dataPoints);
data.setProperties(properties);
MonitorBase monitorBase = new MonitorBase();
monitorBase.setBaseType("MetricData");
monitorBase.setBaseData(data);
telemetry.setData(monitorBase);
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class AttachStatsbeat method send.
@Override
protected void send(TelemetryClient telemetryClient) {
// WEBSITE_HOSTNAME is lazily set in Linux Consumption Plan.
if (resourceProviderId == null || resourceProviderId.isEmpty()) {
resourceProviderId = initResourceProviderId(customDimensions.getResourceProvider(), null);
}
TelemetryItem statsbeatTelemetry = createStatsbeatTelemetry(telemetryClient, ATTACH_METRIC_NAME, 0);
TelemetryUtil.getProperties(statsbeatTelemetry.getData().getBaseData()).put("rpId", resourceProviderId);
telemetryClient.trackStatsbeatAsync(statsbeatTelemetry);
}
Aggregations