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

http_text_format + w3c trace parent #55

Merged
merged 15 commits into from
Sep 12, 2019

Conversation

ibawt
Copy link
Contributor

@ibawt ibawt commented Aug 29, 2019

w3c Trace Parent support

  • omitting trace state as it's being removed ( at least as of now )
  • the actual integration points aren't well defined right now, but the TraceParent thing should be alright
  • I went through the w3c SHOULD's and MUST's and did most of them, at least in terms for the actual parsing

questions

  • pass through services? apparently we shouldn't do anything with it, not sure how to represent in the current api ( what defines a pass through service? why would anyone write a proxy in ruby anyhoo )
  • are trace-ids every not 32 bytes? there's language in the w3c standard indicating we should fill them with random values and not zeros. However it also says the trace-id is exactly 32 bytes long.
  • is this too many objects etc?

https://www.w3.org/TR/trace-context/

@ibawt
Copy link
Contributor Author

ibawt commented Sep 3, 2019

@fbogsany 👀 lets start the bike shed of the actual http_text_format api.

@ibawt
Copy link
Contributor Author

ibawt commented Sep 3, 2019

@fbogsany we could also just not parse the headers at and leave teh trace-ids as hex encoded strings? it would require 2x the memory, but would omit serialization and deserializations. Kind of feel like it should be a Number. maybe we should profile first.

@fbogsany
Copy link
Contributor

fbogsany commented Sep 3, 2019

we could also just not parse the headers at and leave teh trace-ids as hex encoded strings?

See discussion in #57. A similar point was raised there. I don't mind leaving them as hex strings, but we should still validate them.

@ibawt
Copy link
Contributor Author

ibawt commented Sep 5, 2019

@fbogsany comments have been addressed

@ibawt ibawt force-pushed the http-text-format branch 4 times, most recently from 7d9ff6f to ff8440d Compare September 5, 2019 16:22
end

def parse_flags(string)
OpenTelemetry::Trace::TraceFlags.from_byte(string.to_i(16))
Copy link
Contributor

Choose a reason for hiding this comment

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

D'you think we should add a from_string to TraceFlags and push the responsibility there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does the opentelemetry spec list the number of bytes and the hex format? ie 2 digit hex.
if it lives in the w3c but not in the OT spec I would say that would govern where it should live.

Copy link
Contributor

Choose a reason for hiding this comment

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

The OT spec says TraceFlags is a single byte of boolean flags. Otherwise it defers to the W3C spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then it should live here, as this is using a hex encoding of a byte. Therefore the at the boundary it should be a native byte.

@ibawt ibawt changed the title rough cut http_text_format + w3c trace parent Sep 6, 2019
@ibawt ibawt marked this pull request as ready for review September 6, 2019 17:55
Copy link
Member

@mwear mwear left a comment

Choose a reason for hiding this comment

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

Thanks for taking this work on @ibawt. I left a couple comments. I think the diff would be cleaned up if you could rebase this off of master.

@@ -17,7 +16,22 @@ module Propagation
# Propagation is usually implemented via library-specific request interceptors, where the client-side injects values
# and the server-side extracts them.
class HTTPTextFormat
# TODO
def extract(carrier, &block)
Copy link
Member

Choose a reason for hiding this comment

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

Would an implicit block be better since we opt for yielding and not using the explicit &block param.

In either case can we document the parameters to this method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

imo with an implicit block you have to read the documentation/implementation rather than the function signature. If you feel strongly I don't mind.

documentation for sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did the changes, have a look. Not so sure about my documentation though.

Copy link
Member

Choose a reason for hiding this comment

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

Looks good. The alternative would have been to use the block param (block.call) instead of using yield, but its slightly faster to use yield with an implicit block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I looked through the rails source, and I think a good rule is, only name the block if we pass it down to another method. Then it's clear the yield is getting "passed" as it were.

@ibawt
Copy link
Contributor Author

ibawt commented Sep 9, 2019

re: rebase, now you know why I was poking at getting the other merged :D

@@ -25,6 +25,10 @@ def from_byte(flags)
end
end

def to_s
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test?

Copy link
Contributor Author

@ibawt ibawt Sep 10, 2019

Choose a reason for hiding this comment

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

so I moved this into the trace parent, as the trace parent defines the flags it can support due to it's version. It also says that we can only send flags we know about re: version.

Also this pushes the "encoding" choice to the parent, which I think is the correct place for it.

@ibawt
Copy link
Contributor Author

ibawt commented Sep 10, 2019

RE: http_text_format class, I'm not too sold on the "getter" and "setter" as blocks. But I'd like to see how this will integrate with the rest of the code before bike shedding on it too much. Hence most of the meat is in the trace_parent class.

# @yield [Carrier, String] the header key
# {SpanContext}
def extract(carrier)
raise Error, 'block must be supplied' unless block_given?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be an ordinary ArgumentError rather than the OT Error. Same thing below in inject.

Copy link
Contributor

@fbogsany fbogsany left a comment

Choose a reason for hiding this comment

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

LGTM - thanks @ibawt!

# A TraceParent is an implementation of the W3C trace context specification
# https://www.w3.org/TR/trace-context/
# {SpanContext}
class TraceParent
Copy link
Member

Choose a reason for hiding this comment

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

The layout of this class is not what I am used to seeing. I'm not sure if we have a convention, or if we should have one, but typically I'm used to seeing something like:

class MyClass
  #constants
  MY_CONST = 1
  class << self
     #public class methods
     def public_class_method; end
     
     private
     
    #private class methods
     def private_class_method; end
  end
  
  #public instance methods

  def public_instance_method; end

  private
  
  #private instance methods
  def private_instance_method; end
end

Would there be any objections to adopting a similar format for OTel Ruby (and this file)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so you want the "static" methods up top? That doesn't bother me at all, I'll move it up.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, there are some that are in the class << self block and a few that are self. prefixed. If you wouldn't mind moving them into one class << self block at the top that'd be awesome!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated it, have a look.

Copy link
Member

Choose a reason for hiding this comment

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

Looks great!

Copy link
Member

@mwear mwear left a comment

Choose a reason for hiding this comment

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

Just the question about formatting. I also wanted to mention: #73 as it's related (but can and should be a seperate PR).

Copy link
Member

@mwear mwear left a comment

Choose a reason for hiding this comment

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

Nice work!

# A TraceParent is an implementation of the W3C trace context specification
# https://www.w3.org/TR/trace-context/
# {SpanContext}
class TraceParent
Copy link
Member

Choose a reason for hiding this comment

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

Looks great!

@fbogsany fbogsany merged commit 02f3138 into open-telemetry:master Sep 12, 2019
@fbogsany fbogsany deleted the http-text-format branch September 12, 2019 01:28
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