Search in sources :

Example 21 with TelemetryItem

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;
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)

Example 22 with TelemetryItem

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);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

Example 23 with TelemetryItem

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);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) RequestData(com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes)

Example 24 with TelemetryItem

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);
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)

Example 25 with TelemetryItem

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);
    }
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)

Aggregations

TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)51 Test (org.junit.jupiter.api.Test)13 ArrayList (java.util.ArrayList)9 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)8 MetricsData (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData)7 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)7 HashMap (java.util.HashMap)7 MetricDataPoint (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)6 MessageData (com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)5 TelemetryExceptionData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData)4 RemoteDependencyData (com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData)3 RequestData (com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData)3 TelemetryEventData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)3 FinalCounters (com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters)3 Attributes (io.opentelemetry.api.common.Attributes)3 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)3 MemoryUsage (java.lang.management.MemoryUsage)3 Date (java.util.Date)3 HttpRequest (com.azure.core.http.HttpRequest)1 SerializedString (com.fasterxml.jackson.core.io.SerializedString)1