Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Use jaeger.thrift #142

Merged
merged 20 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
34 changes: 34 additions & 0 deletions jaeger-core/src/main/java/com/uber/jaeger/Reference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2017, Uber Technologies, Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.uber.jaeger;

import lombok.Value;

/**
* @author Pavol Loffay
*/
@Value
public class Reference {

private final SpanContext spanContext;
private final String type;
}
82 changes: 7 additions & 75 deletions jaeger-core/src/main/java/com/uber/jaeger/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
package com.uber.jaeger;

import com.twitter.zipkin.thriftjava.Endpoint;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -39,12 +37,9 @@ public class Span implements io.opentracing.Span {
private final Map<String, Object> tags;
private long durationMicroseconds; // span durationMicroseconds
private String operationName;
private final List<Reference> references;
private SpanContext context;
private Endpoint peer;
private List<LogData> logs;
private String localComponent;
private boolean isClient;
private boolean isRPC;

Span(
Tracer tracer,
Expand All @@ -53,24 +48,22 @@ public class Span implements io.opentracing.Span {
long startTimeMicroseconds,
long startTimeNanoTicks,
boolean computeDurationViaNanoTicks,
Map<String, Object> tags) {
Map<String, Object> tags,
List<Reference> references) {
this.tracer = tracer;
this.operationName = operationName;
this.context = context;
this.startTimeMicroseconds = startTimeMicroseconds;
this.startTimeNanoTicks = startTimeNanoTicks;
this.computeDurationViaNanoTicks = computeDurationViaNanoTicks;
this.tags = new HashMap<String, Object>();
this.references = new ArrayList<Reference>(references);

for (Map.Entry<String, Object> tag : tags.entrySet()) {
setTagAsObject(tag.getKey(), tag.getValue());
}
}

public String getLocalComponent() {
return localComponent;
}

public long getStart() {
return startTimeMicroseconds;
}
Expand All @@ -85,18 +78,9 @@ public Tracer getTracer() {
return tracer;
}

public Endpoint getPeer() {
public List<Reference> getReferences() {
synchronized (this) {
return peer;
}
}

private Endpoint getOrMakePeer() {
synchronized (this) {
if (peer == null) {
peer = new Endpoint(0, (short) 0, "");
}
return peer;
return Collections.unmodifiableList(references);
}
}

Expand Down Expand Up @@ -204,48 +188,6 @@ public synchronized Span setTag(String key, Number value) {
return setTagAsObject(key, value);
}

/**
* Sets various fields on the {@link Span} when certain {@link Tags} are encountered
*
* @return true iff a special tag is handled
*/
private boolean handleSpecialTag(String key, Object value) {
// TODO use a map of handlers for special tags, instead of if/then
if (key.equals(Tags.COMPONENT.getKey()) && value instanceof String) {
localComponent = (String) value;
return true;
}

if (key.equals(Tags.PEER_HOST_IPV4.getKey()) && value instanceof Integer) {
getOrMakePeer().setIpv4((Integer) value);
return true;
}

if (key.equals(Tags.PEER_PORT.getKey()) && value instanceof Number) {
getOrMakePeer().setPort(((Number) value).shortValue());
return true;
}

if (key.equals(Tags.PEER_SERVICE.getKey()) && value instanceof String) {
getOrMakePeer().setService_name((String) value);
return true;
}

if (key.equals(Tags.SPAN_KIND.getKey()) && value instanceof String) {
isClient = Tags.SPAN_KIND_CLIENT.equals(value);
boolean isServer = Tags.SPAN_KIND_SERVER.equals(value);
isRPC = isClient || isServer;
return true;
}

return false;
}

/**
* Set a key:value tag on a span ONLY when the tag isn't special.
*
* See {@link #handleSpecialTag(String, Object)}
*/
private Span setTagAsObject(String key, Object value) {
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) {
int priority = ((Number) value).intValue();
Expand All @@ -260,9 +202,7 @@ private Span setTagAsObject(String key, Object value) {
}

if (context.isSampled()) {
if (!handleSpecialTag(key, value)) {
tags.put(key, value);
}
tags.put(key, value);
}

return this;
Expand Down Expand Up @@ -319,12 +259,4 @@ public Span log(long timestampMicroseconds, String message, /* @Nullable */ Obje
return this;
}
}

public boolean isRPC() {
return isRPC;
}

public boolean isRPCClient() {
return isClient;
}
}
Loading