Search in sources :

Example 16 with TelemetryItem

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

the class HeartBeatProvider method send.

/**
 * Send the heartbeat item synchronously to application insights backend.
 */
private void send() {
    try {
        TelemetryItem telemetry = gatherData();
        telemetry.getTags().put(ContextTagKeys.AI_OPERATION_SYNTHETIC_SOURCE.toString(), HEARTBEAT_SYNTHETIC_METRIC_NAME);
        telemetryClient.trackAsync(telemetry);
        logger.trace("No of heartbeats sent, {}", ++heartbeatsSent);
    } catch (RuntimeException e) {
        logger.warn("Error occured while sending heartbeat");
    }
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

Example 17 with TelemetryItem

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

the class Exporter method exportRemoteDependency.

private void exportRemoteDependency(SpanData span, boolean inProc) {
    TelemetryItem telemetry = new TelemetryItem();
    RemoteDependencyData data = new RemoteDependencyData();
    telemetryClient.initRemoteDependencyTelemetry(telemetry, data);
    float samplingPercentage = getSamplingPercentage(span.getSpanContext().getTraceState());
    // set standard properties
    setOperationTags(telemetry, span);
    setTime(telemetry, span.getStartEpochNanos());
    setSampleRate(telemetry, samplingPercentage);
    setExtraAttributes(telemetry, data, span.getAttributes());
    addLinks(data, span.getLinks());
    // set dependency-specific properties
    data.setId(span.getSpanId());
    data.setName(getDependencyName(span));
    data.setDuration(FormattedDuration.fromNanos(span.getEndEpochNanos() - span.getStartEpochNanos()));
    data.setSuccess(getSuccess(span));
    if (inProc) {
        data.setType("InProc");
    } else {
        applySemanticConventions(span, data);
    }
    // export
    telemetryClient.trackAsync(telemetry);
    exportEvents(span, null, samplingPercentage);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) RemoteDependencyData(com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData)

Example 18 with TelemetryItem

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

the class Exporter method exportEvents.

private void exportEvents(SpanData span, @Nullable String operationName, float samplingPercentage) {
    for (EventData event : span.getEvents()) {
        String instrumentationLibraryName = span.getInstrumentationLibraryInfo().getName();
        boolean lettuce51 = instrumentationLibraryName.equals("io.opentelemetry.lettuce-5.1");
        if (lettuce51 && event.getName().startsWith("redis.encode.")) {
            // special case as these are noisy and come from the underlying library itself
            continue;
        }
        boolean grpc16 = instrumentationLibraryName.equals("io.opentelemetry.grpc-1.6");
        if (grpc16 && event.getName().equals("message")) {
            // we want to suppress these (at least by default)
            continue;
        }
        if (event.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE) != null || event.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE) != null) {
            // TODO (trask) map OpenTelemetry exception to Application Insights exception better
            String stacktrace = event.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE);
            if (stacktrace != null) {
                trackException(stacktrace, span, operationName, samplingPercentage);
            }
            return;
        }
        TelemetryItem telemetry = new TelemetryItem();
        MessageData data = new MessageData();
        telemetryClient.initMessageTelemetry(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, event.getEpochNanos());
        setExtraAttributes(telemetry, data, event.getAttributes());
        setSampleRate(telemetry, samplingPercentage);
        // set message-specific properties
        data.setMessage(event.getName());
        telemetryClient.trackAsync(telemetry);
    }
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData) EventData(io.opentelemetry.sdk.trace.data.EventData)

Example 19 with TelemetryItem

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

the class TestUtils method createMetricTelemetry.

public static TelemetryItem createMetricTelemetry(String name, int value, String instrumentationKey) {
    TelemetryItem telemetry = new TelemetryItem();
    telemetry.setVersion(1);
    telemetry.setName("Metric");
    telemetry.setInstrumentationKey(instrumentationKey);
    Map<String, String> tags = new HashMap<>();
    tags.put("ai.internal.sdkVersion", "test_version");
    tags.put("ai.internal.nodeName", "test_role_name");
    tags.put("ai.cloud.roleInstance", "test_cloud_name");
    telemetry.setTags(tags);
    MetricsData data = new MetricsData();
    List<MetricDataPoint> dataPoints = new ArrayList<>();
    MetricDataPoint dataPoint = new MetricDataPoint();
    dataPoint.setDataPointType(DataPointType.MEASUREMENT);
    dataPoint.setName(name);
    dataPoint.setValue(value);
    dataPoint.setCount(1);
    dataPoints.add(dataPoint);
    Map<String, String> properties = new HashMap<>();
    properties.put("state", "blocked");
    data.setMetrics(dataPoints);
    data.setProperties(properties);
    MonitorBase monitorBase = new MonitorBase();
    monitorBase.setBaseType("MetricData");
    monitorBase.setBaseData(data);
    telemetry.setData(monitorBase);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    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) ArrayList(java.util.ArrayList) MonitorBase(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorBase)

Example 20 with TelemetryItem

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

the class AttachStatsbeat method send.

@Override
protected void send(TelemetryClient telemetryClient) {
    // WEBSITE_HOSTNAME is lazily set in Linux Consumption Plan.
    if (resourceProviderId == null || resourceProviderId.isEmpty()) {
        resourceProviderId = initResourceProviderId(customDimensions.getResourceProvider(), null);
    }
    TelemetryItem statsbeatTelemetry = createStatsbeatTelemetry(telemetryClient, ATTACH_METRIC_NAME, 0);
    TelemetryUtil.getProperties(statsbeatTelemetry.getData().getBaseData()).put("rpId", resourceProviderId);
    telemetryClient.trackStatsbeatAsync(statsbeatTelemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

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