Skip to content

Make parsing of Google's X-Cloud-Trace-Context less strict#850

Merged
janstenpickle merged 8 commits intotrace4cats:masterfrom
sideeffffect:less-strict-google-trace-header
Mar 9, 2023
Merged

Make parsing of Google's X-Cloud-Trace-Context less strict#850
janstenpickle merged 8 commits intotrace4cats:masterfrom
sideeffffect:less-strict-google-trace-header

Conversation

@sideeffffect
Copy link
Copy Markdown
Contributor

The ;o=... part is supposed to be optional

@sideeffffect
Copy link
Copy Markdown
Contributor Author

/cc @janstenpickle @catostrophe for better visibility. I'd appreciate your review on this PR 🙇

@sideeffffect
Copy link
Copy Markdown
Contributor Author

CCing also @TimWSpence 🙏

val headerPattern =
"""(?xi)
|([0-9a-f]+) # trace ID
|([^\/]+) # trace ID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What motivates this change and the one below? Can the trace ID ever been non-hexadecimal or the span ID non-decimal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You will get error in either case. But this way you get more precise error. The regex should try to match only the rough format of the string.

Copy link
Copy Markdown
Collaborator

@janstenpickle janstenpickle 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 this @sideeffffect, just had one nitpick on parsing the BigInt error handling, other than that happy to merge!

Comment on lines 44 to 46
spanId <- Either.fromOption(
SpanId.fromHexString("%016x".format(BigInt(spanId))),
Either.catchNonFatal(BigInt(spanId)).toOption.flatMap(bi => SpanId.fromHexString("%016x".format(bi))),
new Exception("invalid span ID")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The parse method supports surfacing an exception on the left of an either so I'd suggest doing this instead:

Either.catchNonFatal(BigInt(spanId)).flatMap(bi => Either.fromOption(SpanId.fromHexString("%016x".format(bi)), new Exception("invalid span ID")))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

Copy link
Copy Markdown
Collaborator

@janstenpickle janstenpickle 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 @sideeffffect!

@janstenpickle janstenpickle merged commit 865f500 into trace4cats:master Mar 9, 2023
@sideeffffect sideeffffect deleted the less-strict-google-trace-header branch March 9, 2023 15:36
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.

5 participants