-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathexperimentalFeatures.ts
More file actions
58 lines (50 loc) · 2.06 KB
/
experimentalFeatures.ts
File metadata and controls
58 lines (50 loc) · 2.06 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
56
57
58
/**
* LIMITATION:
* For NPM setup, this feature flag singleton is shared between RUM and Logs product.
* This means that an experimental flag set on the RUM product will be set on the Logs product.
* So keep in mind that in certain configurations, your experimental feature flag may affect other products.
*
* FORMAT:
* All feature flags should be snake_cased
*/
// We want to use a real enum (i.e. not a const enum) here, to be able to check whether an arbitrary
// string is an expected feature flag
import { objectHasValue } from './utils/objectUtils'
// eslint-disable-next-line no-restricted-syntax
export enum ExperimentalFeature {
TRACK_INTAKE_REQUESTS = 'track_intake_requests',
USE_TREE_WALKER_FOR_ACTION_NAME = 'use_tree_walker_for_action_name',
FEATURE_OPERATION_VITAL = 'feature_operation_vital',
SHORT_SESSION_INVESTIGATION = 'short_session_investigation',
START_STOP_ACTION = 'start_stop_action',
START_STOP_RESOURCE = 'start_stop_resource',
USE_CHANGE_RECORDS = 'use_change_records',
SOURCE_CODE_CONTEXT = 'source_code_context',
LCP_SUBPARTS = 'lcp_subparts',
INP_SUBPARTS = 'inp_subparts',
COMPOSED_PATH_SELECTOR = 'composed_path_selector',
}
const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()
export function initFeatureFlags(enableExperimentalFeatures: string[] | undefined) {
if (Array.isArray(enableExperimentalFeatures)) {
addExperimentalFeatures(
enableExperimentalFeatures.filter((flag): flag is ExperimentalFeature =>
objectHasValue(ExperimentalFeature, flag)
)
)
}
}
export function addExperimentalFeatures(enabledFeatures: ExperimentalFeature[]): void {
enabledFeatures.forEach((flag) => {
enabledExperimentalFeatures.add(flag)
})
}
export function isExperimentalFeatureEnabled(featureName: ExperimentalFeature): boolean {
return enabledExperimentalFeatures.has(featureName)
}
export function resetExperimentalFeatures(): void {
enabledExperimentalFeatures.clear()
}
export function getExperimentalFeatures(): Set<ExperimentalFeature> {
return enabledExperimentalFeatures
}