Skip to content

Commit 39dd837

Browse files
committed
Support AvailabilityData
1 parent f9b46b9 commit 39dd837

File tree

11 files changed

+688
-78
lines changed

11 files changed

+688
-78
lines changed

agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/BytecodeUtil.java

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,29 @@ public void trackMetric(
7272
}
7373

7474
public static void trackEvent(
75-
Date timestamp,
75+
@Nullable Date timestamp,
7676
String name,
7777
Map<String, String> properties,
7878
Map<String, String> tags,
7979
Map<String, Double> metrics,
80-
String instrumentationKey) {
80+
@Nullable String instrumentationKey) {
8181
if (delegate != null) {
8282
delegate.trackEvent(timestamp, name, properties, tags, metrics, instrumentationKey);
8383
}
8484
}
8585

8686
public static void trackMetric(
87-
Date timestamp,
87+
@Nullable Date timestamp,
8888
String name,
89-
String namespace,
89+
@Nullable String namespace,
9090
double value,
9191
Integer count,
9292
Double min,
9393
Double max,
94-
Double stdDev,
94+
@Nullable Double stdDev,
9595
Map<String, String> properties,
9696
Map<String, String> tags,
97-
String instrumentationKey) {
97+
@Nullable String instrumentationKey) {
9898
if (delegate != null) {
9999
delegate.trackMetric(
100100
timestamp,
@@ -112,26 +112,26 @@ public static void trackMetric(
112112
}
113113

114114
public static void trackDependency(
115-
Date timestamp,
115+
@Nullable Date timestamp,
116116
String name,
117117
String id,
118118
String resultCode,
119-
Long totalMillis,
119+
Long duration,
120120
boolean success,
121121
String commandName,
122122
String type,
123123
String target,
124124
Map<String, String> properties,
125125
Map<String, String> tags,
126126
Map<String, Double> metrics,
127-
String instrumentationKey) {
127+
@Nullable String instrumentationKey) {
128128
if (delegate != null) {
129129
delegate.trackDependency(
130130
timestamp,
131131
name,
132132
id,
133133
resultCode,
134-
totalMillis,
134+
duration,
135135
success,
136136
commandName,
137137
type,
@@ -144,27 +144,27 @@ public static void trackDependency(
144144
}
145145

146146
public static void trackPageView(
147-
Date timestamp,
147+
@Nullable Date timestamp,
148148
String name,
149149
URI uri,
150150
long totalMillis,
151151
Map<String, String> properties,
152152
Map<String, String> tags,
153153
Map<String, Double> metrics,
154-
String instrumentationKey) {
154+
@Nullable String instrumentationKey) {
155155
if (delegate != null) {
156156
delegate.trackPageView(
157157
timestamp, name, uri, totalMillis, properties, tags, metrics, instrumentationKey);
158158
}
159159
}
160160

161161
public static void trackTrace(
162-
Date timestamp,
162+
@Nullable Date timestamp,
163163
String message,
164164
int severityLevel,
165165
Map<String, String> properties,
166166
Map<String, String> tags,
167-
String instrumentationKey) {
167+
@Nullable String instrumentationKey) {
168168
if (delegate != null) {
169169
delegate.trackTrace(timestamp, message, severityLevel, properties, tags, instrumentationKey);
170170
}
@@ -174,15 +174,15 @@ public static void trackRequest(
174174
String id,
175175
String name,
176176
URL url,
177-
Date timestamp,
177+
@Nullable Date timestamp,
178178
Long duration,
179179
String responseCode,
180180
boolean success,
181181
String source,
182182
Map<String, String> properties,
183183
Map<String, String> tags,
184184
Map<String, Double> metrics,
185-
String instrumentationKey) {
185+
@Nullable String instrumentationKey) {
186186
if (delegate != null) {
187187
delegate.trackRequest(
188188
id,
@@ -201,19 +201,47 @@ public static void trackRequest(
201201
}
202202

203203
public static void trackException(
204-
Date timestamp,
204+
@Nullable Date timestamp,
205205
Throwable throwable,
206206
int severityLevel,
207207
Map<String, String> properties,
208208
Map<String, String> tags,
209209
Map<String, Double> metrics,
210-
String instrumentationKey) {
210+
@Nullable String instrumentationKey) {
211211
if (delegate != null) {
212212
delegate.trackException(
213213
timestamp, throwable, severityLevel, properties, tags, metrics, instrumentationKey);
214214
}
215215
}
216216

217+
public static void trackAvailability(
218+
@Nullable Date timestamp,
219+
String id,
220+
String name,
221+
@Nullable Long duration,
222+
boolean success,
223+
String runLocation,
224+
String message,
225+
Map<String, String> properties,
226+
Map<String, String> tags,
227+
Map<String, Double> metrics,
228+
@Nullable String instrumentationKey) {
229+
if (delegate != null) {
230+
delegate.trackAvailability(
231+
timestamp,
232+
id,
233+
name,
234+
duration,
235+
success,
236+
runLocation,
237+
message,
238+
properties,
239+
tags,
240+
metrics,
241+
instrumentationKey);
242+
}
243+
}
244+
217245
public static void flush() {
218246
if (delegate != null) {
219247
delegate.flush();
@@ -313,7 +341,7 @@ void trackDependency(
313341
@Nullable Date timestamp,
314342
String name,
315343
String id,
316-
String resultCode,
344+
String duration,
317345
Long totalMillis,
318346
boolean success,
319347
String commandName,
@@ -365,6 +393,19 @@ void trackException(
365393
Map<String, Double> metrics,
366394
@Nullable String instrumentationKey);
367395

396+
void trackAvailability(
397+
@Nullable Date timestamp,
398+
String id,
399+
String name,
400+
@Nullable Long duration,
401+
boolean success,
402+
String runLocation,
403+
String message,
404+
Map<String, String> properties,
405+
Map<String, String> tags,
406+
Map<String, Double> metrics,
407+
@Nullable String instrumentationKey);
408+
368409
void flush();
369410

370411
void logErrorOnce(Throwable t);

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/classicsdk/BytecodeUtilImpl.java

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.azure.monitor.opentelemetry.exporter.implementation.AiOperationNameSpanProcessor;
2828
import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder;
29+
import com.azure.monitor.opentelemetry.exporter.implementation.builders.AvailabilityTelemetryBuilder;
2930
import com.azure.monitor.opentelemetry.exporter.implementation.builders.EventTelemetryBuilder;
3031
import com.azure.monitor.opentelemetry.exporter.implementation.builders.ExceptionTelemetryBuilder;
3132
import com.azure.monitor.opentelemetry.exporter.implementation.builders.MessageTelemetryBuilder;
@@ -159,7 +160,7 @@ public void trackDependency(
159160
String name,
160161
@Nullable String id,
161162
String resultCode,
162-
@Nullable Long totalMillis,
163+
@Nullable Long duration,
163164
boolean success,
164165
String commandName,
165166
String type,
@@ -182,8 +183,8 @@ public void trackDependency(
182183
telemetryBuilder.setId(id);
183184
}
184185
telemetryBuilder.setResultCode(resultCode);
185-
if (totalMillis != null) {
186-
telemetryBuilder.setDuration(FormattedDuration.fromNanos(MILLISECONDS.toNanos(totalMillis)));
186+
if (duration != null) {
187+
telemetryBuilder.setDuration(FormattedDuration.fromNanos(MILLISECONDS.toNanos(duration)));
187188
}
188189
telemetryBuilder.setSuccess(success);
189190
telemetryBuilder.setData(commandName);
@@ -383,6 +384,58 @@ public void trackException(
383384
track(telemetryBuilder, tags, true);
384385
}
385386

387+
@Override
388+
public void trackAvailability(
389+
@Nullable Date timestamp,
390+
String id,
391+
String name,
392+
@Nullable Long duration,
393+
boolean success,
394+
String runLocation,
395+
String message,
396+
Map<String, String> properties,
397+
Map<String, String> tags,
398+
Map<String, Double> measurements,
399+
@Nullable String instrumentationKey) {
400+
401+
if (Strings.isNullOrEmpty(name)) {
402+
return;
403+
}
404+
AvailabilityTelemetryBuilder telemetryBuilder =
405+
TelemetryClient.getActive().newAvailabilityTelemetryBuilder();
406+
407+
telemetryBuilder.setName(name);
408+
if (id == null) {
409+
telemetryBuilder.setId(AiLegacyPropagator.generateSpanId());
410+
} else {
411+
telemetryBuilder.setId(id);
412+
}
413+
if (duration != null) {
414+
telemetryBuilder.setDuration(FormattedDuration.fromNanos(MILLISECONDS.toNanos(duration)));
415+
}
416+
telemetryBuilder.setSuccess(success);
417+
telemetryBuilder.setRunLocation(runLocation);
418+
telemetryBuilder.setMessage(message);
419+
for (Map.Entry<String, Double> entry : measurements.entrySet()) {
420+
telemetryBuilder.addMeasurement(entry.getKey(), entry.getValue());
421+
}
422+
for (Map.Entry<String, String> entry : properties.entrySet()) {
423+
telemetryBuilder.addProperty(entry.getKey(), entry.getValue());
424+
}
425+
426+
if (timestamp != null) {
427+
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromEpochMillis(timestamp.getTime()));
428+
} else {
429+
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
430+
}
431+
selectivelySetTags(telemetryBuilder, tags);
432+
if (instrumentationKey != null) {
433+
telemetryBuilder.setInstrumentationKey(instrumentationKey);
434+
}
435+
436+
track(telemetryBuilder, tags, false);
437+
}
438+
386439
@Nullable
387440
private static SeverityLevel getSeverityLevel(int value) {
388441
// these mappings from the 2.x SDK

0 commit comments

Comments
 (0)