Skip to content

Commit

Permalink
Support AvailabilityData
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Aug 17, 2022
1 parent cd630b4 commit a2fc8e6
Show file tree
Hide file tree
Showing 11 changed files with 688 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,29 @@ public void trackMetric(
}

public static void trackEvent(
Date timestamp,
@Nullable Date timestamp,
String name,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> metrics,
String instrumentationKey) {
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackEvent(timestamp, name, properties, tags, metrics, instrumentationKey);
}
}

public static void trackMetric(
Date timestamp,
@Nullable Date timestamp,
String name,
String namespace,
@Nullable String namespace,
double value,
Integer count,
Double min,
Double max,
Double stdDev,
@Nullable Double stdDev,
Map<String, String> properties,
Map<String, String> tags,
String instrumentationKey) {
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackMetric(
timestamp,
Expand All @@ -112,26 +112,26 @@ public static void trackMetric(
}

public static void trackDependency(
Date timestamp,
@Nullable Date timestamp,
String name,
String id,
String resultCode,
Long totalMillis,
Long duration,
boolean success,
String commandName,
String type,
String target,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> metrics,
String instrumentationKey) {
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackDependency(
timestamp,
name,
id,
resultCode,
totalMillis,
duration,
success,
commandName,
type,
Expand All @@ -144,27 +144,27 @@ public static void trackDependency(
}

public static void trackPageView(
Date timestamp,
@Nullable Date timestamp,
String name,
URI uri,
long totalMillis,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> metrics,
String instrumentationKey) {
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackPageView(
timestamp, name, uri, totalMillis, properties, tags, metrics, instrumentationKey);
}
}

public static void trackTrace(
Date timestamp,
@Nullable Date timestamp,
String message,
int severityLevel,
Map<String, String> properties,
Map<String, String> tags,
String instrumentationKey) {
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackTrace(timestamp, message, severityLevel, properties, tags, instrumentationKey);
}
Expand All @@ -174,15 +174,15 @@ public static void trackRequest(
String id,
String name,
URL url,
Date timestamp,
@Nullable Date timestamp,
Long duration,
String responseCode,
boolean success,
String source,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> metrics,
String instrumentationKey) {
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackRequest(
id,
Expand All @@ -201,19 +201,47 @@ public static void trackRequest(
}

public static void trackException(
Date timestamp,
@Nullable Date timestamp,
Throwable throwable,
int severityLevel,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> metrics,
String instrumentationKey) {
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackException(
timestamp, throwable, severityLevel, properties, tags, metrics, instrumentationKey);
}
}

public static void trackAvailability(
@Nullable Date timestamp,
String id,
String name,
@Nullable Long duration,
boolean success,
String runLocation,
String message,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> metrics,
@Nullable String instrumentationKey) {
if (delegate != null) {
delegate.trackAvailability(
timestamp,
id,
name,
duration,
success,
runLocation,
message,
properties,
tags,
metrics,
instrumentationKey);
}
}

public static void flush() {
if (delegate != null) {
delegate.flush();
Expand Down Expand Up @@ -313,7 +341,7 @@ void trackDependency(
@Nullable Date timestamp,
String name,
String id,
String resultCode,
String duration,
Long totalMillis,
boolean success,
String commandName,
Expand Down Expand Up @@ -365,6 +393,19 @@ void trackException(
Map<String, Double> metrics,
@Nullable String instrumentationKey);

void trackAvailability(
@Nullable Date timestamp,
String id,
String name,
@Nullable Long duration,
boolean success,
String runLocation,
String message,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> metrics,
@Nullable String instrumentationKey);

void flush();

void logErrorOnce(Throwable t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.azure.monitor.opentelemetry.exporter.implementation.AiOperationNameSpanProcessor;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.AvailabilityTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.EventTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.ExceptionTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.MessageTelemetryBuilder;
Expand Down Expand Up @@ -159,7 +160,7 @@ public void trackDependency(
String name,
@Nullable String id,
String resultCode,
@Nullable Long totalMillis,
@Nullable Long duration,
boolean success,
String commandName,
String type,
Expand All @@ -182,8 +183,8 @@ public void trackDependency(
telemetryBuilder.setId(id);
}
telemetryBuilder.setResultCode(resultCode);
if (totalMillis != null) {
telemetryBuilder.setDuration(FormattedDuration.fromNanos(MILLISECONDS.toNanos(totalMillis)));
if (duration != null) {
telemetryBuilder.setDuration(FormattedDuration.fromNanos(MILLISECONDS.toNanos(duration)));
}
telemetryBuilder.setSuccess(success);
telemetryBuilder.setData(commandName);
Expand Down Expand Up @@ -383,6 +384,58 @@ public void trackException(
track(telemetryBuilder, tags, true);
}

@Override
public void trackAvailability(
@Nullable Date timestamp,
String id,
String name,
@Nullable Long duration,
boolean success,
String runLocation,
String message,
Map<String, String> properties,
Map<String, String> tags,
Map<String, Double> measurements,
@Nullable String instrumentationKey) {

if (Strings.isNullOrEmpty(name)) {
return;
}
AvailabilityTelemetryBuilder telemetryBuilder =
TelemetryClient.getActive().newAvailabilityTelemetryBuilder();

telemetryBuilder.setName(name);
if (id == null) {
telemetryBuilder.setId(AiLegacyPropagator.generateSpanId());
} else {
telemetryBuilder.setId(id);
}
if (duration != null) {
telemetryBuilder.setDuration(FormattedDuration.fromNanos(MILLISECONDS.toNanos(duration)));
}
telemetryBuilder.setSuccess(success);
telemetryBuilder.setRunLocation(runLocation);
telemetryBuilder.setMessage(message);
for (Map.Entry<String, Double> entry : measurements.entrySet()) {
telemetryBuilder.addMeasurement(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : properties.entrySet()) {
telemetryBuilder.addProperty(entry.getKey(), entry.getValue());
}

if (timestamp != null) {
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromEpochMillis(timestamp.getTime()));
} else {
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
}
selectivelySetTags(telemetryBuilder, tags);
if (instrumentationKey != null) {
telemetryBuilder.setInstrumentationKey(instrumentationKey);
}

track(telemetryBuilder, tags, false);
}

@Nullable
private static SeverityLevel getSeverityLevel(int value) {
// these mappings from the 2.x SDK
Expand Down
Loading

0 comments on commit a2fc8e6

Please sign in to comment.