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

Add support for the LightStep binary format in SpanContext propagation. #40

Closed
wants to merge 3 commits into from

Conversation

joeblubaugh
Copy link

This change adds support for the LightStep binary format (a protocol
buffer-based encoding) of OT SpanContext in the LightStep tracer.

LSBinaryCodec contains all functions that performing encoding and
decoding of this format, which is a set of bytes that are then base64
encoded.

This change adds support for the LightStep binary format (a protocol
buffer-based encoding) of OT SpanContext in the LightStep tracer.

LSBinaryCodec contains all functions that performing encoding and
decoding of this format, which is a set of bytes that are then base64
encoded.
@joeblubaugh joeblubaugh requested review from bhs and jmacd March 30, 2017 22:39
Copy link
Contributor

@bhs bhs left a comment

Choose a reason for hiding this comment

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

Just a few first-pass comments and meta-comments.

I'll try to turn up the pedantic-ness since this is all so subtle.

}
}

+ (void)writeFixedEncodedUInt64:(UInt64)number buffer:(NSMutableData *)buffer {
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be easier to grok/review if we move the truly generic stuff (like this) into its own compilation unit

Copy link
Author

Choose a reason for hiding this comment

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

Done - these are now moved to LSPBUtil

return keyInfo;
}

// Reads a varint off the proto bytes, advances the offset to the next byte after the varint.
Copy link
Contributor

Choose a reason for hiding this comment

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

assuming you are basing each of these helper functions on C/C++ code that lives elsewhere, can you link to those function definitions in each function comment?

Copy link
Author

Choose a reason for hiding this comment

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

not really - they're based on my reading of the Protobuf encoding "spec"

return false;
}

while (head < tail) {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like corrupt data could lead to an infinite loop if mapKeyInfo.length == 0... I'm not reading all of this defensively, but I think we should audit this code to check that corrupt data doesn't lead to actual crashes or infinite loops (and attempt to defend against them: e.g., in the mapKeyInfo.length == 0 case, we would fill out errorPtr with something and return).

Copy link
Author

Choose a reason for hiding this comment

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

Yes, corrupt data could lead to an infinite loop here. There's also a bug where we weren't advancing the offset correctly after reading a baggage string.

return outer;
}

+ (BOOL)decodeMessage:(NSData *)protoEnc
Copy link
Contributor

Choose a reason for hiding this comment

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

thinking out loud: would it make more sense to only include the encode path for now? realistically the iOS app has no need to decode a context/baggage ~ever, and the less code we have here the fewer errors there might be.

Copy link
Author

Choose a reason for hiding this comment

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

It's actually slightly easier to test if I can decode too - what "should" a given message look like? Kind of a pain to generate the test cases...

Copy link
Author

Choose a reason for hiding this comment

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

This also gives us a road to server-side swift integration, which is coming: http://perfect.org/

Copy link
Member

Choose a reason for hiding this comment

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

It should not be very difficult to separate the encoder and decoder into separate libraries, though. It's either a C-preprocessor, BUILD-system problem, or pragma thing.

#if LIGHTSTEP_CARRIER_ENCODER
...
#endif

Copy link
Author

Choose a reason for hiding this comment

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

Any advice about what to do about code that calls the decode path? What's the right way to switch on that? Would it also be to use #if or something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to separate them. I was just thinking about minimizing the surface area for this code entirely... i.e., it's not about the binary size or whether they get linked in, but just whether we need to maintain it.

I did have one thought overnight about this (ah, insomnia): we could skip baggage for v1 of this code (fine to keep it around in a git branch or whatever). Once all parties feel confident about the "flat" varint stuff, we could then introduce baggage and unittest the hell out of it, including intentionally corrupt data and so forth.

@joeblubaugh
Copy link
Author

I've also created a no-baggage, encoding only version of this PR:
#41

I left the utilities for writing a string map in place there for now.

@jmacd jmacd removed their request for review June 28, 2017 21:27
@joeblubaugh
Copy link
Author

This issue is ancient, and I imagine the repo itself is rarely used.

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.

None yet

3 participants