Skip to content

Commit

Permalink
Set time
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Apr 26, 2021
1 parent 56d9d15 commit 62be412
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void trackEvent(String name, Map<String, String> properties, Map<String,
}
}

telemetry.setTime(TelemetryUtil.getFormattedNow());
telemetry.getTags().putAll(tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
Expand Down Expand Up @@ -108,6 +109,7 @@ public void trackMetric(String name, double value, Integer count, Double min, Do
}
}

telemetry.setTime(TelemetryUtil.getFormattedNow());
telemetry.getTags().putAll(tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
Expand Down Expand Up @@ -150,6 +152,7 @@ public void trackDependency(String name, String id, String resultCode, @Nullable
}
}

telemetry.setTime(TelemetryUtil.getFormattedNow());
telemetry.getTags().putAll(tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
Expand Down Expand Up @@ -183,6 +186,7 @@ public void trackPageView(String name, URI uri, long totalMillis, Map<String, St
}
}

telemetry.setTime(TelemetryUtil.getFormattedNow());
telemetry.getTags().putAll(tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
Expand Down Expand Up @@ -215,6 +219,7 @@ public void trackTrace(String message, int severityLevel, Map<String, String> pr
}
}

telemetry.setTime(TelemetryUtil.getFormattedNow());
telemetry.getTags().putAll(tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
Expand Down Expand Up @@ -247,10 +252,6 @@ public void trackRequest(String id, String name, URL url, Date timestamp, @Nulla
data.setSource(source);
data.setMeasurements(metrics);

if (timestamp != null) {
telemetry.setTime(TelemetryUtil.getFormattedTime(timestamp.getTime()));
}

if (!properties.isEmpty()) {
Map<String, String> existingProperties = data.getProperties();
if (existingProperties == null) {
Expand All @@ -260,6 +261,11 @@ public void trackRequest(String id, String name, URL url, Date timestamp, @Nulla
}
}

if (timestamp != null) {
telemetry.setTime(TelemetryUtil.getFormattedTime(timestamp.getTime()));
} else {
telemetry.setTime(TelemetryUtil.getFormattedNow());
}
telemetry.getTags().putAll(tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
Expand Down Expand Up @@ -291,6 +297,7 @@ public void trackException(Exception exception, Map<String, String> properties,
}
}

telemetry.setTime(TelemetryUtil.getFormattedNow());
telemetry.getTags().putAll(tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ private static String getBaseType(MonitorDomain data) {
}
}

public static String currentTime() {
return getFormattedTime(System.currentTimeMillis());
}

// FIXME (trask) share below functions with exporter

private static final long MILLISECONDS_PER_DAY = DAYS.toMillis(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.azure.monitor.opentelemetry.exporter.implementation.models.MetricsData;
import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem;
import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.TelemetryUtil;
import com.microsoft.applicationinsights.internal.util.ThreadPoolUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -208,6 +209,9 @@ private TelemetryItem gatherData() {
point.setValue(numHealthy);

data.setProperties(properties);

telemetry.setTime(TelemetryUtil.getFormattedNow());

return telemetry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import com.azure.monitor.opentelemetry.exporter.implementation.models.*;
import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.TelemetryUtil;
import com.microsoft.applicationinsights.internal.perfcounter.PerformanceCounter;
import com.microsoft.applicationinsights.internal.util.LocalStringsUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -107,10 +108,16 @@ public void report(TelemetryClient telemetryClient) {
TelemetryClient.getActive().initMessageTelemetry(messageTelemetry, messageData);

messageData.setMessage(String.format("%s%s", "Suspected deadlocked threads: ", sb));

messageTelemetry.setTime(TelemetryUtil.getFormattedNow());
messageTelemetry.getTags().put(ContextTagKeys.AI_OPERATION_ID.toString(), uuid);

telemetryClient.trackAsync(messageTelemetry);
}
}

telemetry.setTime(TelemetryUtil.getFormattedNow());

telemetryClient.trackAsync(telemetry);
}
private void setThreadInfoAndStack(StringBuilder sb, ThreadInfo ti) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static void emitGcEvent(TelemetryClient telemetryClient, GcEventMonitorC
}
data.setMeasurements(measurements);

telemetry.setTime(TelemetryUtil.currentTime());
telemetry.setTime(TelemetryUtil.getFormattedNow());

telemetryClient.trackAsync(telemetry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ static UploadCompleteHandler sendServiceProfilerIndex(TelemetryClient telemetryC
TelemetryClient.getActive().initEventTelemetry(telemetry, data);

data.setName("ServiceProfilerIndex");
telemetry.setTime(TelemetryUtil.getFormattedNow());
data.setProperties(done.getServiceProfilerIndex().getProperties());
data.setMeasurements(done.getServiceProfilerIndex().getMetrics());

telemetry.setTime(TelemetryUtil.getFormattedNow());

telemetryClient.trackAsync(telemetry);
};
}
Expand Down

0 comments on commit 62be412

Please sign in to comment.