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

ddtrace/tracer: encode span IDs in execution traces efficiently #2268

Merged
merged 4 commits into from
Oct 23, 2023

Conversation

nsrip-dd
Copy link
Contributor

@nsrip-dd nsrip-dd commented Oct 13, 2023

What does this PR do?

Encode span IDs directly as 8-byte unsigned integers in the execution trace log
message.

Add a unit test that we create the appropriate span annotations in execution
traces. This test is dependent on parsing an execution trace, which can
change format across releases. We don't have a standard library parser.
We rely on an external implementation. To prevent this test from
breaking in the window between when a new Go version comes out and when
the parser supports any format changes, guard it with the supported Go
version. We support several Go versions, so we should have some coverage
all the time.

cc @felixge

Motivation

We were previously encoding span IDs into execution traces as base-10
strings. This is wasteful, in terms of CPU time to encode the ID and
more importantly in terms of how much of the limited execution trace
data the profiler collects will be taken up by span IDs. They can be
encoded directly as 8-byte unsigned integers.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

We were previously encoding span IDs into execution traces as base-10
strings. This is wasteful, in terms of CPU time to encode the ID and
more importantly in terms of how much of the limited execution trace
data the profiler collects will be taken up by span IDs. They can be
encoded directly as 8-byte unsigned integers.
@pr-commenter
Copy link

pr-commenter bot commented Oct 13, 2023

Benchmarks

Benchmark execution time: 2023-10-23 13:07:04

Comparing candidate commit 33dc21c in PR branch prof-8343-small-span-id-trace-log with baseline commit e1a2437 in branch main.

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

Check that we create the appropriate span annotations in execution
traces. This test is dependent on parsing an execution trace, which can
change format across releases. We don't have a standard library parser.
We rely on an external implementation. To prevent this test from
breaking in the window between when a new Go version comes out and when
the parser supports any format changes, guard it with the supported Go
version. We support several Go versions, so we should have some coverage
all the time.
@nsrip-dd nsrip-dd marked this pull request as ready for review October 18, 2023 13:14
@nsrip-dd nsrip-dd requested a review from a team October 18, 2023 13:14
@nsrip-dd nsrip-dd marked this pull request as draft October 20, 2023 11:23
@nsrip-dd nsrip-dd marked this pull request as ready for review October 20, 2023 11:57
Comment on lines +708 to +711
// TODO: can we make string(b[:]) not allocate? e.g. with unsafe
// shenanigans? rt.Log won't retain the message string, though perhaps
// we can't assume that will always be the case.
rt.Log(ctx, "datadog.uint64_span_id", string(b[:]))
Copy link
Member

Choose a reason for hiding this comment

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

From Go 1.20 we can use unsafe.String but looking at the repository and from what I heard, I think that we don't want unsafe calls in the tracer.

Copy link
Member

Choose a reason for hiding this comment

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

@darccio 👍

Let's not worry about it as part of this PR. The previous code already caused an allocation as well as far as I can tell. We can revisit this for flight recording mode.

Copy link
Member

@felixge felixge left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

Comment on lines +708 to +711
// TODO: can we make string(b[:]) not allocate? e.g. with unsafe
// shenanigans? rt.Log won't retain the message string, though perhaps
// we can't assume that will always be the case.
rt.Log(ctx, "datadog.uint64_span_id", string(b[:]))
Copy link
Member

Choose a reason for hiding this comment

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

@darccio 👍

Let's not worry about it as part of this PR. The previous code already caused an allocation as well as far as I can tell. We can revisit this for flight recording mode.

@nsrip-dd nsrip-dd merged commit 5e9b0b1 into main Oct 23, 2023
52 checks passed
@nsrip-dd nsrip-dd deleted the prof-8343-small-span-id-trace-log branch October 23, 2023 13:15
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.

3 participants