Skip to content

Commit 633e0ae

Browse files
committed
Use the new simplified id format
See #1174
1 parent 58a4bc5 commit 633e0ae

File tree

2 files changed

+11
-19
lines changed
  • agent
    • agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/instrumentation/sdk
    • exporter/src/main/java/com/microsoft/applicationinsights/agent

2 files changed

+11
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private static void track(Telemetry telemetry) {
141141
String traceId = context.getTraceId().toLowerBase16();
142142
String spanId = context.getSpanId().toLowerBase16();
143143
telemetry.getContext().getOperation().setId(traceId);
144-
telemetry.getContext().getOperation().setParentId("|" + traceId + "." + spanId + ".");
144+
telemetry.getContext().getOperation().setParentId(spanId);
145145
}
146146
if (sample(telemetry)) {
147147
// this is not null because sdk instrumentation is not added until Global.setTelemetryClient() is called

agent/exporter/src/main/java/com/microsoft/applicationinsights/agent/Exporter.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ private void exportRequest(SpanData span) {
153153
telemetry.setSource(peerAddress + "/" + destination);
154154
}
155155

156-
String id = setContext(span, telemetry);
157-
telemetry.setId(id);
156+
setContext(span, telemetry);
157+
telemetry.setId(span.getSpanId().toLowerBase16());
158158

159159
telemetry.setTimestamp(new Date(NANOSECONDS.toMillis(span.getStartEpochNanos())));
160160
telemetry.setDuration(new Duration(NANOSECONDS.toMillis(span.getEndEpochNanos() - span.getStartEpochNanos())));
@@ -211,8 +211,8 @@ private void exportRemoteDependency(String component, SpanData span, boolean inP
211211
}
212212
}
213213

214-
String id = setContext(span, telemetry);
215-
telemetry.setId(id);
214+
setContext(span, telemetry);
215+
telemetry.setId(span.getSpanId().toLowerBase16());
216216

217217
telemetry.setTimestamp(new Date(NANOSECONDS.toMillis(span.getStartEpochNanos())));
218218
telemetry.setDuration(new Duration(NANOSECONDS.toMillis(span.getEndEpochNanos() - span.getStartEpochNanos())));
@@ -267,9 +267,8 @@ private void trackTrace(String message, long timeEpochNanos, String level, Strin
267267
TraceTelemetry telemetry = new TraceTelemetry(message, toSeverityLevel(level));
268268

269269
if (parentSpanId.isValid()) {
270-
String traceIdStr = traceId.toLowerBase16();
271-
telemetry.getContext().getOperation().setId(traceIdStr);
272-
telemetry.getContext().getOperation().setParentId(combine(traceIdStr, parentSpanId));
270+
telemetry.getContext().getOperation().setId(traceId.toLowerBase16());
271+
telemetry.getContext().getOperation().setParentId(parentSpanId.toLowerBase16());
273272
}
274273

275274
setProperties(telemetry.getProperties(), timeEpochNanos, level, loggerName);
@@ -282,9 +281,8 @@ private void trackTraceAsException(String message, long timeEpochNanos, String l
282281
ExceptionTelemetry telemetry = new ExceptionTelemetry();
283282

284283
if (parentSpanId.isValid()) {
285-
String traceIdStr = traceId.toLowerBase16();
286-
telemetry.getContext().getOperation().setId(traceIdStr);
287-
telemetry.getContext().getOperation().setParentId(combine(traceIdStr, parentSpanId));
284+
telemetry.getContext().getOperation().setId(traceId.toLowerBase16());
285+
telemetry.getContext().getOperation().setParentId(parentSpanId.toLowerBase16());
288286
}
289287

290288
telemetry.getData().setExceptions(Exceptions.minimalParse(errorStack));
@@ -441,19 +439,13 @@ private void track(Telemetry telemetry, Double samplingPercentage) {
441439
public void shutdown() {
442440
}
443441

444-
private static String setContext(SpanData span, Telemetry telemetry) {
442+
private static void setContext(SpanData span, Telemetry telemetry) {
445443
String traceId = span.getTraceId().toLowerBase16();
446444
telemetry.getContext().getOperation().setId(traceId);
447445
SpanId parentSpanId = span.getParentSpanId();
448446
if (parentSpanId.isValid()) {
449-
telemetry.getContext().getOperation().setParentId(combine(traceId, parentSpanId));
447+
telemetry.getContext().getOperation().setParentId(parentSpanId.toLowerBase16());
450448
}
451-
return combine(traceId, span.getSpanId());
452-
}
453-
454-
private static String combine(String traceId, SpanId spanId) {
455-
// TODO optimize with fixed length StringBuilder
456-
return "|" + traceId + "." + spanId.toLowerBase16() + ".";
457449
}
458450

459451
private static boolean isNonNullLong(AttributeValue attributeValue) {

0 commit comments

Comments
 (0)