Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support metric namespace #2447

Merged
merged 7 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void trackMetric(
delegate.trackMetric(
null,
name,
null,
value,
count,
min,
Expand All @@ -71,55 +72,66 @@ 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,
@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, name, value, count, min, max, stdDev, properties, tags, instrumentationKey);
timestamp,
name,
namespace,
value,
count,
min,
max,
stdDev,
properties,
tags,
instrumentationKey);
}
}

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 @@ -132,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 @@ -162,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 @@ -189,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 @@ -287,6 +327,7 @@ void trackEvent(
void trackMetric(
@Nullable Date timestamp,
String name,
@Nullable String namespace,
double value,
Integer count,
Double min,
Expand All @@ -301,7 +342,7 @@ void trackDependency(
String name,
String id,
String resultCode,
Long totalMillis,
Long duration,
boolean success,
String commandName,
String type,
Expand Down Expand Up @@ -352,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 @@ -110,6 +111,7 @@ public void trackEvent(
public void trackMetric(
@Nullable Date timestamp,
String name,
@Nullable String namespace,
double value,
@Nullable Integer count,
@Nullable Double min,
Expand All @@ -127,6 +129,7 @@ public void trackMetric(

MetricPointBuilder point = new MetricPointBuilder();
point.setName(name);
point.setNamespace(namespace);
point.setValue(value);
point.setCount(count);
point.setMin(min);
Expand Down Expand Up @@ -157,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 @@ -180,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 @@ -381,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