@@ -8,49 +8,78 @@ const { version } = require('../../package.json')
8
8
9
9
describe ( 'Dynamic Instrumentation' , function ( ) {
10
10
describe ( 'ddtags' , function ( ) {
11
- const t = setup ( {
12
- env : {
13
- DD_ENV : 'test-env' ,
14
- DD_VERSION : 'test-version' ,
15
- DD_GIT_COMMIT_SHA : 'test-commit-sha' ,
16
- DD_GIT_REPOSITORY_URL : 'test-repository-url'
17
- } ,
18
- testApp : 'target-app/basic.js'
19
- } )
11
+ describe ( 'basic case' , function ( ) {
12
+ const t = setup ( {
13
+ env : {
14
+ DD_ENV : 'test-env' ,
15
+ DD_VERSION : 'test-version' ,
16
+ DD_GIT_COMMIT_SHA : 'test-commit-sha' ,
17
+ DD_GIT_REPOSITORY_URL : 'test-repository-url'
18
+ } ,
19
+ testApp : 'target-app/basic.js'
20
+ } )
21
+
22
+ it ( 'should add the expected ddtags as a query param to /debugger/v1/input' , function ( done ) {
23
+ t . triggerBreakpoint ( )
24
+
25
+ t . agent . on ( 'debugger-input' , ( { query } ) => {
26
+ assert . property ( query , 'ddtags' )
27
+
28
+ const ddtags = extractDDTagsFromQuery ( query )
20
29
21
- it ( 'should add the expected ddtags as a query param to /debugger/v1/input' , function ( done ) {
22
- t . triggerBreakpoint ( )
23
-
24
- t . agent . on ( 'debugger-input' , ( { query } ) => {
25
- assert . property ( query , 'ddtags' )
26
-
27
- // Before: "a:b,c:d"
28
- // After: { a: 'b', c: 'd' }
29
- const ddtags = query . ddtags
30
- . split ( ',' )
31
- . map ( ( tag ) => tag . split ( ':' ) )
32
- . reduce ( ( acc , [ k , v ] ) => { acc [ k ] = v ; return acc } , { } )
33
-
34
- assert . hasAllKeys ( ddtags , [
35
- 'env' ,
36
- 'version' ,
37
- 'debugger_version' ,
38
- 'host_name' ,
39
- 'git.commit.sha' ,
40
- 'git.repository_url'
41
- ] )
42
-
43
- assert . strictEqual ( ddtags . env , 'test-env' )
44
- assert . strictEqual ( ddtags . version , 'test-version' )
45
- assert . strictEqual ( ddtags . debugger_version , version )
46
- assert . strictEqual ( ddtags . host_name , os . hostname ( ) )
47
- assert . strictEqual ( ddtags [ 'git.commit.sha' ] , 'test-commit-sha' )
48
- assert . strictEqual ( ddtags [ 'git.repository_url' ] , 'test-repository-url' )
49
-
50
- done ( )
30
+ assert . hasAllKeys ( ddtags , [
31
+ 'env' ,
32
+ 'version' ,
33
+ 'debugger_version' ,
34
+ 'host_name' ,
35
+ 'git.commit.sha' ,
36
+ 'git.repository_url'
37
+ ] )
38
+
39
+ assert . strictEqual ( ddtags . env , 'test-env' )
40
+ assert . strictEqual ( ddtags . version , 'test-version' )
41
+ assert . strictEqual ( ddtags . debugger_version , version )
42
+ assert . strictEqual ( ddtags . host_name , os . hostname ( ) )
43
+ assert . strictEqual ( ddtags [ 'git.commit.sha' ] , 'test-commit-sha' )
44
+ assert . strictEqual ( ddtags [ 'git.repository_url' ] , 'test-repository-url' )
45
+
46
+ done ( )
47
+ } )
48
+
49
+ t . agent . addRemoteConfig ( t . rcConfig )
51
50
} )
51
+ } )
52
52
53
- t . agent . addRemoteConfig ( t . rcConfig )
53
+ describe ( 'with undefined values' , function ( ) {
54
+ const t = setup ( { testApp : 'target-app/basic.js' } )
55
+
56
+ it ( 'should not include undefined values in the ddtags query param' , function ( done ) {
57
+ t . triggerBreakpoint ( )
58
+
59
+ t . agent . on ( 'debugger-input' , ( { query } ) => {
60
+ assert . property ( query , 'ddtags' )
61
+
62
+ const ddtags = extractDDTagsFromQuery ( query )
63
+
64
+ assert . hasAllKeys ( ddtags , [
65
+ 'debugger_version' ,
66
+ 'host_name'
67
+ ] )
68
+
69
+ done ( )
70
+ } )
71
+
72
+ t . agent . addRemoteConfig ( t . rcConfig )
73
+ } )
54
74
} )
55
75
} )
56
76
} )
77
+
78
+ // Before: "a:b,c:d"
79
+ // After: { a: 'b', c: 'd' }
80
+ function extractDDTagsFromQuery ( query ) {
81
+ return query . ddtags
82
+ . split ( ',' )
83
+ . map ( ( tag ) => tag . split ( ':' ) )
84
+ . reduce ( ( acc , [ k , v ] ) => { acc [ k ] = v ; return acc } , { } )
85
+ }
0 commit comments