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);
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations