Skip to content

Commit 9f5ca17

Browse files
committed
wip
1 parent 48e8703 commit 9f5ca17

File tree

5 files changed

+35
-30
lines changed

5 files changed

+35
-30
lines changed

packages/signals/signals/src/core/emitter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class SignalEmitter implements EmitSignal {
1010
private emitter = new Emitter<{ add: [Signal] }>()
1111

1212
emit(signal: Signal) {
13-
logger.debug('new signal emitted', signal)
13+
logger.debug('New signal:', signal.type, signal.data)
1414
this.emitter.emit('add', signal)
1515
}
1616

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ export class SignalsDebugSettings {
130130
}
131131
}
132132

133-
setAllDebugging(boolean: boolean) {
133+
setAllDebugging = (boolean: boolean) => {
134134
this.setDebugKey(SignalsDebugSettings.redactionKey, boolean)
135135
this.setDebugKey(SignalsDebugSettings.ingestionKey, boolean)
136136
}
137137

138-
private setDebugKey(key: string, enable: boolean) {
138+
private setDebugKey = (key: string, enable: boolean): void => {
139139
try {
140140
if (enable) {
141141
window[this.storageType].setItem(key, 'true')
@@ -148,7 +148,7 @@ export class SignalsDebugSettings {
148148
}
149149
}
150150

151-
private getDebugKey(key: string): boolean {
151+
private getDebugKey = (key: string): boolean => {
152152
try {
153153
const isEnabled = Boolean(window[this.storageType].getItem(key))
154154
if (isEnabled) {
@@ -161,11 +161,11 @@ export class SignalsDebugSettings {
161161
return false
162162
}
163163

164-
getDisableSignalsRedaction(): boolean {
164+
getDisableSignalsRedaction = (): boolean => {
165165
return this.getDebugKey(SignalsDebugSettings.redactionKey)
166166
}
167167

168-
getEnableSignalsIngestion(): boolean {
168+
getEnableSignalsIngestion = (): boolean => {
169169
return this.getDebugKey(SignalsDebugSettings.ingestionKey)
170170
}
171171
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,18 @@ export class Signals implements ISignals {
129129
void this.buffer.clear()
130130
}
131131

132-
debug({ logSignalsOnly = false } = {}): void {
132+
/**
133+
* Disable redaction and enable ingestion of signals.
134+
*/
135+
debug(): void {
133136
this.globalSettings.signalsDebug.setAllDebugging(true)
134-
if (logSignalsOnly) {
135-
this.signalEmitter.subscribe((signal) => {
136-
console.log('[signals debug]', signal.type, signal.data, {
137-
buffer: this.buffer,
138-
})
139-
})
140-
} else {
141-
logger.enableDebugLogging()
142-
}
137+
}
138+
139+
/**
140+
* Log signals to the console.
141+
*/
142+
enableDebugLogging(): void {
143+
this.enableDebugLogging()
143144
}
144145

145146
/**

packages/signals/signals/src/lib/logger/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
import { parseDebugLoggingQueryString } from '../../core/debug-mode'
22

33
class Logger {
4-
private static loggingKey = 'segment_signals_debug_logging_enabled'
4+
private storageType = 'sessionStorage' as const
5+
private static loggingKey = 'segment_signals_debug_logging'
6+
public signalsOnly = false
57
constructor() {
68
const val = parseDebugLoggingQueryString()
79
if (typeof val === 'boolean') {
810
this.setDebugKey(Logger.loggingKey, val)
911
}
1012
}
1113

12-
private debugLoggingEnabled(): boolean {
14+
private debugLoggingEnabled = (): boolean => {
1315
try {
1416
const isEnabled = Boolean(
15-
window.sessionStorage.getItem(Logger.loggingKey)
17+
globalThis[this.storageType].getItem(Logger.loggingKey)
1618
)
1719
if (isEnabled) {
1820
return true
1921
}
2022
} catch (e) {
21-
logger.debug('Storage error', e)
23+
console.warn('Storage error', e)
2224
}
2325
return false
2426
}
2527

26-
private setDebugKey(key: string, enable: boolean) {
28+
private setDebugKey = (key: string, enable: boolean) => {
2729
try {
2830
if (enable) {
29-
window.sessionStorage.setItem(key, 'true')
31+
globalThis[this.storageType].setItem(key, 'true')
3032
} else {
31-
logger.debug(`Removing debug key ${key} from storage`)
32-
window.sessionStorage.removeItem(key)
33+
globalThis[this.storageType].removeItem(key)
3334
}
3435
} catch (e) {
35-
logger.debug('Storage error', e)
36+
console.warn('Storage error', e)
3637
}
3738
}
3839

39-
enableDebugLogging(bool = true) {
40+
enableDebugLogging = (bool = true) => {
4041
this.setDebugKey(Logger.loggingKey, bool)
4142
}
4243

43-
debug(...args: any[]): void {
44+
debug = (...args: any[]): void => {
4445
if (this.debugLoggingEnabled()) {
4546
console.log('[signals debug]', ...args)
4647
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Plugin } from '@segment/analytics-next'
2-
import { Signals, SignalsDebugSettings } from '../core/signals'
2+
import { Signals } from '../core/signals'
33
import { logger } from '../lib/logger'
44
import { AnyAnalytics, SignalsPluginSettingsConfig } from '../types'
55
import { Signal } from '@segment/analytics-signals-runtime'
@@ -86,7 +86,10 @@ export class SignalsPlugin implements Plugin, SignalsAugmentedFunctionality {
8686
return this
8787
}
8888

89-
debug(enable = true) {
90-
this.signals.debug(enable)
89+
/**
90+
* Turn on debug logging for signals
91+
*/
92+
debug() {
93+
this.signals.debug()
9194
}
9295
}

0 commit comments

Comments
 (0)