File tree Expand file tree Collapse file tree 4 files changed +74
-1
lines changed Expand file tree Collapse file tree 4 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 9
9
const path = require ( 'path' )
10
10
const { assert } = require ( 'chai' )
11
11
const semver = require ( 'semver' )
12
+ const { inspect } = require ( 'util' )
13
+ const fs = require ( 'fs' )
12
14
13
15
const execArgvs = [
14
16
{
@@ -72,6 +74,39 @@ execArgvs.forEach(({ execArgv, skip }) => {
72
74
} )
73
75
} )
74
76
77
+ it ( 'saves tracer configuration on disk' , async ( ) => {
78
+ if ( process . platform !== 'linux' ) {
79
+ return
80
+ }
81
+
82
+ proc = await spawnProc ( startupTestFile , {
83
+ cwd,
84
+ execArgv,
85
+ env : {
86
+ AGENT_PORT : agent . port
87
+ }
88
+ } )
89
+
90
+ const containsDatadogMemfd = ( fds ) => {
91
+ for ( const fd of fds ) {
92
+ try {
93
+ const fdName = fs . readlinkSync ( `/proc/${ proc . pid } /fd/${ fd } ` )
94
+ if ( fdName . includes ( 'datadog-tracer-info-' ) ) {
95
+ return true
96
+ }
97
+ } catch { }
98
+ }
99
+ return false
100
+ }
101
+
102
+ const fds = fs . readdirSync ( `/proc/${ proc . pid } /fd` )
103
+
104
+ assert (
105
+ containsDatadogMemfd ( fds ) ,
106
+ `FDs ${ inspect ( fds ) } of PID ${ proc . pid } did not contain the datadog tracer configuration in memfd`
107
+ )
108
+ } )
109
+
75
110
it ( 'works for options.url' , async ( ) => {
76
111
proc = await spawnProc ( startupTestFile , {
77
112
cwd,
Original file line number Diff line number Diff line change @@ -24,6 +24,17 @@ class DatadogTracer extends Tracer {
24
24
this . _scope = new Scope ( )
25
25
setStartupLogConfig ( config )
26
26
flushStartupLogs ( log )
27
+
28
+ if ( ! config . _isInServerlessEnvironment ( ) ) {
29
+ const storeConfig = require ( './tracer_metadata' )
30
+ // Keep a reference to the handle, to keep the memfd alive in memory.
31
+ // It is read by the service discovery feature.
32
+ const metadata = storeConfig ( config )
33
+ if ( metadata === undefined ) {
34
+ log . warn ( 'Could not store tracer configuration for service discovery' )
35
+ }
36
+ this . _inmem_cfg = metadata
37
+ }
27
38
}
28
39
29
40
configure ( config ) {
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ // Load binding first to not import other modules if it throws
4
+ const libdatadog = require ( '@datadog/libdatadog' )
5
+ const tracerVersion = require ( '../../../version' ) . VERSION
6
+
7
+ function storeConfig ( config ) {
8
+ const processDiscovery = libdatadog . maybeLoad ( 'process-discovery' )
9
+ if ( processDiscovery === undefined ) {
10
+ return
11
+ }
12
+
13
+ const metadata = new processDiscovery . TracerMetadata (
14
+ config . tags [ 'runtime-id' ] ,
15
+ tracerVersion ,
16
+ config . hostname ,
17
+ config . server || null ,
18
+ config . env || null ,
19
+ config . version || null
20
+ )
21
+
22
+ return processDiscovery . storeMetadata ( metadata )
23
+ }
24
+
25
+ module . exports = storeConfig
Original file line number Diff line number Diff line change 3
3
/* eslint-disable no-var */
4
4
/* eslint-disable unicorn/prefer-number-properties */
5
5
6
- var ddMatches = require ( './package.json' ) . version . match ( / ^ ( \d + ) \. ( \d + ) \. ( \d + ) / )
6
+ var version = require ( './package.json' ) . version
7
+ var ddMatches = version . match ( / ^ ( \d + ) \. ( \d + ) \. ( \d + ) / )
7
8
var nodeMatches = process . versions . node . match ( / ^ ( \d + ) \. ( \d + ) \. ( \d + ) / )
8
9
9
10
module . exports = {
11
+ VERSION : version ,
10
12
DD_MAJOR : parseInt ( ddMatches [ 1 ] ) ,
11
13
DD_MINOR : parseInt ( ddMatches [ 2 ] ) ,
12
14
DD_PATCH : parseInt ( ddMatches [ 3 ] ) ,
You can’t perform that action at this time.
0 commit comments