Search in sources :

Example 41 with TelemetryItem

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

the class BytecodeUtilImpl method trackPageView.

@Override
public void trackPageView(Date timestamp, String name, URI uri, long totalMillis, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
    if (Strings.isNullOrEmpty(name)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    PageViewData data = new PageViewData();
    TelemetryClient.getActive().initPageViewTelemetry(telemetry, data);
    data.setName(name);
    if (uri != null) {
        data.setUrl(uri.toString());
    }
    data.setDuration(FormattedDuration.fromMillis(totalMillis));
    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) PageViewData(com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewData)

Example 42 with TelemetryItem

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

the class TelemetryChannel method send.

public CompletableResultCode send(List<TelemetryItem> telemetryItems) {
    Map<String, List<TelemetryItem>> instrumentationKeyMap = new HashMap<>();
    List<CompletableResultCode> resultCodeList = new ArrayList<>();
    for (TelemetryItem telemetryItem : telemetryItems) {
        String instrumentationKey = telemetryItem.getInstrumentationKey();
        if (!instrumentationKeyMap.containsKey(instrumentationKey)) {
            instrumentationKeyMap.put(instrumentationKey, new ArrayList<>());
        }
        instrumentationKeyMap.get(instrumentationKey).add(telemetryItem);
    }
    for (String instrumentationKey : instrumentationKeyMap.keySet()) {
        resultCodeList.add(internalSendByInstrumentationKey(instrumentationKeyMap.get(instrumentationKey), instrumentationKey));
    }
    return CompletableResultCode.ofAll(resultCodeList);
}
Also used : HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 43 with TelemetryItem

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

the class TelemetryUtil method createMetricsTelemetry.

public static TelemetryItem createMetricsTelemetry(TelemetryClient telemetryClient, String name, double value) {
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    telemetryClient.initMetricTelemetry(telemetry, data, point);
    point.setName(name);
    point.setValue(value);
    point.setDataPointType(DataPointType.MEASUREMENT);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    return telemetry;
}
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)

Example 44 with TelemetryItem

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

the class OshiPerformanceCounter method send.

private static void send(TelemetryClient telemetryClient, double value, String metricName) {
    TelemetryItem telemetry = TelemetryUtil.createMetricsTelemetry(telemetryClient, metricName, value);
    telemetryClient.trackAsync(telemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

Example 45 with TelemetryItem

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

the class ProcessMemoryPerformanceCounter method report.

@Override
public void report(TelemetryClient telemetryClient) {
    MemoryMXBean memoryData = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemoryUsage = memoryData.getHeapMemoryUsage();
    MemoryUsage nonHeapMemoryUsage = memoryData.getNonHeapMemoryUsage();
    double memoryBytes = (double) heapMemoryUsage.getUsed();
    memoryBytes += (double) nonHeapMemoryUsage.getUsed();
    logger.trace("Performance Counter: {}: {}", PROCESS_MEM_PC_METRICS_NAME, memoryBytes);
    TelemetryItem telemetry = TelemetryUtil.createMetricsTelemetry(telemetryClient, PROCESS_MEM_PC_METRICS_NAME, memoryBytes);
    telemetryClient.trackAsync(telemetry);
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MemoryUsage(java.lang.management.MemoryUsage)

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