Skip to content

fix(opentelemetry): resolve thread-unsafe iter#18178

Open
llimllib wants to merge 1 commit into
DataDog:mainfrom
llimllib:main
Open

fix(opentelemetry): resolve thread-unsafe iter#18178
llimllib wants to merge 1 commit into
DataDog:mainfrom
llimllib:main

Conversation

@llimllib
Copy link
Copy Markdown

@llimllib llimllib commented May 19, 2026

Description

Wrap dd_baggage.items() and otel_baggage.items() with list() in get_current() and attach() to prevent RuntimeError: dictionary changed size during iteration when multiple threads concurrently read and mutate shared baggage dicts via OTel context propagation.

Closes #16523

Testing

added a test and verified that the tests pass

Risks

Adds an additional allocation in get_current and attach

Additional Notes

I made this PR with the assistance of AI, but have read it and think I understand it well enough to suggest it

@llimllib llimllib requested review from a team as code owners May 19, 2026 19:42
@llimllib llimllib requested review from brettlangdon and mabdinur May 19, 2026 19:42
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48199bc104

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/opentelemetry/test_context.py Outdated
Copy link
Copy Markdown
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

can you add a release note for this?

https://ddtrace.readthedocs.io/en/stable/releasenotes.html

@llimllib llimllib requested a review from a team as a code owner May 19, 2026 20:31
@llimllib llimllib requested a review from florentinl May 19, 2026 20:31
@datadog-official
Copy link
Copy Markdown
Contributor

datadog-official Bot commented May 20, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

System Tests | download-s3-wheels   View in Datadog   GitHub Actions

🔄 Retry job. This looks flaky and may succeed on retry. Timed out after 1800s waiting for https://dd-trace-py-builds.s3.amazonaws.com/676f3dbce48d938ae19d31cc30e4517bf5d63e13/index-manylinux2014_x86_64.html

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 676f3db | Docs | Datadog PR Page | Give us feedback!

@llimllib
Copy link
Copy Markdown
Author

llimllib commented May 20, 2026

DataDog/apm-reliability/dd-trace-py | os tests ubuntu: [3.10] View in Datadog GitLab
🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration.
Failed to fetch repository due to not signed and curl command not found during install attempts.

Is this due to something I did, or something in the CI process? I can't access the link

update: this may be because my commit was unverified? I set up verification and rebased with a signed commit

Wrap `dd_baggage.items()` and `otel_baggage.items()` with `list()` in
`get_current()` and `attach()` to prevent `RuntimeError: dictionary
changed size during iteration` when multiple threads concurrently read
and mutate shared baggage dicts via OTel context propagation.

Closes DataDog#16523
@llimllib
Copy link
Copy Markdown
Author

llimllib commented May 21, 2026

The commit is now signed:

$ git log --show-signature -1
commit 676f3dbce48d938ae19d31cc30e4517bf5d63e13 (HEAD -> main, origin/main, origin/HEAD)
Good "git" signature for bill.mill@jellyfish.co with ED25519 key SHA256:Syzy+NnUbX75eh+S705o8d8ZK8LbTZFkB/cjyI>
Author: Bill Mill <bill.mill@jellyfish.co>
Date:   Tue May 19 15:37:41 2026 -0400

and the links in the CI message don't work for me, they seem to be private pages. GitHub shows the commit as verified.

If you want to make the commit yourself because CI won't let me, I won't be offended

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.

[BUG]: RuntimeError: dictionary changed size during iteration in _get_metas_to_propagate

3 participants