Search in sources :

Example 1 with MessageData

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

the class BytecodeUtilImpl method trackTrace.

@Override
public void trackTrace(Date timestamp, String message, int severityLevel, Map<String, String> properties, Map<String, String> tags, String instrumentationKey) {
    if (Strings.isNullOrEmpty(message)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    MessageData data = new MessageData();
    TelemetryClient.getActive().initMessageTelemetry(telemetry, data);
    data.setMessage(message);
    if (severityLevel != -1) {
        data.setSeverityLevel(getSeverityLevel(severityLevel));
    }
    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) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)

Example 2 with MessageData

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData 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 3 with MessageData

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

the class TelemetryUtil method getProperties.

// TODO (trask) Azure SDK: can we move getProperties up to MonitorDomain, or if not, a common
// interface?
public static Map<String, String> getProperties(MonitorDomain data) {
    if (data instanceof AvailabilityData) {
        AvailabilityData availabilityData = (AvailabilityData) data;
        Map<String, String> properties = availabilityData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            availabilityData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof MessageData) {
        MessageData messageData = (MessageData) data;
        Map<String, String> properties = messageData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            messageData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof MetricsData) {
        MetricsData metricsData = (MetricsData) data;
        Map<String, String> properties = metricsData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            metricsData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof PageViewData) {
        PageViewData pageViewData = (PageViewData) data;
        Map<String, String> properties = pageViewData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            pageViewData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof PageViewPerfData) {
        PageViewPerfData pageViewPerfData = (PageViewPerfData) data;
        Map<String, String> properties = pageViewPerfData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            pageViewPerfData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof RemoteDependencyData) {
        RemoteDependencyData remoteDependencyData = (RemoteDependencyData) data;
        Map<String, String> properties = remoteDependencyData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            remoteDependencyData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof RequestData) {
        RequestData requestData = (RequestData) data;
        Map<String, String> properties = requestData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            requestData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof TelemetryEventData) {
        TelemetryEventData eventData = (TelemetryEventData) data;
        Map<String, String> properties = eventData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            eventData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof TelemetryExceptionData) {
        TelemetryExceptionData exceptionData = (TelemetryExceptionData) data;
        Map<String, String> properties = exceptionData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            exceptionData.setProperties(properties);
        }
        return properties;
    } else {
        throw new IllegalArgumentException("Unexpected type: " + data.getClass().getName());
    }
}
Also used : AvailabilityData(com.microsoft.applicationinsights.agent.internal.exporter.models.AvailabilityData) PageViewPerfData(com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewPerfData) HashMap(java.util.HashMap) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData) RemoteDependencyData(com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData) PageViewData(com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewData) MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) RequestData(com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData) HashMap(java.util.HashMap) Map(java.util.Map) TelemetryExceptionData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData) TelemetryEventData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)

Example 4 with MessageData

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData 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 5 with MessageData

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

the class Exporter method trackMessage.

private void trackMessage(SpanData span) {
    TelemetryItem telemetry = new TelemetryItem();
    MessageData data = new MessageData();
    telemetryClient.initMessageTelemetry(telemetry, data);
    Attributes attributes = span.getAttributes();
    // set standard properties
    setTime(telemetry, span.getStartEpochNanos());
    setOperationTags(telemetry, span);
    setSampleRate(telemetry, span);
    setExtraAttributes(telemetry, data, attributes);
    // set message-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.setVersion(2);
    data.setSeverityLevel(toSeverityLevel(level));
    data.setMessage(span.getName());
    setLoggerProperties(data, level, loggerName, threadName);
    // export
    telemetryClient.trackAsync(telemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes)

Aggregations

MessageData (com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)6 TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)5 AvailabilityData (com.microsoft.applicationinsights.agent.internal.exporter.models.AvailabilityData)1 MetricsData (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData)1 PageViewData (com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewData)1 PageViewPerfData (com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewPerfData)1 RemoteDependencyData (com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData)1 RequestData (com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData)1 TelemetryEventData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)1 TelemetryExceptionData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData)1 Attributes (io.opentelemetry.api.common.Attributes)1 EventData (io.opentelemetry.sdk.trace.data.EventData)1 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)1 ThreadInfo (java.lang.management.ThreadInfo)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1