Skip to content

128-bit trace IDs#17

Merged
dgoffredo merged 57 commits into
mainfrom
david.goffredo/128-bit-trace-id
Jan 19, 2023
Merged

128-bit trace IDs#17
dgoffredo merged 57 commits into
mainfrom
david.goffredo/128-bit-trace-id

Conversation

@dgoffredo
Copy link
Copy Markdown
Contributor

@dgoffredo dgoffredo commented Jan 11, 2023

This revision introduces 128-bit trace ID generation and propagation for all propagation styles.

It's based on an internal design document.

128-bit generation is disabled by default, and can be enabled via either bool TracerConfig::trace_id_128_bit or DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED.

Base automatically changed from david.goffredo/w3c-propagation to main January 13, 2023 15:53
@dgoffredo dgoffredo marked this pull request as ready for review January 16, 2023 16:19
@dgoffredo dgoffredo requested a review from cgilmour January 16, 2023 16:20
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.

Approving, with some comments for consideration.

Comment thread src/datadog/trace_id.h
namespace tracing {

struct TraceID {
std::uint64_t low;
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.

Setting the initial values to zero here would be another option, instead of doing it in constructors.

Comment thread src/datadog/trace_id.cpp
}

bool operator==(TraceID left, std::uint64_t right) {
return left == TraceID{right};
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.

It'd be clearer to me if this were defined as left.low == right if that's effectively the outcome.

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.

left.high == 0 && left.low == right, as I had it before. Then I saw this as better. I see your point, though.

Think I'll keep it as is.

decision.configured_rate = rule.sample_rate;
const std::uint64_t threshold = max_id_from_rate(rule.sample_rate);
if (knuth_hash(span.trace_id) < threshold) {
if (knuth_hash(span.trace_id.low) < threshold) {
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.

So sampling decisions are only affected by the low 64 bits, not the entire value?
Not objecting at all, but it might deserve mentioning in a comment somewhere.

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.

Yes... maybe in sampling_util, where knuth_hash is defined. Will do.


if (auto enabled_env =
lookup(environment::DD_TRACE_128_BIT_TRACEID_ENABLED)) {
result.trace_id_128_bit = !falsy(*enabled_env);
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.

Just for amusement, what's the outcome for DD_TRACE_128_BIT_TRACEID_ENABLED being set to "" or anything not specifically "falsy"?

This is answered in the tests, but is that the desired behavior?

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.

Yes, that's the desired behavior.

As we discussed in our standup yesterday, the falsiness behavior of this library could use revisiting. For now, though, I think that

export DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED=''

should enable the feature, if only because of the word "enabled" in there. Reminds me of the tension in C preprocess macros between #ifdef and #if.

Comment thread src/datadog/tracer_config.h Outdated
// trace IDs, extract them from incoming trace context, inject them into
// outgoing trace context, and send them to the collector. If false, then the
// tracer will generate 64-bit trace IDs, and extract only the lower 64 bits
// of trace IDs from incoming trace context.
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.

And what does it inject when false? (especially for w3c)

// of trace IDs from incoming trace context.
// `trace_id_128_bit` is overridden by the `DD_TRACE_128_BIT_TRACEID_ENABLED`
// environment variable.
bool trace_id_128_bit = false;
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 would be the impact of this being set to true right now, in terms of datadog-only propagation to other tracers?

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 would mean we always send the _dd.p.tid trace tag to the Agent and to forward services. The data cost is marginal, and I wasn't able to measure the latency cost. Still, the spec.

Comment thread src/datadog/trace_id.h Outdated
// ID, padded with zeroes on the left.
std::string hex_padded() const;

// Return either a decimal or a "0x"-prefixed hexadecimal representation of
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.

Not sure I like this, a straight token is easier to lug around (copy-paste) if it's being used for error diagnostics.

@dgoffredo dgoffredo merged commit c608269 into main Jan 19, 2023
@dgoffredo dgoffredo deleted the david.goffredo/128-bit-trace-id branch January 19, 2023 15:01
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