-
Notifications
You must be signed in to change notification settings - Fork 11
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 16 hex character traceIds. #18
Conversation
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.
Thanks for the PR! Having this inside Zipkin.hs
makes sense - it appears to be tied to this particular representation.
src/Monitor/Tracing/Zipkin.hs
Outdated
decodeZipkinTraceID txt | T.length txt == 16 = decodeTraceID $ "0000000000000000" <> txt | ||
| otherwise = decodeTraceID txt |
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.
Let's keep the indentation style consistent style and consolidate the common parts:
decodeZipkinTraceID txt =
let normalized = if T.length txt == 16 then "0000000000000000" <> txt else txt
in decodeTraceID normalized
Similar below for indentation.
src/Monitor/Tracing/Zipkin.hs
Outdated
-- | Takes into account that the first position of the b3 value is the 32 or 16 lower-hex character TraceId. | ||
encodeZipkinTraceID :: TraceID -> Text | ||
encodeZipkinTraceID traceId = let txt = encodeTraceID traceId | ||
in fromMaybe txt $ T.stripPrefix "0000000000000000" txt |
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.
Let's consolidate the prefix constant, for ex as shortIDPrefix
.
src/Monitor/Tracing/Zipkin.hs
Outdated
optional = encodeSpanID <$> maybeToList mbParentID | ||
in BS.intercalate "-" $ fmap T.encodeUtf8 $ required ++ optional | ||
|
||
-- | Takes into account that the first position of the b3 value is the 32 or 16 lower-hex character TraceId. |
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.
Can you start the new doc comments with a quick blurb describing what the function does (before the specifics sentence here)? Something like "Decodes a trace ID from its Zipkin header representation, returning nothing if it is invalid. ...".
Resolves #12
Intentionally I only changed Zipkin.hs and not Trace/Internal.hs:
a) It's part of the Zipkin specification, so I thought it naturally belongs to Zipkin.hs 😄
b) Other propagation standards (e.g. https://www.w3.org/TR/trace-context/#trace-id) use 128-bit - so I believe it's okay to always use 128-bit internally
c) Even if this is a internal module - it's public API - so to only change things in Zipkin.hs reduces the chance of a breaking change
But it has the drawback that the handling is somehow distributed and the implementation looks "patched".
As always, just let me know what you think.