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 16 hex character traceIds. #18

Merged
merged 2 commits into from
Jun 28, 2021
Merged

Conversation

alaendle
Copy link
Contributor

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.

Copy link
Owner

@mtth mtth 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 the PR! Having this inside Zipkin.hs makes sense - it appears to be tied to this particular representation.

Comment on lines 268 to 269
decodeZipkinTraceID txt | T.length txt == 16 = decodeTraceID $ "0000000000000000" <> txt
| otherwise = decodeTraceID txt
Copy link
Owner

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.

-- | 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
Copy link
Owner

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.

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.
Copy link
Owner

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. ...".

@mtth mtth merged commit 79afc40 into mtth:master Jun 28, 2021
@alaendle alaendle deleted the 16hex-traceId branch January 18, 2024 09:39
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.

Allow 16 lower-hex character TraceId's
2 participants