Skip to content

Commit

Permalink
Merge pull request #5 from praveenbarli/writetoaidatamodel
Browse files Browse the repository at this point in the history
data model changes to add name, id and dependency for sr annotaiton
  • Loading branch information
praveenbarli authored Jun 29, 2017
2 parents c563faf + 607f59c commit ab7fc99
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 57 deletions.
5 changes: 0 additions & 5 deletions storage/applicationinsights/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
<artifactId>applicationinsights-core</artifactId>
<version>[1.0,)</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-web</artifactId>
<version>[1.0,)</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
package zipkin.storage.applicationinsights;

import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.telemetry.RequestTelemetry;
import com.microsoft.applicationinsights.telemetry.SeverityLevel;
import com.microsoft.applicationinsights.TelemetryConfiguration;
import com.microsoft.applicationinsights.telemetry.Duration;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import zipkin.Annotation;
import zipkin.Span;
import zipkin.internal.Util;
import zipkin.storage.StorageAdapters;
import zipkin.Constants;

import static zipkin.internal.ApplyTimestampAndDuration.guessTimestamp;

Expand All @@ -47,12 +53,22 @@ public void accept(List<Span> spans) {
for (int i = 0; i < spans.size(); i++) {
Span span = spans.get(i);
Map<String, String> spanProps = new HashMap<String, String>();

String spanId = Long.toString(span.id);
String parentSpanId = span.parentId != null? Long.toString(span.parentId): null;

String traceId = Long.toString(span.traceId);
String traceIdHigh = Long.toString(span.traceIdHigh);
String namespace = (this.namespace == null) ? "" : this.namespace;

//set indexing properties, avoid null values for props
spanProps.put("spanid", Long.toString(span.id));
spanProps.put("traceId", Long.toString(span.traceId));
spanProps.put("traceIdHigh", Long.toString(span.traceIdHigh));
spanProps.put("spanid", spanId);
spanProps.put("traceId", traceId);
spanProps.put("traceIdHigh", traceIdHigh);
if(parentSpanId!= null)
spanProps.put("OperationParentId", parentSpanId);
//namespace to support duplicate data
spanProps.put("namespace", (this.namespace == null)?"":this.namespace);
spanProps.put("namespace", namespace);
if (span.annotations != null
&& span.annotations.size() > 0
&& span.annotations.get(0).endpoint != null
Expand All @@ -69,6 +85,24 @@ public void accept(List<Span> spans) {
String res = gson.toJson(jsonElement);
String msg = "{ \"Span\":" + res + "}";
telemetry.trackTrace(msg, SeverityLevel.Critical, spanProps);

//data model changes
telemetry.getContext().getOperation().setId(Util.toLowerHex(span.traceIdHigh, span.traceId));
telemetry.getContext().getOperation().setName(span.name);

for (Annotation annotation : span.annotations) {

if (annotation.value.equalsIgnoreCase(Constants.CLIENT_SEND)) {
String spanName = span.name !=null && !span.name.isEmpty()?span.name:Constants.CLIENT_SEND;
telemetry.trackDependency(spanName, "request", new Duration(span.duration==null?0L:span.duration/1000),
true);
}
else if(annotation.value.equalsIgnoreCase(Constants.SERVER_SEND)){
String spanName = span.name !=null && !span.name.isEmpty()?span.name:Constants.SERVER_RECV;
telemetry.trackRequest(new RequestTelemetry(spanName, new Date(timestamp), span.duration/1000,
"Ok",true));
}
}
}

telemetry.flush();
Expand Down

This file was deleted.

0 comments on commit ab7fc99

Please sign in to comment.