Skip to content

enforce fixed length of 16 for _dd.p.tid#42

Merged
dgoffredo merged 5 commits into
mainfrom
david.goffredo/tid-has-fixed-length
Jul 11, 2023
Merged

enforce fixed length of 16 for _dd.p.tid#42
dgoffredo merged 5 commits into
mainfrom
david.goffredo/tid-has-fixed-length

Conversation

@dgoffredo
Copy link
Copy Markdown
Contributor

I missed a spot in #41. The integration test's -k command line argument, used to select a subset of tests to run, doesn't work the way I thought, so I wasn't running all of the tests.

This revision enforces a fixed length of 16 for the _dd.p.tid trace tag, i.e. the 64-bit hex value must be padded with zeroes.

@dgoffredo dgoffredo requested a review from cgilmour July 10, 2023 12:49
Comment thread src/datadog/tracer.cpp
span_data->tags[tags::internal::propagation_error] =
"inconsistent_tid " + extant->second;
extant->second = hex_high;
} else {
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.

Maybe add a comment here, supporting the comment above, describing what's going on. For example, the appearance of extant->second = hex_high; twice might be surprising.

Copy link
Copy Markdown
Contributor

@cgilmour cgilmour left a comment

Choose a reason for hiding this comment

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

Approved, with a usual amount of comments for consideration

Comment thread src/datadog/tracer.cpp
span_tags[tags::internal::propagation_error] = "malformed_tid " + value;
const Optional<std::uint64_t> high =
parse_trace_id_high(value, span_tags);
if (!high) {
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.

I'd consider tagging things in this block instead. It's the point where the error is being handled

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.

I could remove the span_tags argument from parse_trace_id_high, and duplicate the setting of "malformed_tid " ... in the two places where it is used. Yeah, I like that better.

Comment thread src/datadog/tracer.cpp Outdated
const std::string& value,
std::unordered_map<std::string, std::string>& span_tags) {
auto high = parse_uint64(value, 16);
if (!high || value.size() != 16) {
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.

Size/length could be checked before attempting to parse it

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.

Oh the underlying parse_integer is stripping spaces. That's fairly liberal. And makes the size check inaccurate.
It also means there should be some quoting around value when setting an error.

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.

parse_integer maybe ought to be more strict. I don't remember why I stripped the input -- maybe I was anticipating data coming from HTTP headers and environment variables. Probably better to be be more strict. I'll consider changing that...

Comment thread test/test_tracer.cpp
auto test_case = GENERATE(values<TestCase>(
{{__LINE__, "invalid _dd.p.tid", "noodle", "malformed_tid "},
{__LINE__, "_dd.p.tid inconsistent with trace ID", "adfeed",
{__LINE__, "short _dd.p.tid", "beef", "malformed_tid "},
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.

I'd probably test with values of length 0, 1, 15, and 17.
4 and 22 seems a bit arbitrary

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.

It is arbitrary. For the long tests I held down 0 until it looked longer than 16. For the short test I omitted any 0s.

1, 15, and 17, to be just below and above 16? Yeah, I see your point. I'll leave this, though.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Jul 11, 2023

Benchmarks

Benchmark execution time: 2023-07-11 19:33:20

Comparing candidate commit 20f8dd0 in PR branch david.goffredo/tid-has-fixed-length with baseline commit 9b2ac56 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

@dgoffredo dgoffredo force-pushed the david.goffredo/tid-has-fixed-length branch from f2e918e to 20f8dd0 Compare July 11, 2023 19:30
@dgoffredo dgoffredo merged commit 440c28e into main Jul 11, 2023
@dgoffredo dgoffredo deleted the david.goffredo/tid-has-fixed-length branch July 11, 2023 19:34
dmehala added a commit that referenced this pull request Jun 28, 2024
Fixed a regression introduced in #42 preventing HTTP headers with
leading spaces to be parsed.
dmehala added a commit that referenced this pull request Jun 28, 2024
Fixed a regression introduced in #42 preventing HTTP headers with
leading spaces to be parsed.
dmehala added a commit that referenced this pull request Jun 28, 2024
Fixed a regression introduced in #42 preventing HTTP headers with
leading spaces to be parsed.
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.

2 participants