Skip to content

♻️ introduce Logs plugin API and assemble hook enrichment - #5014

Open
BenoitZugmeyer wants to merge 4 commits into
mainfrom
benoit/logs-plugin
Open

♻️ introduce Logs plugin API and assemble hook enrichment#5014
BenoitZugmeyer wants to merge 4 commits into
mainfrom
benoit/logs-plugin

Conversation

@BenoitZugmeyer

@BenoitZugmeyer BenoitZugmeyer commented Sep 4, 2026

Copy link
Copy Markdown
Member

Motivation

This PR introduces plugin-related changes required for creating a wasm plugin, started in #4920. I am opening my own PR for platform work, so #4920 can focus on the wasm plugin itself.

The Browser SDK did not let third-party code enrich or override events before they are sent to Datadog. This makes it impossible for plugins (e.g. a WebAssembly symbolication plugin) to attach metadata such as source_type or loaded module build IDs to error events, which downstream tooling needs to symbolicate WASM stack traces.

This PR introduces an experimental plugin API on the Logs SDK and extends the existing RUM plugin API so plugins can register assemble callbacks that read the raw event and return enrichments or overrides.

Changes

  • Logs plugin API: add the LogsPlugin interface (name, getConfigurationTelemetry, onInit, onLogsStart), a plugins configuration option with schema + telemetry serialization, and the callPluginsMethod helper. Wire onInit and onLogsStart in the public API.
  • Assemble hook enrichment (Logs): expose rawLogsEvent and domainContext to the assemble hook so plugins can read the raw event and return enrichments.
  • Two-hook split (Logs & RUM): split the single assemble hook into assembleEventDefaults (provides default attributes, existing behavior) and assembleEvent (provides attributes that take precedence over the raw event). The override result is merged after the raw event in the combine order, so plugins can override fields such as error.source_type without ad-hoc mergeInto workarounds.
  • Plugin hook exposure (Logs & RUM): expose registerAssembleEventHook on the onInit options so plugins can register override callbacks. Only the register function is exposed, not the full hook, keeping the API minimal.

The plugins API is unstable and experimental, and may change without notice.

Test instructions

  • Start the dev server (yarn dev) and open the sandbox at http://localhost:8080.
  • Register a plugin in DD_LOGS.init / DD_RUM.init that uses the onInit registerAssembleEventHook callback to override an error field (e.g. set error.fingerprint).
  • Trigger an error (e.g. setTimeout(() => { throw new Error('boom') })) and flush events.
  • In the intake registry / network tab, verify the assembled event carries the overridden field while the rest of the raw event is preserved.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@BenoitZugmeyer BenoitZugmeyer changed the title ✨ introduce Logs plugin API and assemble hook enrichment ♻️ introduce Logs plugin API and assemble hook enrichment Sep 4, 2026
@BenoitZugmeyer
BenoitZugmeyer marked this pull request as ready for review September 4, 2026 08:03
@BenoitZugmeyer
BenoitZugmeyer requested a review from a team as a code owner September 4, 2026 08:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T14:47:56.339804Z 9240f39 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 4, 2026

Copy link
Copy Markdown

Tests

All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 81.82%
Overall Coverage: 76.99% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9240f39 | Docs | View more details | Give us feedback!

@BenoitZugmeyer BenoitZugmeyer changed the title ♻️ introduce Logs plugin API and assemble hook enrichment ♻️ introduce Logs plugin API and assemble hook enrichment Sep 4, 2026

@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: e58976b0ac

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

Comment thread packages/browser-logs/src/domain/plugins.ts
Comment thread packages/browser-logs/src/entries/main.ts Outdated
Comment thread packages/browser-logs/src/domain/hooks.ts Outdated
Comment thread packages/browser-logs/src/boot/preStartLogs.ts
Comment thread packages/browser-rum-core/src/boot/preStartRum.ts
Comment thread packages/browser-rum-core/src/domain/hooks.ts
Comment thread packages/browser-logs/src/boot/preStartLogs.ts
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 4, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 182.02 KiB 182.24 KiB +225 B +0.12%
Rum Profiler 8.43 KiB 8.43 KiB 0 B 0.00%
Rum Recorder 25.32 KiB 25.32 KiB 0 B 0.00%
Logs 57.96 KiB 58.71 KiB +773 B +1.30%
Rum Salesforce N/A 140.28 KiB N/A N/A N/A
Rum Slim 140.08 KiB 140.27 KiB +202 B +0.14%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%
Rum Shopify N/A 207.04 KiB N/A N/A N/A
Rum-shopify Profiler N/A 8.43 KiB N/A N/A N/A
Rum-shopify Recorder N/A 3.74 KiB N/A N/A N/A

@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: 15886e85dd

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

Comment thread packages/browser-logs/src/boot/preStartLogs.ts
Comment thread packages/browser-logs/src/domain/assembly.ts
Comment thread packages/browser-logs/src/domain/assembly.ts Outdated
Comment thread packages/browser-logs/src/domain/plugins.ts

@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: a72e2c9df9

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

Comment thread packages/browser-logs/src/domain/configuration.ts

@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: 9a15b5709c

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

Comment thread packages/browser-rum-core/src/domain/assembly.ts Outdated
Comment thread packages/browser-rum-core/src/domain/plugins.ts Outdated

@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: bd585658a0

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

Comment thread packages/browser-logs/src/domain/plugins.ts
Comment thread packages/browser-logs/src/domain/hooks.ts Outdated
Apply the same two-hook split to the RUM SDK:
- assembleEventDefaults: provides default attributes (existing behavior)
- assembleEvent: provides attributes that take precedence over the raw
  event, so plugins can override fields such as error.source_type

The override hook result is merged after the raw RUM event in the combine
order, letting plugins enrich/override fields without workarounds.
@BenoitZugmeyer
BenoitZugmeyer force-pushed the benoit/logs-plugin branch 2 times, most recently from ad2d986 to 1a3e7a3 Compare September 4, 2026 13:31

@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

export type AssembleHook = Hook<AssembleHookParams, DefaultRumEventAttributes>

P2 Badge Let RUM enrichment callbacks omit the event type

issue: registerAssembleEventHook is advertised for returning partial enrichments, but reusing DefaultRumEventAttributes makes type mandatory in every callback result. Under strictNullChecks, a plugin returning only { error: { fingerprint: ... } } or { context: ... } is rejected even though the assembly code already preserves the raw event's type; use a separate recursive-partial result type for the override hook so plugins need not redundantly return eventType.

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

Comment thread packages/browser-logs/src/domain/plugins.ts Outdated

@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: 1e4905196a

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

Comment thread packages/browser-rum-core/src/domain/plugins.ts Outdated
Comment thread packages/browser-logs/src/boot/preStartLogs.ts
Comment thread packages/browser-rum-core/src/domain/assembly.ts

@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: 765b37b9e3

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

Comment thread packages/browser-rum-core/src/domain/plugins.ts
Comment thread packages/browser-rum-core/src/domain/assembly.ts
Pass the assembleEvent hook register function to plugins' onInit
callback as registerAssembleEventHook, so plugins can register callbacks
to override RUM event fields before they are sent. Mirrors the Logs SDK
plugin API.
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.

1 participant