Skip to content
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

Support Zipkin v2 Span format #12

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open

Support Zipkin v2 Span format #12

wants to merge 12 commits into from

Conversation

flier
Copy link
Owner

@flier flier commented Aug 11, 2017

resolve #11

@flier flier closed this Aug 11, 2017
Copy link

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you've done very well just site reading! Here are some tests that might help you. Note the server code is more complex just because sometimes it receives spans that are merged from multiple hosts. In a tracer, it will be simpler as there's only one local endpoint per span:

https://github.com/openzipkin/zipkin/blob/master/zipkin/src/test/java/zipkin/internal/Span2ConverterTest.java

/**
* \brief Report the span is sharing between the client and the server.
*/
inline bool shared(void) const { return m_shared; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this would be set when you successfully extract a trace context from headers (and use it)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set shared when extract span ID from context 5eb34ed

src/Span.h Outdated
writer.String(host->service_name());

writer.Key("ipv4");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi there's also ipv6

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, it's a bug, fixed in a2b1401

src/Span.h Outdated
for (auto &annotation : m_span.annotations)
{
if (annotation.value == TraceKeys::CLIENT_SEND || annotation.value == TraceKeys::CLIENT_RECV) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also messaging ones, too.. openzipkin/zipkin#1677

src/Span.h Outdated
local_endpoint.reset(new Endpoint(annotation.host));
}
if (!remote_endpoint && annotation.value == TraceKeys::SERVER_ADDR &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SERVER_ADDR is actually the remote side of span.kind=CLIENT

src/Span.h Outdated
for (auto &annotation : m_span.binary_annotations)
{
if (!local_endpoint && annotation.value == TraceKeys::CLIENT_ADDR &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLIENT_ADDR is actually the remote side of span.kind=SERVER

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a little confuse :), c6c4723

src/Span.h Outdated
(annotation.host.__isset.ipv4 || annotation.host.__isset.ipv6)) {
remote_endpoint.reset(new Endpoint(annotation.host));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also messaging addr.

"parentId": "%016llx",
"kind": "CLIENT",
"timestamp": %lld,
"annotations": [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to map span 1 format to span 2 involves a little more logic, particularly to remove redundancy (ex cs is the same as span.kind = client + start timestamp). The following is a little more complex than you need because from your tracer, you will only have one host in a span:

https://github.com/openzipkin/zipkin/blob/master/zipkin/src/main/java/zipkin/internal/Span2Converter.java#L43

If you expose a primary recording api in span2 style, like brave's the translation to span1 model is easier

https://github.com/openzipkin/zipkin/blob/master/zipkin/src/main/java/zipkin/internal/Span2Converter.java#L269

}
],
"tags": {
"sa": "8.8.8.8",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sa should translate into remote address

@flier flier reopened this Aug 11, 2017
@flier flier changed the base branch from master to develop August 11, 2017 10:13
@flier flier changed the title Feature/format v2 Support Zipkin v2 Span format Aug 14, 2017
}

const std::vector<Span2> Span2::from_span(const Span *span) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh wow! you actually ported over the conversion code :)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's too complicated to do it when serialize Span

Copy link

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

epic!

enum Kind {
UNKNOWN,
CLIENT,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRODUCER and CONSUMER are also kinds, btw. sadly the conversion code got a bit longer to support these https://github.com/openzipkin/zipkin/blob/master/zipkin/src/main/java/zipkin/internal/Span2Converter.java#L300

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is whether the client library need to support those broker message types?

ASSERT_EQ(std::string(buffer.GetString(), buffer.GetSize()), std::string(str, str_len));
}

TEST(span, serialize_json_v2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to add some more tests since there's a lot of conversion logic. Perhaps port some from here for the major cases https://github.com/openzipkin/zipkin/blob/master/zipkin/src/test/java/zipkin/internal/Span2ConverterTest.java

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm working on it

struct Span2 {
enum Kind {
UNKNOWN,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we leave null for unknown vs an unknown constant. as long as you handle the same semantics up to you though

@codefromthecrypt
Copy link

codefromthecrypt commented Aug 17, 2017 via email

#@namespace scala com.twitter.zipkin.thriftscala
namespace rb Zipkin

struct DependencyLink {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think you'll need this in the tracer, mainly as you can't reliably create a link streaming (bc you don't know if downstream will be instrumented or not)

@codefromthecrypt
Copy link

ps not required to implement the same way in C of course, but a late chat about java representation of the v2 format openzipkin/zipkin#1499 (comment)

@jcchavezs
Copy link

Great work @flier! any plan to continue this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants