Skip to content

Commit b4d35a4

Browse files
committed
use sample rate
1 parent 58ca71a commit b4d35a4

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

packages/browser/src/browser/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ export interface CDNSettings {
122122
version: number
123123
}
124124
| {}
125+
/**
126+
* Settings for auto instrumentation
127+
*/
128+
autoInstrumentationSettings?: {
129+
/**
130+
* A sample rate to determine what percentage of sessions should send signals, from [0,1]
131+
*/
132+
sampleRate: number
133+
}
125134
}
126135

127136
export interface AnalyticsBrowserSettings {

packages/signals/signals/src/core/signals/signals.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ export class Signals implements ISignals {
8383
* - Registers custom signal generators.
8484
*/
8585
async start(analytics: AnyAnalytics): Promise<void> {
86+
if (
87+
!analytics.settings.cdnSettings.autoInstrumentationSettings ||
88+
Math.random() >
89+
analytics.settings.cdnSettings.autoInstrumentationSettings.sampleRate
90+
)
91+
return
8692
const analyticsService = new AnalyticsService(analytics)
8793

8894
this.globalSettings.update({

packages/signals/signals/src/types/analytics-api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type EdgeFnCDNSettings = {
99
}
1010

1111
export interface CDNSettings {
12+
autoInstrumentationSettings?: CDNSettingsAutoInstrumentation
1213
integrations: CDNSettingsIntegrations
1314
edgeFunction?: EdgeFnCDNSettings | { [key: string]: never }
1415
}
@@ -72,6 +73,10 @@ export interface CDNSettingsIntegrations {
7273
[integrationName: string]: { [key: string]: any }
7374
}
7475

76+
export interface CDNSettingsAutoInstrumentation {
77+
sampleRate: number
78+
}
79+
7580
export type PluginType = 'before' | 'after' | 'destination'
7681

7782
export interface Plugin<Analytics = AnyAnalytics, Ctx = Record<string, any>> {

0 commit comments

Comments
 (0)