Skip to content

Commit b8e7ef7

Browse files
committed
refactor debug mode
1 parent 705aa7e commit b8e7ef7

File tree

4 files changed

+22
-83
lines changed

4 files changed

+22
-83
lines changed

packages/signals/signals-integration-tests/src/helpers/base-page-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class BasePage {
7171
await this.page.evaluate(
7272
({ signalSettings }) => {
7373
window.signalsPlugin = new window.SignalsPlugin({
74-
disableSignalsRedaction: true,
74+
enableSignalsDebug: true,
7575
flushInterval: 1000,
7676
...signalSettings,
7777
})

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

Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ export type SignalsSettingsConfig = Pick<
1313
| 'functionHost'
1414
| 'flushAt'
1515
| 'flushInterval'
16-
| 'disableSignalsRedaction'
17-
| 'signalsIngestion'
18-
| 'sampleRate'
16+
| 'enableSignalsDebug'
1917
| 'networkSignalsAllowList'
2018
| 'networkSignalsDisallowList'
2119
| 'networkSignalsAllowSameDomain'
@@ -34,10 +32,9 @@ export class SignalGlobalSettings {
3432
signalBuffer: SignalBufferSettingsConfig
3533
ingestClient: SignalsIngestSettingsConfig
3634
network: NetworkSettingsConfig
37-
private sampleRate = 0
3835

39-
private redaction = new SignalRedactionSettings()
40-
private ingestion = new SignalIngestionSettings()
36+
private sampleRate = 0
37+
private signalsDebug = new SignalsDebugSettings()
4138

4239
constructor(settings: SignalsSettingsConfig) {
4340
if (settings.maxBufferSize && settings.signalStorage) {
@@ -46,9 +43,7 @@ export class SignalGlobalSettings {
4643
)
4744
}
4845

49-
this.redaction = new SignalRedactionSettings(
50-
settings.disableSignalsRedaction
51-
)
46+
this.signalsDebug = new SignalsDebugSettings(settings.enableSignalsDebug)
5247

5348
this.signalBuffer = {
5449
signalStorage: settings.signalStorage,
@@ -58,9 +53,9 @@ export class SignalGlobalSettings {
5853
apiHost: settings.apiHost,
5954
flushAt: settings.flushAt,
6055
flushInterval: settings.flushInterval,
61-
shouldDisableSignalRedaction: this.redaction.getDisableSignalRedaction,
56+
shouldDisableSignalRedaction: this.signalsDebug.getSignalsDebug,
6257
shouldIngestSignals: () => {
63-
if (this.ingestion.getSignalIngestion()) {
58+
if (this.signalsDebug.getSignalsDebug()) {
6459
return true
6560
}
6661
if (Math.random() > this.sampleRate) {
@@ -108,99 +103,43 @@ export class SignalGlobalSettings {
108103
}
109104
}
110105

111-
class SignalRedactionSettings {
112-
private static redactionKey = 'segment_signals_debug_redaction_disabled'
106+
class SignalsDebugSettings {
107+
private static key = 'segment_signals_debug'
113108
constructor(initialValue?: boolean) {
114109
if (typeof initialValue === 'boolean') {
115-
this.setDisableSignalRedaction(initialValue)
110+
this.setSignalsDebug(initialValue)
116111
}
117112

118-
// setting ?segment_signals_debug=true will disable redaction, and set a key in local storage
113+
// setting ?segment_signals_debug=true will disable redaction, enable ingestion, and set keys in local storage
119114
// this setting will persist across page loads (even if there is no query string)
120115
// in order to clear the setting, user must set ?segment_signals_debug=false
121116
const debugModeInQs = parseDebugModeQueryString()
122117
logger.debug('debugMode is set to true via query string')
123118
if (typeof debugModeInQs === 'boolean') {
124-
this.setDisableSignalRedaction(debugModeInQs)
119+
this.setSignalsDebug(debugModeInQs)
125120
}
126121
}
127122

128-
setDisableSignalRedaction(shouldDisable: boolean) {
123+
setSignalsDebug(shouldDisable: boolean) {
129124
try {
130125
if (shouldDisable) {
131-
window.sessionStorage.setItem(
132-
SignalRedactionSettings.redactionKey,
133-
'true'
134-
)
126+
window.sessionStorage.setItem(SignalsDebugSettings.key, 'true')
135127
} else {
136-
logger.debug('Removing redaction key from storage')
137-
window.sessionStorage.removeItem(SignalRedactionSettings.redactionKey)
128+
logger.debug('Removing debug key from storage')
129+
window.sessionStorage.removeItem(SignalsDebugSettings.key)
138130
}
139131
} catch (e) {
140132
logger.debug('Storage error', e)
141133
}
142134
}
143135

144-
getDisableSignalRedaction() {
136+
getSignalsDebug() {
145137
try {
146138
const isDisabled = Boolean(
147-
window.sessionStorage.getItem(SignalRedactionSettings.redactionKey)
139+
window.sessionStorage.getItem(SignalsDebugSettings.key)
148140
)
149141
if (isDisabled) {
150-
logger.debug(
151-
`${SignalRedactionSettings.redactionKey}=true (app. storage)`
152-
)
153-
return true
154-
}
155-
} catch (e) {
156-
logger.debug('Storage error', e)
157-
}
158-
return false
159-
}
160-
}
161-
162-
class SignalIngestionSettings {
163-
private static ingestionKey = 'segment_signals_debug_ingestion_enabled'
164-
constructor(initialValue?: boolean) {
165-
if (typeof initialValue === 'boolean') {
166-
this.setSignalIngestion(initialValue)
167-
}
168-
169-
// setting ?segment_signals_debug=true will disable redaction, and set a key in local storage
170-
// this setting will persist across page loads (even if there is no query string)
171-
// in order to clear the setting, user must set ?segment_signals_debug=false
172-
const debugModeInQs = parseDebugModeQueryString()
173-
logger.debug('debugMode is set to true via query string')
174-
if (typeof debugModeInQs === 'boolean') {
175-
this.setSignalIngestion(debugModeInQs)
176-
}
177-
}
178-
179-
setSignalIngestion(shouldEnable: boolean) {
180-
try {
181-
if (shouldEnable) {
182-
window.sessionStorage.setItem(
183-
SignalIngestionSettings.ingestionKey,
184-
'true'
185-
)
186-
} else {
187-
logger.debug('Removing ingestion key from storage')
188-
window.sessionStorage.removeItem(SignalIngestionSettings.ingestionKey)
189-
}
190-
} catch (e) {
191-
logger.debug('Storage error', e)
192-
}
193-
}
194-
195-
getSignalIngestion() {
196-
try {
197-
const isEnabled = Boolean(
198-
window.sessionStorage.getItem(SignalIngestionSettings.ingestionKey)
199-
)
200-
if (isEnabled) {
201-
logger.debug(
202-
`${SignalIngestionSettings.ingestionKey}=true (app. storage)`
203-
)
142+
logger.debug(`${SignalsDebugSettings.key}=true (app. storage)`)
204143
return true
205144
}
206145
} catch (e) {

packages/signals/signals/src/plugin/signals-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class SignalsPlugin implements Plugin, SignalsAugmentedFunctionality {
3434
logger.debug('SignalsPlugin initializing', { settings })
3535

3636
this.signals = new Signals({
37-
disableSignalsRedaction: settings.disableSignalsRedaction,
37+
enableSignalsDebug: settings.enableSignalsDebug,
3838
flushAt: settings.flushAt,
3939
flushInterval: settings.flushInterval,
4040
functionHost: settings.functionHost,

packages/signals/signals/src/types/settings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export interface SignalsPluginSettingsConfig {
1818
enableDebugLogging?: boolean
1919

2020
/**
21-
* Disable redaction of signals
21+
* Enables signals debug mode (turns off redaction, enables ingestion)
2222
* @default false
2323
*/
24-
disableSignalsRedaction?: boolean
24+
enableSignalsDebug?: boolean
2525

2626
/**
2727
* If signals ingestion is enabled/disabled

0 commit comments

Comments
 (0)