Skip to content

Conversation

BeltranBulbarellaDD
Copy link
Contributor

@BeltranBulbarellaDD BeltranBulbarellaDD commented Jul 3, 2025

Motivation

The idea is to be able to inject the SDK on a page that does not have it. Injecting the local version and CDN version.

Changes

Added a Trial tab that allows to configure the SDK to be injected.
Screenshot 2025-07-17 at 10 40 02

If CDN injection is enabled, the setting's tab gets set to:
Event collection strategy: Requests and
Auto Flush as it is needed for CDN.
Screenshot 2025-07-17 at 10 32 57

I can note an issue which is that when I Disable event intake (do not send data to Datadog) for which I do:
{ beforeSend: () => false, }
For which the initial view gets created but no other information gets sent.

Test instructions

Injecting using local version:
https://github.com/user-attachments/assets/b63b6fc2-5901-4703-88d3-798d9ea4be49

Injecting CDN version:
https://github.com/user-attachments/assets/874df7c6-b921-40eb-b01d-84fbba7a2423

Testing Session Replay tab on CDN injection.
https://github.com/user-attachments/assets/edab2e73-f596-428f-b89b-29a8f6d21d23

Checklist

  • [X ] Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.

@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.15%. Comparing base (84c872f) to head (c600e3e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...nsion/src/panel/hooks/useEvents/eventCollection.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3671      +/-   ##
==========================================
- Coverage   92.19%   92.15%   -0.04%     
==========================================
  Files         331      331              
  Lines        8286     8288       +2     
  Branches     1867     1868       +1     
==========================================
- Hits         7639     7638       -1     
- Misses        647      650       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Copy link

cit-pr-commenter bot commented Jul 3, 2025

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum N/A 161.72 KiB N/A N/A N/A
Rum Recorder N/A 19.48 KiB N/A N/A N/A
Rum Profiler N/A 5.32 KiB N/A N/A N/A
Logs N/A 56.02 KiB N/A N/A N/A
Flagging N/A 944 B N/A N/A N/A
Rum Slim N/A 119.31 KiB N/A N/A N/A
Worker N/A 23.60 KiB N/A N/A N/A
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫 (%)
addglobalcontext N/A 0.0074 N/A
addaction N/A 0.0221 N/A
adderror N/A 0.0211 N/A
addtiming N/A 0.0069 N/A
startview N/A 0.0055 N/A
startstopsessionreplayrecording N/A 0.0011 N/A
logmessage N/A 0.0202 N/A
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
addglobalcontext N/A 25.71 KiB N/A
addaction N/A 45.91 KiB N/A
addtiming N/A 24.49 KiB N/A
adderror N/A 49.83 KiB N/A
startstopsessionreplayrecording N/A 23.83 KiB N/A
startview N/A 431.35 KiB N/A
logmessage N/A 99.54 KiB N/A

🔗 RealWorld

@BeltranBulbarellaDD BeltranBulbarellaDD force-pushed the beltran.bulbarella/RUM-8780 branch from 8a4b6c3 to 2d75031 Compare July 17, 2025 09:01
- **Request Interception**: override the current SDK bundle with local build, or ​​switch between `rum` and `rum-slim` bundles on any site that is using RUM SDK. (note: if the SDK is installed from NPM, this override might not work, as it is still in an experimental stage.)

- **Trial Mode**: Access SDK injection capabilities through the Trial tab. When enabled, you can configure and inject the Datadog Browser SDK into pages that don't have it. Configure your Application ID, Client Token, site, and other parameters to test SDK features on any website.
Copy link
Contributor

Choose a reason for hiding this comment

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

No action requested in this PR, but: "Request Interception" and "Trial Mode" feel like they have a bit of overlap, since they both involve injection. I don't think it's necessary to change things in this PR, because handling it cleanly would probably require changes to the some of the wording in the extension UI, but it'd be nice to rename things a bit to clarify when you would use each feature. It feels like "Request Interception" is really "SDK Version Swapping", or something like that.

Edit: actually, looking at the settings panel changes, I'm starting to think that maybe we should address this issue in this PR. We may want to outright remove existing features that are duplicated by Trial Mode, so that there's a single clear place to accomplish each task.

chrome.storage.local.get(null, (allSettings) => {
sendResponse({ settings: allSettings })
})
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: IMO it'd be nicer to return a Promise, which AFAIK is also supported. I had to look up what return true mean to understand what was happening here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Promise returned in function argument where a void return was expected @typescript-eslint/no-misused-promises

So I am having issues returning a Promise. I could eslint-ignore it.


export interface SdkInjectionConfig {
enabled: boolean
sdkTypes: Array<'rum' | 'logs'>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe Record<'rum' | 'logs', boolean> would be a bit nicer.

`if (!scriptUrl) scriptUrl = ${JSON.stringify(url)};`
)
// Fallback – if the above pattern did not match (future wording change), explicitly set the
// webpack public path at the very top of the bundle so chunk loading keeps working.
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is reliable, heck, we could just get rid of the old method!

<>
<Space h="lg" />
<Text size="lg" fw={600}>
SDK Injection Configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a bit confusing that we're using the term "injection" both here and as one of the override strategies on the other page, and that one prevents you from using the other, even though they're very nearly the same thing. I think this ties back to the concern I had that the two features are confusingly similar in the docs, but I think the issue is even more visible when looking at how the different settings panels interact.

Perhaps we should just get rid of the override stuff that's duplicated by Trial Mode?

}
// intake request path is /api/vX/track
if (!['rum', 'logs'].includes(url.pathname.split('/')[3])) {
// Accept various intake path formats: older /api/vX/track, newer /v1/input, or anything containing /rum or /logs.
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like you are low-key fixing a bunch of existing bugs here, in addition to implementing Trial Mode. 😄

function setSetting<Name extends keyof Settings>(name: Name, value: Settings[Name]) {
settings![name] = value

// Special case: keep bundleSource and sdkInjection.bundleSource in sync
Copy link
Contributor

Choose a reason for hiding this comment

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

Another indication that we might want to consolidate things.

@BeltranBulbarellaDD BeltranBulbarellaDD changed the title added trial tab that injects the SDK ✨add trial tab that injects the SDK Jul 21, 2025
@BeltranBulbarellaDD BeltranBulbarellaDD changed the title ✨add trial tab that injects the SDK ✨[RUM-8780]add trial tab that injects the SDK Jul 21, 2025
@BeltranBulbarellaDD BeltranBulbarellaDD changed the title ✨[RUM-8780]add trial tab that injects the SDK ✨ [RUM-8780] Make developer extension capable of injecting the browser SDK Jul 21, 2025
@datadog-datadog-prod-us1
Copy link

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage
Patch Coverage: 0.00%
Total Coverage: 92.48% (-0.03%)

View detailed report

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 364a2ff | Docs | Was this helpful? Give us feedback!

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