Skip to content

Cache global fields in LogsAgent#166

Merged
kikoveiga merged 2 commits into
developfrom
kikoveiga/cache-global-fields-logsagent
May 29, 2026
Merged

Cache global fields in LogsAgent#166
kikoveiga merged 2 commits into
developfrom
kikoveiga/cache-global-fields-logsagent

Conversation

@kikoveiga

@kikoveiga kikoveiga commented May 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Use observe and cache pattern on global fields in LogsAgent.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@datadog-official

This comment has been minimized.

@kikoveiga
kikoveiga marked this pull request as ready for review May 29, 2026 12:31
@kikoveiga
kikoveiga requested a review from a team as a code owner May 29, 2026 12:31
@kikoveiga
kikoveiga force-pushed the kikoveiga/cache-global-fields-logsagent branch from 34e6353 to 199d696 Compare May 29, 2026 12:33

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

Copy link
Copy Markdown

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: 34e63533d0

ℹ️ 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".

' 4. Cache the global context locally, kept in sync via observers
m.global.observeFieldScoped("datadogUserInfo", "onUserInfoChanged")
m.global.observeFieldScoped("datadogContext", "onContextChanged")
m.global.observeFieldScoped("datadogRumContext", "onRumContextChanged")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid observing the RUM context before it exists

When the first log is emitted immediately after initialize, LogsAgent.setupIfNeeded() can run before the RumAgent task has executed setup() and added datadogRumContext; initialize only adds datadogContext/datadogUserInfo synchronously, while datadogRumContext is added later from the RUM task. In that timing window this observer is not attached to a real field, so m.rumContext stays invalid and subsequent logs miss RUM correlation even after the RUM agent creates/updates the global context. Ensure the field is created synchronously before logs can initialize, or retry/register the observer once the field exists.

Useful? React with 👍 / 👎.

@kikoveiga kikoveiga May 29, 2026

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.

We now create the datadogRumContext synchronously in datadogSdk, wdyt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the review is a good call, and the workaround makes sense also

@kikoveiga
kikoveiga merged commit c4a30d8 into develop May 29, 2026
8 checks passed
@kikoveiga
kikoveiga deleted the kikoveiga/cache-global-fields-logsagent branch May 29, 2026 14:03
@kikoveiga kikoveiga self-assigned this May 29, 2026
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