Search in sources :

Example 26 with TelemetryItem

use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.

the class FreeMemoryPerformanceCounter method report.

@Override
public void report(TelemetryClient telemetryClient) {
    long freePhysicalMemorySize;
    try {
        freePhysicalMemorySize = getFreePhysicalMemorySize();
    } catch (Exception e) {
        logger.error("Error getting FreePhysicalMemorySize");
        logger.trace("Error getting FreePhysicalMemorySize", e);
        return;
    }
    logger.trace("Performance Counter: {}: {}", Constants.TOTAL_MEMORY_PC_METRIC_NAME, freePhysicalMemorySize);
    TelemetryItem telemetry = TelemetryUtil.createMetricsTelemetry(telemetryClient, Constants.TOTAL_MEMORY_PC_METRIC_NAME, freePhysicalMemorySize);
    telemetryClient.trackAsync(telemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

Example 27 with TelemetryItem

use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.

the class GcPerformanceCounter method report.

@Override
public void report(TelemetryClient telemetryClient) {
    synchronized (this) {
        List<GarbageCollectorMXBean> gcs = ManagementFactory.getGarbageCollectorMXBeans();
        if (gcs.isEmpty()) {
            return;
        }
        long totalCollectionCount = 0;
        long totalCollectionTime = 0;
        for (GarbageCollectorMXBean gc : gcs) {
            long gcCollectionCount = gc.getCollectionCount();
            if (gcCollectionCount > 0) {
                totalCollectionCount += gcCollectionCount;
            }
            long gcCollectionTime = gc.getCollectionTime();
            if (gcCollectionTime > 0) {
                totalCollectionTime += gcCollectionTime;
            }
        }
        long countToReport = totalCollectionCount - currentTotalCount;
        long timeToReport = totalCollectionTime - currentTotalTime;
        currentTotalCount = totalCollectionCount;
        currentTotalTime = totalCollectionTime;
        TelemetryItem mtTotalCount = TelemetryUtil.createMetricsTelemetry(telemetryClient, GC_TOTAL_COUNT, countToReport);
        TelemetryItem mtTotalTime = TelemetryUtil.createMetricsTelemetry(telemetryClient, GC_TOTAL_TIME, timeToReport);
        telemetryClient.trackAsync(mtTotalCount);
        telemetryClient.trackAsync(mtTotalTime);
    }
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

Example 28 with TelemetryItem

use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.

the class BytecodeUtilImpl method trackRequest.

@Override
public void trackRequest(String id, String name, URL url, Date timestamp, @Nullable Long duration, String responseCode, boolean success, String source, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
    if (Strings.isNullOrEmpty(name)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    RequestData data = new RequestData();
    TelemetryClient.getActive().initRequestTelemetry(telemetry, data);
    if (id == null) {
        data.setId(AiLegacyPropagator.generateSpanId());
    } else {
        data.setId(id);
    }
    data.setName(name);
    if (url != null) {
        data.setUrl(url.toString());
    }
    if (duration != null) {
        data.setDuration(FormattedDuration.fromMillis(duration));
    }
    data.setResponseCode(responseCode);
    data.setSuccess(success);
    data.setSource(source);
    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);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) RequestData(com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData)

Example 29 with TelemetryItem

use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.

the class Exporter method trackException.

private void trackException(String errorStack, SpanData span, @Nullable String operationName, float samplingPercentage) {
    TelemetryItem telemetry = new TelemetryItem();
    TelemetryExceptionData data = new TelemetryExceptionData();
    telemetryClient.initExceptionTelemetry(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, span.getEndEpochNanos());
    setSampleRate(telemetry, samplingPercentage);
    // set exception-specific properties
    data.setExceptions(Exceptions.minimalParse(errorStack));
    telemetryClient.trackAsync(telemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) TelemetryExceptionData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData)

Example 30 with TelemetryItem

use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.

the class Exporter method trackTraceAsException.

private void trackTraceAsException(SpanData span, String errorStack) {
    TelemetryItem telemetry = new TelemetryItem();
    TelemetryExceptionData data = new TelemetryExceptionData();
    telemetryClient.initExceptionTelemetry(telemetry, data);
    Attributes attributes = span.getAttributes();
    // set standard properties
    setOperationTags(telemetry, span);
    setTime(telemetry, span.getStartEpochNanos());
    setSampleRate(telemetry, span);
    setExtraAttributes(telemetry, data, attributes);
    // set exception-specific properties
    String level = attributes.get(AI_LOG_LEVEL_KEY);
    String loggerName = attributes.get(AI_LOGGER_NAME_KEY);
    String threadName = attributes.get(SemanticAttributes.THREAD_NAME);
    data.setExceptions(Exceptions.minimalParse(errorStack));
    data.setSeverityLevel(toSeverityLevel(level));
    TelemetryUtil.getProperties(data).put("Logger Message", span.getName());
    setLoggerProperties(data, level, loggerName, threadName);
    // export
    telemetryClient.trackAsync(telemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) TelemetryExceptionData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData)

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