-
Notifications
You must be signed in to change notification settings - Fork 38
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
Switch to Zipkin v2 span format #141
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ class RackHandler | |
REQUEST_METHOD = Rack::REQUEST_METHOD rescue 'REQUEST_METHOD'.freeze | ||
|
||
DEFAULT_SERVER_RECV_TAGS = { | ||
Trace::BinaryAnnotation::PATH => PATH_INFO | ||
Trace::Span::Tag::PATH => PATH_INFO | ||
}.freeze | ||
|
||
def initialize(app, config = nil) | ||
|
@@ -55,12 +55,11 @@ def annotate_plugin(span, env, status, response_headers, response_body) | |
|
||
def trace!(span, zipkin_env, &block) | ||
trace_request_information(span, zipkin_env) | ||
span.record(Trace::Annotation::SERVER_RECV) | ||
span.kind = Trace::Span::Kind::SERVER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a way to tell if the incoming span ID was shared (from b3 headers)? if so, add span.shared=true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated in 1139cc5 |
||
span.record('whitelisted') if zipkin_env.force_sample? | ||
status, headers, body = yield | ||
ensure | ||
annotate_plugin(span, zipkin_env.env, status, headers, body) | ||
span.record(Trace::Annotation::SERVER_SEND) | ||
end | ||
|
||
def trace_request_information(span, zipkin_env) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,54 +48,17 @@ def default_endpoint | |
# Moved here as a first step, eventually move them out of the Trace module | ||
|
||
class Annotation | ||
CLIENT_SEND = "cs" | ||
CLIENT_RECV = "cr" | ||
SERVER_SEND = "ss" | ||
SERVER_RECV = "sr" | ||
|
||
attr_reader :value, :host, :timestamp | ||
def initialize(value, host) | ||
attr_reader :value, :timestamp | ||
|
||
def initialize(value) | ||
@timestamp = (Time.now.to_f * 1000 * 1000).to_i # micros | ||
@value = value | ||
@host = host | ||
end | ||
|
||
def to_h | ||
{ | ||
value: @value, | ||
timestamp: @timestamp, | ||
endpoint: host.to_h | ||
} | ||
end | ||
end | ||
|
||
class BinaryAnnotation | ||
SERVER_ADDRESS = 'sa'.freeze | ||
URI = 'http.url'.freeze | ||
METHOD = 'http.method'.freeze | ||
PATH = 'http.path'.freeze | ||
STATUS = 'http.status'.freeze | ||
LOCAL_COMPONENT = 'lc'.freeze | ||
ERROR = 'error'.freeze | ||
|
||
module Type | ||
BOOL = "BOOL" | ||
STRING = "STRING" | ||
end | ||
attr_reader :key, :value, :host | ||
|
||
def initialize(key, value, annotation_type, host) | ||
@key = key | ||
@value = value | ||
@annotation_type = annotation_type | ||
@host = host | ||
end | ||
|
||
def to_h | ||
{ | ||
key: @key, | ||
value: @value, | ||
endpoint: host.to_h | ||
timestamp: @timestamp | ||
} | ||
end | ||
end | ||
|
@@ -199,12 +162,29 @@ def to_i; @i128; end | |
|
||
# A span may contain many annotations | ||
class Span | ||
attr_accessor :name, :annotations, :binary_annotations, :debug | ||
module Tag | ||
METHOD = "http.method".freeze | ||
PATH = "http.path".freeze | ||
STATUS = "http.status".freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong, it should be http.status_code though possibly was always incorrect here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated d4b6254 |
||
LOCAL_COMPONENT = "lc".freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ls is no longer needed unless there's a value for it. sometimes we had "lc"->"" just to add an endpoint to a span. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we are still using it in our library. Added TODO in 2cd021e |
||
ERROR = "error".freeze | ||
end | ||
|
||
module Kind | ||
CLIENT = "CLIENT".freeze | ||
SERVER = "SERVER".freeze | ||
end | ||
|
||
attr_accessor :name, :kind, :local_endpoint, :remote_endpoint, :annotations, :tags, :debug | ||
|
||
def initialize(name, span_id) | ||
@name = name | ||
@span_id = span_id | ||
@kind = nil | ||
@local_endpoint = nil | ||
@remote_endpoint = nil | ||
@annotations = [] | ||
@binary_annotations = [] | ||
@tags = {} | ||
@debug = span_id.debug? | ||
@timestamp = to_microseconds(Time.now) | ||
@duration = UNKNOWN_DURATION | ||
|
@@ -219,28 +199,30 @@ def to_h | |
name: @name, | ||
traceId: @span_id.trace_id.to_s, | ||
id: @span_id.span_id.to_s, | ||
annotations: @annotations.map(&:to_h), | ||
binaryAnnotations: @binary_annotations.map(&:to_h), | ||
localEndpoint: @local_endpoint.to_h, | ||
timestamp: @timestamp, | ||
duration: @duration, | ||
debug: @debug | ||
} | ||
h[:parentId] = @span_id.parent_id.to_s unless @span_id.parent_id.nil? | ||
h[:kind] = @kind unless @kind.nil? | ||
h[:remoteEndpoint] = @remote_endpoint.to_h unless @remote_endpoint.nil? | ||
h[:annotations] = @annotations.map(&:to_h) unless @annotations.empty? | ||
h[:tags] = @tags unless @tags.empty? | ||
h | ||
end | ||
|
||
# We record information into spans, then we send these spans to zipkin | ||
def record(value, endpoint = Trace.default_endpoint) | ||
annotations << Trace::Annotation.new(value.to_s, endpoint) | ||
def record(value) | ||
annotations << Trace::Annotation.new(value.to_s) | ||
end | ||
|
||
def record_tag(key, value, type = Trace::BinaryAnnotation::Type::STRING, endpoint = Trace.default_endpoint) | ||
value = value.to_s if type == Trace::BinaryAnnotation::Type::STRING | ||
binary_annotations << Trace::BinaryAnnotation.new(key, value, type, endpoint) | ||
def record_tag(key, value) | ||
@tags[key] = value | ||
end | ||
|
||
def record_local_component(value) | ||
record_tag(BinaryAnnotation::LOCAL_COMPONENT, value) | ||
record_tag(Tag::LOCAL_COMPONENT, value) | ||
end | ||
|
||
def has_parent_span? | ||
|
@@ -293,6 +275,5 @@ def to_h | |
hsh[:port] = port if port | ||
hsh | ||
end | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module ZipkinTracer | ||
VERSION = '0.32.4'.freeze | ||
VERSION = '0.33.0'.freeze | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a comment about what this is doing? I'm guessing it is lazy parsing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is explaining:
zipkin-ruby/lib/zipkin-tracer/hostname_resolver.rb
Lines 5 to 6 in f0435f9