Skip to content

Commit d181f51

Browse files
Integrate congyao/use-treewalker-for-action-name (#3972) into staging-09
Integrated commit sha: 77d6150 Co-authored-by: BenoitZugmeyer <benoit.zugmeyer@datadoghq.com>
2 parents fa99c8e + 77d6150 commit d181f51

File tree

71 files changed

+1609
-1730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1609
-1730
lines changed

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ scripts/ # Build, deploy, release automation
7676
- Test framework: Jasmine + Karma. Spec files co-located with implementation: `feature.ts``feature.spec.ts`
7777
- Focus tests with `fit()` / `fdescribe()`, skip with `xit()` / `xdescribe()`
7878
- Use `registerCleanupTask()` for cleanup, NOT `afterEach()`
79+
- Prefer `collectAsyncCalls(spy, n)` over `waitFor(() => spy.calls.count() > 0)` for waiting on spy calls
80+
- Don't destructure methods from `spy.calls` (e.g., `argsFor`, `mostRecent`) - use `calls.argsFor()` to avoid `@typescript-eslint/unbound-method` errors
7981
- Mock values/functions: wrap with `mockable()` in source, use `replaceMockable()` or `replaceMockableWithSpy()` in tests (auto-cleanup)
8082

8183
### Naming Conventions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
1919
---
2020

21+
## v7.0.0-alpha.0
22+
23+
**Internal Changes:**
24+
25+
- 👷 bump all packages to version to v7.0.0-alpha.0
26+
2127
## v6.27.1
2228

2329
**Public Changes:**

developer-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@datadog/browser-sdk-developer-extension",
3-
"version": "6.27.1",
3+
"version": "7.0.0-alpha.0",
44
"private": true,
55
"scripts": {
66
"build": "wxt build",

developer-extension/src/content-scripts/main.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,11 @@ function loadSdkScriptFromURL(url: string) {
175175
if (xhr.status === 200) {
176176
let sdkCode = xhr.responseText
177177

178-
// Webpack expects the script to be loaded with a `<script src="...">` tag to get its URL to
179-
// know where to load the relative chunks. By loading it with an XHR and evaluating it in an
180-
// inline script tag, Webpack does not know where to load the chunks from.
181-
//
182-
// Let's replace Webpack logic that breaks with our own logic to define the URL. It's not
183-
// pretty, but loading the script this way isn't either, so...
184-
//
185-
// We'll probably have to revisit when using actual `import()` expressions instead of relying on
186-
// Webpack runtime to load the chunks.
187-
sdkCode = sdkCode.replace(
188-
'if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");',
189-
`if (!scriptUrl) scriptUrl = ${JSON.stringify(url)};`
190-
)
178+
// Webpack chunks are loaded via ESM dynamic imports with relative paths (e.g. `import('./chunks/...')`).
179+
// Since this script is injected inline rather than loaded via `<script src>`, relative import()
180+
// paths would resolve against the page URL instead of the SDK URL. Replace them with absolute URLs.
181+
const baseUrl = url.slice(0, url.lastIndexOf('/') + 1)
182+
sdkCode = sdkCode.replaceAll(/\bimport\(['"]\.\/['"]/g, `import('${baseUrl}'`)
191183

192184
const script = document.createElement('script')
193185
script.type = 'text/javascript'

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"npmClient": "yarn",
3-
"version": "6.27.1"
3+
"version": "7.0.0-alpha.0"
44
}

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@datadog/browser-core",
3-
"version": "6.27.1",
3+
"version": "7.0.0-alpha.0",
44
"license": "Apache-2.0",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",

packages/core/src/domain/configuration/configuration.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { SessionPersistence } from '../session/sessionConstants'
1010
import type { MatchOption } from '../../tools/matchOption'
1111
import { isAllowedTrackingOrigins } from '../allowedTrackingOrigins'
1212
import type { Site } from '../intakeSites'
13-
import { isWorkerEnvironment } from '../../tools/globalObject'
1413
import type { TransportConfiguration } from './transportConfiguration'
1514
import { computeTransportConfiguration } from './transportConfiguration'
1615

@@ -216,15 +215,6 @@ export interface InitConfiguration {
216215
*/
217216
trackAnonymousUser?: boolean | undefined
218217

219-
/**
220-
* Encode cookie options in the cookie value. This can be used as a mitigation for microssession issues.
221-
* ⚠️ This is a beta feature and may be changed or removed in the future.
222-
*
223-
* @category Beta
224-
* @defaultValue false
225-
*/
226-
betaEncodeCookieOptions?: boolean | undefined
227-
228218
// internal options
229219
/**
230220
* [Internal option] Enable experimental features
@@ -327,7 +317,6 @@ export interface Configuration extends TransportConfiguration {
327317
trackingConsent: TrackingConsent
328318
storeContextsAcrossPages: boolean
329319
trackAnonymousUser?: boolean
330-
betaEncodeCookieOptions: boolean
331320

332321
// internal
333322
sdkVersion: string | undefined
@@ -401,7 +390,7 @@ export function validateAndBuildConfiguration(
401390
return {
402391
beforeSend:
403392
initConfiguration.beforeSend && catchUserErrors(initConfiguration.beforeSend, 'beforeSend threw an error:'),
404-
sessionStoreStrategyType: isWorkerEnvironment ? undefined : selectSessionStoreStrategyType(initConfiguration),
393+
sessionStoreStrategyType: selectSessionStoreStrategyType(initConfiguration),
405394
sessionSampleRate: initConfiguration.sessionSampleRate ?? 100,
406395
telemetrySampleRate: initConfiguration.telemetrySampleRate ?? 20,
407396
telemetryConfigurationSampleRate: initConfiguration.telemetryConfigurationSampleRate ?? 5,
@@ -415,7 +404,6 @@ export function validateAndBuildConfiguration(
415404
trackingConsent: initConfiguration.trackingConsent ?? TrackingConsent.GRANTED,
416405
trackAnonymousUser: initConfiguration.trackAnonymousUser ?? true,
417406
storeContextsAcrossPages: !!initConfiguration.storeContextsAcrossPages,
418-
betaEncodeCookieOptions: !!initConfiguration.betaEncodeCookieOptions,
419407

420408
/**
421409
* The source of the SDK, used for support plugins purposes.
@@ -448,7 +436,6 @@ export function serializeConfiguration(initConfiguration: InitConfiguration) {
448436
allow_untrusted_events: !!initConfiguration.allowUntrustedEvents,
449437
tracking_consent: initConfiguration.trackingConsent,
450438
use_allowed_tracking_origins: Array.isArray(initConfiguration.allowedTrackingOrigins),
451-
beta_encode_cookie_options: initConfiguration.betaEncodeCookieOptions,
452439
source: initConfiguration.source,
453440
sdk_version: initConfiguration.sdkVersion,
454441
variant: initConfiguration.variant,

packages/core/src/domain/contexts/userContext.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('user context', () => {
1616
findTrackedSession: () =>
1717
({
1818
anonymousId: 'device-123',
19-
}) as SessionContext<string>,
19+
}) as SessionContext,
2020
}
2121

2222
beforeEach(() => {

packages/rum-core/src/domain/sampler/sampler.spec.ts renamed to packages/core/src/domain/sampler.spec.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
import { isSampled, resetSampleDecisionCache, sampleUsingKnuthFactor } from './sampler'
2-
3-
// UUID known to yield a low hash value using the Knuth formula, making it more likely to be sampled
4-
const LOW_HASH_UUID = '29a4b5e3-9859-4290-99fa-4bc4a1a348b9'
5-
// UUID known to yield a high hash value using the Knuth formula, making it less likely to be
6-
// sampled
7-
const HIGH_HASH_UUID = '5321b54a-d6ec-4b24-996d-dd70c617e09a'
1+
import { HIGH_HASH_UUID, LOW_HASH_UUID } from '../../test'
2+
import { correctedChildSampleRate, isSampled, resetSampleDecisionCache, sampleUsingKnuthFactor } from './sampler'
83

94
// UUID chosen arbitrarily, to be used when the test doesn't actually depend on it.
105
const ARBITRARY_UUID = '1ff81c8c-6e32-473b-869b-55af08048323'
116

127
describe('isSampled', () => {
13-
beforeEach(() => {
14-
resetSampleDecisionCache()
15-
})
16-
178
it('returns true when sampleRate is 100', () => {
189
expect(isSampled(ARBITRARY_UUID, 100)).toBeTrue()
1910
})
@@ -75,6 +66,28 @@ describe('isSampled', () => {
7566
})
7667
})
7768

69+
describe('correctedChildSampleRate', () => {
70+
it('should apply the correction formula', () => {
71+
expect(correctedChildSampleRate(60, 20)).toBe(12)
72+
})
73+
74+
it('should return the child rate unchanged when parent is 100%', () => {
75+
expect(correctedChildSampleRate(100, 50)).toBe(50)
76+
})
77+
78+
it('should return 0 when child rate is 0', () => {
79+
expect(correctedChildSampleRate(60, 0)).toBe(0)
80+
})
81+
82+
it('should return 0 when parent rate is 0', () => {
83+
expect(correctedChildSampleRate(0, 50)).toBe(0)
84+
})
85+
86+
it('should return the parent rate when child rate is 100%', () => {
87+
expect(correctedChildSampleRate(60, 100)).toBe(60)
88+
})
89+
})
90+
7891
describe('sampleUsingKnuthFactor', () => {
7992
beforeEach(() => {
8093
if (!window.BigInt) {

packages/rum-core/src/domain/sampler/sampler.ts renamed to packages/core/src/domain/sampler.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { performDraw } from '@datadog/browser-core'
1+
import { performDraw } from '../tools/utils/numberUtils'
2+
3+
export function correctedChildSampleRate(parentRate: number, childRate: number): number {
4+
return (parentRate * childRate) / 100
5+
}
26

37
const sampleDecisionCache: Map<number, { sessionId: string; decision: boolean }> = new Map()
48

5-
export function isSampled(sessionId: string, sampleRate: number) {
9+
export function isSampled(sessionId: string, sampleRate: number): boolean {
610
// Shortcuts for common cases. This is not strictly necessary, but it makes the code faster for
711
// customers willing to ingest all traces.
812
if (sampleRate === 100) {
@@ -43,7 +47,7 @@ export function resetSampleDecisionCache() {
4347
* @param identifier - The identifier to use for sampling.
4448
* @param sampleRate - The sample rate in percentage between 0 and 100.
4549
*/
46-
export function sampleUsingKnuthFactor(identifier: bigint, sampleRate: number) {
50+
export function sampleUsingKnuthFactor(identifier: bigint, sampleRate: number): boolean {
4751
// The formula is:
4852
//
4953
// (identifier * knuthFactor) % 2^64 < sampleRate * 2^64

0 commit comments

Comments
 (0)