use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class BaseStatsbeat method createStatsbeatTelemetry.
protected TelemetryItem createStatsbeatTelemetry(TelemetryClient telemetryClient, String name, double value) {
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
telemetryClient.initMetricTelemetry(telemetry, data, point);
// overwrite the default name (which is "Metric")
telemetry.setName(STATSBEAT_TELEMETRY_NAME);
point.setName(name);
point.setValue(value);
point.setDataPointType(DataPointType.MEASUREMENT);
telemetry.setInstrumentationKey(telemetryClient.getStatsbeatInstrumentationKey());
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
Map<String, String> properties = new HashMap<>();
customDimensions.populateProperties(properties, telemetryClient.getInstrumentationKey());
data.setProperties(properties);
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class NonessentialStatsbeat method send.
@Override
protected void send(TelemetryClient telemetryClient) {
if (readFailureCount.get() != 0) {
TelemetryItem telemetryItem = createStatsbeatTelemetry(telemetryClient, READ_FAILURE_COUNT, readFailureCount.get());
telemetryClient.trackStatsbeatAsync(telemetryItem);
}
if (writeFailureCount.get() != 0) {
TelemetryItem telemetryItem = createStatsbeatTelemetry(telemetryClient, WRITE_FAILURE_COUNT, writeFailureCount.get());
telemetryClient.trackStatsbeatAsync(telemetryItem);
}
readFailureCount.set(0L);
writeFailureCount.set(0L);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class Exporter method exportRequest.
private void exportRequest(SpanData span) {
TelemetryItem telemetry = new TelemetryItem();
RequestData data = new RequestData();
telemetryClient.initRequestTelemetry(telemetry, data);
Attributes attributes = span.getAttributes();
long startEpochNanos = span.getStartEpochNanos();
float samplingPercentage = getSamplingPercentage(span.getSpanContext().getTraceState());
// set standard properties
data.setId(span.getSpanId());
setTime(telemetry, startEpochNanos);
setSampleRate(telemetry, samplingPercentage);
setExtraAttributes(telemetry, data, attributes);
addLinks(data, span.getLinks());
String operationName = getOperationName(span);
telemetry.getTags().put(ContextTagKeys.AI_OPERATION_NAME.toString(), operationName);
telemetry.getTags().put(ContextTagKeys.AI_OPERATION_ID.toString(), span.getTraceId());
// see behavior specified at https://github.com/microsoft/ApplicationInsights-Java/issues/1174
String aiLegacyParentId = span.getAttributes().get(AI_LEGACY_PARENT_ID_KEY);
if (aiLegacyParentId != null) {
// this was the real (legacy) parent id, but it didn't fit span id format
telemetry.getTags().put(ContextTagKeys.AI_OPERATION_PARENT_ID.toString(), aiLegacyParentId);
} else if (span.getParentSpanContext().isValid()) {
telemetry.getTags().put(ContextTagKeys.AI_OPERATION_PARENT_ID.toString(), span.getParentSpanContext().getSpanId());
}
String aiLegacyRootId = span.getAttributes().get(AI_LEGACY_ROOT_ID_KEY);
if (aiLegacyRootId != null) {
telemetry.getTags().put("ai_legacyRootID", aiLegacyRootId);
}
// set request-specific properties
data.setName(operationName);
data.setDuration(FormattedDuration.fromNanos(span.getEndEpochNanos() - startEpochNanos));
data.setSuccess(getSuccess(span));
String httpUrl = getHttpUrlFromServerSpan(attributes);
if (httpUrl != null) {
data.setUrl(httpUrl);
}
Long httpStatusCode = attributes.get(SemanticAttributes.HTTP_STATUS_CODE);
if (httpStatusCode == null) {
httpStatusCode = attributes.get(SemanticAttributes.RPC_GRPC_STATUS_CODE);
}
if (httpStatusCode != null) {
data.setResponseCode(Long.toString(httpStatusCode));
} else {
data.setResponseCode("0");
}
String locationIp = attributes.get(SemanticAttributes.HTTP_CLIENT_IP);
if (locationIp == null) {
// only use net.peer.ip if http.client_ip is not available
locationIp = attributes.get(SemanticAttributes.NET_PEER_IP);
}
if (locationIp != null) {
telemetry.getTags().put(ContextTagKeys.AI_LOCATION_IP.toString(), locationIp);
}
data.setSource(getSource(attributes, span.getSpanContext()));
String sessionId = attributes.get(AI_SESSION_ID_KEY);
if (sessionId != null) {
// this is only used by the 2.x web interop bridge for
// ThreadContext.getRequestTelemetryContext().getHttpRequestTelemetry().getContext().getSession().setId()
telemetry.getTags().put(ContextTagKeys.AI_SESSION_ID.toString(), sessionId);
}
String deviceOs = attributes.get(AI_DEVICE_OS_KEY);
if (deviceOs != null) {
// this is only used by the 2.x web interop bridge for
// ThreadContext.getRequestTelemetryContext().getHttpRequestTelemetry().getContext().getDevice().setOperatingSystem()
telemetry.getTags().put(ContextTagKeys.AI_DEVICE_OS.toString(), deviceOs);
}
String deviceOsVersion = attributes.get(AI_DEVICE_OS_VERSION_KEY);
if (deviceOsVersion != null) {
// this is only used by the 2.x web interop bridge for
// ThreadContext.getRequestTelemetryContext().getHttpRequestTelemetry().getContext().getDevice().setOperatingSystemVersion()
telemetry.getTags().put(ContextTagKeys.AI_DEVICE_OS_VERSION.toString(), deviceOsVersion);
}
// TODO(trask)? for batch consumer, enqueuedTime should be the average of this attribute
// across all links
Long enqueuedTime = attributes.get(AZURE_SDK_ENQUEUED_TIME);
if (enqueuedTime != null) {
long timeSinceEnqueuedMillis = Math.max(0L, NANOSECONDS.toMillis(span.getStartEpochNanos()) - SECONDS.toMillis(enqueuedTime));
if (data.getMeasurements() == null) {
data.setMeasurements(new HashMap<>());
}
data.getMeasurements().put("timeSinceEnqueued", (double) timeSinceEnqueuedMillis);
}
Long timeSinceEnqueuedMillis = attributes.get(KAFKA_RECORD_QUEUE_TIME_MS);
if (timeSinceEnqueuedMillis != null) {
if (data.getMeasurements() == null) {
data.setMeasurements(new HashMap<>());
}
data.getMeasurements().put("timeSinceEnqueued", (double) timeSinceEnqueuedMillis);
}
// export
telemetryClient.trackAsync(telemetry);
exportEvents(span, operationName, samplingPercentage);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class DeadLockDetectorPerformanceCounter method sendDetailedMessage.
private void sendDetailedMessage(TelemetryClient telemetryClient, long[] threadIds) {
TelemetryItem messageTelemetry = new TelemetryItem();
MessageData messageData = new MessageData();
TelemetryClient.getActive().initMessageTelemetry(messageTelemetry, messageData);
StringBuilder sb = new StringBuilder("Suspected deadlocked threads: ");
for (long threadId : threadIds) {
ThreadInfo threadInfo = threadBean.getThreadInfo(threadId, MAX_STACK_TRACE);
if (threadInfo != null) {
appendThreadInfoAndStack(sb, threadInfo);
}
}
messageData.setMessage(sb.toString());
messageTelemetry.setTime(FormattedTime.offSetDateTimeFromNow());
telemetryClient.trackAsync(messageTelemetry);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class DeadLockDetectorPerformanceCounter method report.
@Override
public void report(TelemetryClient telemetryClient) {
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
TelemetryClient.getActive().initMetricTelemetry(telemetry, data, point);
point.setName(METRIC_NAME);
point.setValue(0);
point.setDataPointType(DataPointType.MEASUREMENT);
long[] threadIds = threadBean.findDeadlockedThreads();
int blockedThreadCount = threadIds == null ? 0 : threadIds.length;
data.getMetrics().get(0).setValue(blockedThreadCount);
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
telemetryClient.trackAsync(telemetry);
if (blockedThreadCount > 0) {
sendDetailedMessage(telemetryClient, threadIds);
}
}
Aggregations