-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathdefaults.js
More file actions
177 lines (166 loc) · 4.83 KB
/
defaults.js
File metadata and controls
177 lines (166 loc) · 4.83 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
'use strict'
const pkg = require('../pkg')
const { isFalse, isTrue } = require('../util')
const { DD_MAJOR } = require('../../../../version')
const { getEnvironmentVariable: getEnv } = require('./helper')
const {
supportedConfigurations,
} = /** @type {import('./helper').SupportedConfigurationsJson} */ (require('./supported-configurations.json'))
const service = getEnv('AWS_LAMBDA_FUNCTION_NAME') ||
getEnv('FUNCTION_NAME') || // Google Cloud Function Name set by deprecated runtimes
getEnv('K_SERVICE') || // Google Cloud Function Name set by newer runtimes
getEnv('WEBSITE_SITE_NAME') || // set by Azure Functions
pkg.name ||
'node'
/**
* @param {string|null} raw
* @param {string} type
* @returns {string|number|boolean|Record<string, string>|unknown[]|undefined}
*/
function parseDefaultByType (raw, type) {
if (raw === null) {
return
}
switch (type) {
case 'boolean':
if (isTrue(raw)) return true
if (isFalse(raw)) return false
// TODO: What should we do with these?
return
case 'int':
case 'decimal': {
return Number(raw)
}
case 'array': {
if (!raw || raw.length === 0) return []
// TODO: Make the parsing a helper that is reused.
return raw.split(',').map(item => {
const colonIndex = item.indexOf(':')
if (colonIndex === -1) {
return item.trim()
}
const key = item.slice(0, colonIndex).trim()
const value = item.slice(colonIndex + 1).trim()
return `${key}:${value}`
})
}
case 'map': {
if (!raw || raw.length === 0) return {}
// TODO: Make the parsing a helper that is reused.
/** @type {Record<string, string>} */
const entries = {}
for (const item of raw.split(',')) {
const colonIndex = item.indexOf(':')
if (colonIndex === -1) {
const key = item.trim()
if (key.length > 0) {
entries[key] = ''
}
continue
}
const key = item.slice(0, colonIndex).trim()
const value = item.slice(colonIndex + 1).trim()
if (key.length > 0) {
entries[key] = value
}
}
return entries
}
default:
return raw
}
}
/** @type {Record<string, unknown>} */
const metadataDefaults = {}
for (const entries of Object.values(supportedConfigurations)) {
for (const entry of entries) {
// TODO: Replace $dynamic with method names that would be called and that
// are also called when the user passes through the value. That way the
// handling is unified and methods can be declared as default.
// The name of that method should be expressive for users.
// TODO: Add handling for all environment variable names. They should not
// need a configuration name for being listed with their default.
if (!Array.isArray(entry.configurationNames)) {
continue
}
const parsedValue = parseDefaultByType(entry.default, entry.type)
for (const configurationName of entry.configurationNames) {
metadataDefaults[configurationName] = entry.default === null ? undefined : parsedValue
}
}
}
// Defaults required by JS config merge/applyCalculated that are not represented in supported-configurations.
const defaultsWithoutSupportedConfigurationEntry = {
'cloudPayloadTagging.rules': [],
'cloudPayloadTagging.requestsEnabled': false,
'cloudPayloadTagging.responsesEnabled': false,
isAzureFunction: false,
isCiVisibility: false,
isGCPFunction: false,
instrumentationSource: 'manual',
isServiceUserProvided: false,
isServiceNameInferred: true,
lookup: undefined,
plugins: true,
}
// These values are documented in supported-configurations as CI Visibility
// defaults. Keep startup baseline false and let #applyCalculated() switch them
// when CI Visibility is active.
// TODO: These entries should be removed. They are off by default
// because they rely on other configs.
const defaultsWithConditionalRuntimeBehavior = {
startupLogs: DD_MAJOR >= 6,
isGitUploadEnabled: false,
isImpactedTestsEnabled: false,
isIntelligentTestRunnerEnabled: false,
isManualApiEnabled: false,
isTestManagementEnabled: false,
// TODO: These are not conditional, they would just be of type number.
'dogstatsd.port': '8125',
port: '8126',
// Override due to expecting numbers, not strings. TODO: Replace later.
'grpc.client.error.statuses': [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
],
'grpc.server.error.statuses': [
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
],
}
/** @type {Record<string, unknown>} */
const defaults = {
...defaultsWithoutSupportedConfigurationEntry,
...metadataDefaults,
...defaultsWithConditionalRuntimeBehavior,
service,
version: pkg.version,
}
module.exports = defaults