dd-trace-go icon indicating copy to clipboard operation
dd-trace-go copied to clipboard

chore: hold RLock when reading meta/metric maps

Open hannahkm opened this issue 1 month ago β€’ 3 comments

What does this PR do?

Ensures that span.metric and span.meta are read while holding span.mu.RLock. Targets areas where the lock is not already held and we are not in a StartSpan function.

The main issue was that, when finishing a span, we only want to set trace tags on the first finished span. In some cases, that is the same span that is passed to tracer.finish(). This span is already locked. However, in other cases, we get the first finished span from finishedSpans[0]. This span is not already locked. This PR adds a lock around this span when setting its metric and meta tags.

Motivation

#incident-46344

Reviewer's Checklist

  • [ ] Changed code has unit tests for its functionality at or near 100% coverage.
  • [ ] System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • [ ] 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.
  • [ ] New code is free of linting errors. You can check this by running ./scripts/lint.sh locally.
  • [ ] Add an appropriate team label so this PR gets put in the right place for the release notes.
  • [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

hannahkm avatar Dec 11 '25 19:12 hannahkm

Benchmarks

Benchmark execution time: 2025-12-17 13:33:03

Comparing candidate commit 07c776eaedef1cd5616741eaf4fbffd3940c797e in PR branch hannahkm/rlock-meta with baseline commit c8e44a3d84ad2e60fce8394dcd24b3ba01ff58b8 in branch main.

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

pr-commenter[bot] avatar Dec 11 '25 19:12 pr-commenter[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 54.37%. Comparing base (bb69888) to head (7fc6441). :warning: Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Ξ”
ddtrace/tracer/spancontext.go 90.18% <100.00%> (+0.12%) :arrow_up:

... and 7 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Dec 11 '25 19:12 codecov[bot]

βœ…Β Tests

πŸŽ‰ All green!

❄️ No new flaky tests detected
πŸ§ͺ All tests passed

This comment will be updated automatically if new data arrives.
πŸ”— Commit SHA: 07c776e | Docs | Datadog PR Page | Was this helpful? Give us feedback!

/merge

hannahkm avatar Dec 15 '25 15:12 hannahkm

View all feedbacks in Devflow UI.

2025-12-15 15:21:00 UTC :information_source: Start processing command /merge


2025-12-15 15:21:13 UTC :information_source: MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts β€” but it could also be blocked by other repository rules or settings. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.


2025-12-15 19:22:10 UTC :warning: MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

/merge

darccio avatar Dec 16 '25 10:12 darccio

View all feedbacks in Devflow UI.

2025-12-16 10:13:59 UTC :information_source: Start processing command /merge


2025-12-16 10:14:09 UTC :information_source: MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts β€” but it could also be blocked by other repository rules or settings. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.


2025-12-16 14:15:15 UTC :warning: MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

@codex review

darccio avatar Dec 16 '25 15:12 darccio

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/merge

darccio avatar Dec 17 '25 13:12 darccio

View all feedbacks in Devflow UI.

2025-12-17 13:23:37 UTC :information_source: Start processing command /merge


2025-12-17 13:23:46 UTC :information_source: MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts β€” but it could also be blocked by other repository rules or settings. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.


2025-12-17 13:46:16 UTC :information_source: MergeQueue: merge request added to the queue

The expected merge time in main is approximately 44m (p90).


2025-12-17 14:13:52 UTC :information_source: MergeQueue: This merge request was merged