-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathstartup-log.js
More file actions
120 lines (105 loc) · 2.86 KB
/
startup-log.js
File metadata and controls
120 lines (105 loc) · 2.86 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
'use strict'
const os = require('os')
const { inspect } = require('util')
const tracerVersion = require('../../../package.json').version
const { getAgentUrl } = require('./agent/url')
const { warn } = require('./log/writer')
const errors = {}
let config
let pluginManager
/** @type {import('./sampling_rule')[]} */
let samplingRules = []
let startupLogRan = false
let agentErrorLogged = false
/**
* Logs the tracer configuration on startup
*/
function startupLog () {
if (startupLogRan || !config || !config.startupLogs || !pluginManager) {
return
}
startupLogRan = true
const out = tracerInfo()
warn('DATADOG TRACER CONFIGURATION - ' + out)
}
/**
* Logs a diagnostic error when the agent connection fails
* @param {{ status: number, message: string }} agentError
*/
function logAgentError (agentError) {
if (agentErrorLogged || !config || !config.startupLogs) {
return
}
agentErrorLogged = true
warn('DATADOG TRACER DIAGNOSTIC - Agent Error: ' + agentError.message)
errors.agentError = {
code: agentError.status,
message: `Agent Error: ${agentError.message}`,
}
}
/**
* @returns {Record<string, unknown>}
*/
function tracerInfo () {
const url = getAgentUrl(config)
const out = {
[inspect.custom] () {
return String(this)
},
toString () {
return JSON.stringify(this, (_key_, value) => {
return typeof value === 'bigint' || typeof value === 'symbol' ? String(value) : value
})
},
date: new Date().toISOString(),
os_name: os.type(),
os_version: os.release(),
architecture: os.arch(),
version: tracerVersion,
lang: 'nodejs',
lang_version: process.versions.node,
env: config.env,
enabled: config.enabled,
service: config.service,
agent_url: url,
debug: !!config.debug,
sample_rate: config.sampler.sampleRate,
sampling_rules: samplingRules,
tags: config.tags,
...(config.tags && config.tags.version && { dd_version: config.tags.version }),
log_injection_enabled: !!config.logInjection,
runtime_metrics_enabled: !!config.runtimeMetrics,
profiling_enabled: config.profiling?.enabled === 'true' || config.profiling?.enabled === 'auto',
integrations_loaded: Object.keys(pluginManager._pluginsByName),
appsec_enabled: !!config.appsec.enabled,
data_streams_enabled: !!config.dsmEnabled,
}
return out
}
/**
* @param {import('./config')} aConfig
*/
function setStartupLogConfig (aConfig) {
config = aConfig
}
/**
* @param {import('./plugin_manager')} thePluginManager
*/
function setStartupLogPluginManager (thePluginManager) {
pluginManager = thePluginManager
}
/**
* @param {import('./sampling_rule')[]} theRules
*/
function setSamplingRules (theRules) {
samplingRules = theRules
}
module.exports = {
startupLog,
logAgentError,
setStartupLogConfig,
setStartupLogPluginManager,
setSamplingRules,
tracerInfo,
errors,
}