Search in sources :

Example 36 with TelemetryItem

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

the class TelemetryChannelTest method dualIkeyBatchTest.

@Test
public void dualIkeyBatchTest() throws MalformedURLException {
    // given
    List<TelemetryItem> telemetryItems = new ArrayList<>();
    telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 1, 1, INSTRUMENTATION_KEY));
    telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 2, 2, INSTRUMENTATION_KEY));
    telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 3, 3, REDIRECT_INSTRUMENTATION_KEY));
    telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 4, 4, REDIRECT_INSTRUMENTATION_KEY));
    TelemetryChannel telemetryChannel = getTelemetryChannel();
    // when
    CompletableResultCode completableResultCode = telemetryChannel.send(telemetryItems);
    // then
    assertThat(completableResultCode.isSuccess()).isEqualTo(true);
    assertThat(recordingHttpClient.getCount()).isEqualTo(3);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 37 with TelemetryItem

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

the class TelemetryChannelTest method dualIkeyTest.

@Test
public void dualIkeyTest() throws MalformedURLException {
    // given
    List<TelemetryItem> telemetryItems = new ArrayList<>();
    telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 1, 1, INSTRUMENTATION_KEY));
    telemetryItems.add(TestUtils.createMetricTelemetry("metric" + 2, 2, REDIRECT_INSTRUMENTATION_KEY));
    TelemetryChannel telemetryChannel = getTelemetryChannel();
    // when
    CompletableResultCode completableResultCode = telemetryChannel.send(telemetryItems);
    // then
    assertThat(completableResultCode.isSuccess()).isEqualTo(true);
    assertThat(recordingHttpClient.getCount()).isEqualTo(3);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 38 with TelemetryItem

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

the class BytecodeUtilImpl method trackException.

@Override
public void trackException(Date timestamp, Exception exception, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
    if (exception == null) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    TelemetryExceptionData data = new TelemetryExceptionData();
    TelemetryClient.getActive().initExceptionTelemetry(telemetry, data);
    data.setExceptions(TelemetryUtil.getExceptions(exception));
    data.setSeverityLevel(SeverityLevel.ERROR);
    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) TelemetryExceptionData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData)

Example 39 with TelemetryItem

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

the class BytecodeUtilImpl method trackMetric.

// TODO do not track if perf counter (?)
@Override
public void trackMetric(Date timestamp, String name, double value, Integer count, Double min, Double max, Double stdDev, Map<String, String> properties, Map<String, String> tags, String instrumentationKey) {
    if (Strings.isNullOrEmpty(name)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    TelemetryClient.getActive().initMetricTelemetry(telemetry, data, point);
    point.setName(name);
    point.setValue(value);
    point.setCount(count);
    point.setMin(min);
    point.setMax(max);
    point.setStdDev(stdDev);
    if (count != null || min != null || max != null || stdDev != null) {
        point.setDataPointType(DataPointType.AGGREGATION);
    } else {
        point.setDataPointType(DataPointType.MEASUREMENT);
    }
    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, false);
}
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 40 with TelemetryItem

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

the class BytecodeUtilImpl method trackDependency.

@Override
public void trackDependency(Date timestamp, String name, String id, String resultCode, @Nullable Long totalMillis, boolean success, String commandName, String type, String target, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
    if (Strings.isNullOrEmpty(name)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    RemoteDependencyData data = new RemoteDependencyData();
    TelemetryClient.getActive().initRemoteDependencyTelemetry(telemetry, data);
    data.setName(name);
    if (id == null) {
        data.setId(AiLegacyPropagator.generateSpanId());
    } else {
        data.setId(id);
    }
    data.setResultCode(resultCode);
    if (totalMillis != null) {
        data.setDuration(FormattedDuration.fromMillis(totalMillis));
    }
    data.setSuccess(success);
    data.setData(commandName);
    data.setType(type);
    data.setTarget(target);
    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) RemoteDependencyData(com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData)

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