-
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
Add support for reading B3 single header #165
Add support for reading B3 single header #165
Conversation
return new(parse_sampled_flags(b3_single_header)) if b3_single_header.size == 1 | ||
|
||
trace_id, span_id, flag, parent_span_id = b3_single_header.split('-') | ||
new(trace_id: trace_id, span_id: span_id, parent_span_id: parent_span_id, **parse_sampled_flags(flag)) |
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 it's a bit wasteful to have this method create a new array (by calling split), then a new object and then in the caller call to_a
which is going to create yet another array.
How about having a method getting the header as an input and return an array directly, without instantiating?
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.
though I would say this is the least code approach I've ever seen :P
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.
Updated in 2fef91b
@@ -0,0 +1,38 @@ | |||
module ZipkinTracer |
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.
how about adding the magic comment about frozen strings?
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.
Added in f8d6a89
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.
Lookin good!
agree some performance work could be done, but I like it anyway
def called_with_zipkin_headers? | ||
@called_with_zipkin_headers ||= B3_REQUIRED_HEADERS.all? { |key| @env.key?(key) } | ||
end | ||
|
||
private | ||
|
||
B3_REQUIRED_HEADERS = %w(HTTP_X_B3_TRACEID HTTP_X_B3_SPANID).freeze | ||
B3_OPT_HEADERS = %w(HTTP_X_B3_PARENTSPANID HTTP_X_B3_SAMPLED HTTP_X_B3_FLAGS).freeze | ||
B3_SINGLE_HEADER = 'HTTP_B3'.freeze |
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.
easier to quote, ain't it :)
return new(parse_sampled_flags(b3_single_header)) if b3_single_header.size == 1 | ||
|
||
trace_id, span_id, flag, parent_span_id = b3_single_header.split('-') | ||
new(trace_id: trace_id, span_id: span_id, parent_span_id: parent_span_id, **parse_sampled_flags(flag)) |
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.
though I would say this is the least code approach I've ever seen :P
describe ZipkinTracer::B3SingleHeaderFormat do | ||
let(:b3_single_header_format) { described_class.parse_from_header(b3_single_header) } | ||
|
||
context 'child span' do |
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.
add some malformed tests? Ex in brave we use
"not-a-tumor"
"b970dafd-0d95-40aa-95d8-1d8725aebe40"
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.
@adriancole In ruby client, we are doing malformed check in another class:
zipkin-ruby/lib/zipkin-tracer/trace.rb
Lines 134 to 150 in a1b1523
class TraceId128Bit < SpanId | |
HEX_REGEX_16 = /^[a-f0-9]{16}$/i | |
HEX_REGEX_32 = /^[a-f0-9]{32}$/i | |
MAX_SIGNED_I128 = (2 ** 128 / 2) -1 | |
MASK = (2 ** 128) - 1 | |
def self.from_value(v) | |
if v.is_a?(String) && v =~ HEX_REGEX_16 | |
SpanId.new(v.hex) | |
elsif v.is_a?(String) && v =~ HEX_REGEX_32 | |
new(v.hex) | |
elsif v.is_a?(Numeric) | |
new(v) | |
elsif v.is_a?(SpanId) | |
v | |
end | |
end |
I think we don't need to have malformed tests here but what do you think?
Co-Authored-By: Adrian Cole <adriancole@users.noreply.github.com>
sounds fine
…On Tue, Oct 8, 2019, 4:23 PM Yohei Kitamura ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In spec/lib/zipkin_b3_single_header_format_spec.rb
<#165 (comment)>
:
> @@ -0,0 +1,113 @@
+require 'spec_helper'
+
+describe ZipkinTracer::B3SingleHeaderFormat do
+ let(:b3_single_header_format) { described_class.parse_from_header(b3_single_header) }
+
+ context 'child span' do
@adriancole <https://github.com/adriancole> In ruby client, we are doing
malformed check in another class:
https://github.com/openzipkin/zipkin-ruby/blob/a1b1523a5bfcde3b6d2a8213a76e76b7a0e8a088/lib/zipkin-tracer/trace.rb#L134-L150
I think we don't need to have malformed tests here but what do you think?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#165?email_source=notifications&email_token=AAAPVV4T5L4BLAIP4TIYMILQNT26PA5CNFSM4I6MDYJKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCHJUNJA#discussion_r332740262>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAPVV64NCKWTHFYKRJ2HGDQNT26PANCNFSM4I6MDYJA>
.
|
This PR is just to support the "reading" part of B3 single header (#126).
The writing part is not included.
@adriancole sorry for taking a long time but I like the single header!
@jcarres-mdsol @jfeltesse-mdsol