-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathindex.ts
More file actions
55 lines (48 loc) · 2.03 KB
/
Copy pathindex.ts
File metadata and controls
55 lines (48 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Telemetry Provider - OSS Build Safety
*
* CRITICAL: OSS Build Safety
* This module is conditionally compiled based on distribution. When building
* the open source version (DISTRIBUTION unset), this entire module and its dependencies
* are excluded through via tree-shaking.
*
* To verify OSS builds exclude this code:
* 1. `DISTRIBUTION= pnpm build` (OSS build)
* 2. `grep -RinE --include='*.js' 'trackWorkflow|trackEvent|mixpanel' dist/` (should find nothing)
* 3. Check dist/assets/*.js files contain no tracking code
*
* This approach maintains complete separation between cloud and OSS builds
* while ensuring the open source version contains no telemetry dependencies.
*/
import { isCloud } from '@/platform/distribution/types'
import { CloudAnalyticsProvider } from './providers/cloud/CloudAnalyticsProvider'
import { MixpanelTelemetryProvider } from './providers/cloud/MixpanelTelemetryProvider'
import { TelemetryService } from './services/TelemetryService'
// Singleton instance
let _telemetryService: TelemetryService | null = null
/**
* Telemetry service factory - conditionally creates service with providers based on distribution
* Returns singleton instance.
*
* CRITICAL: This returns null in OSS builds. There is no telemetry service
* for OSS builds and all tracking calls are no-ops.
*/
export function useTelemetry(): TelemetryService | null {
if (_telemetryService === null) {
// Use distribution check for tree-shaking
if (isCloud) {
_telemetryService = new TelemetryService()
// Initialize and add both analytics providers
const mixpanelProvider = new MixpanelTelemetryProvider()
const cloudAnalyticsProvider = new CloudAnalyticsProvider()
void mixpanelProvider.initialize().then(() => {
_telemetryService?.addProvider(mixpanelProvider)
})
void cloudAnalyticsProvider.initialize().then(() => {
_telemetryService?.addProvider(cloudAnalyticsProvider)
})
}
// For OSS builds, _telemetryService stays null
}
return _telemetryService
}