@@ -7,22 +7,34 @@ const { describe, it, beforeEach, afterEach } = require('tap').mocha
77require ( './setup/core' )
88
99describe ( 'process-tags' , ( ) => {
10- const getProcessTags = require ( '../src/process-tags' )
10+ const processTags = require ( '../src/process-tags' )
1111 const { serialize, sanitize } = require ( '../src/process-tags' )
1212
13- describe ( 'getProcessTags' , ( ) => {
14- it ( 'should return an object with tags and serialized properties' , ( ) => {
15- const result = getProcessTags ( )
13+ describe ( 'processTags' , ( ) => {
14+ it ( 'should return an object with tags, serialized, and tagsObject properties' , ( ) => {
15+ assert . ok ( Object . hasOwn ( processTags , 'tags' ) )
16+ assert . ok ( Object . hasOwn ( processTags , 'serialized' ) )
17+ assert . ok ( Object . hasOwn ( processTags , 'tagsObject' ) )
18+ assert . ok ( Array . isArray ( processTags . tags ) )
19+ assert . strictEqual ( typeof processTags . serialized , 'string' )
20+ assert . strictEqual ( typeof processTags . tagsObject , 'object' )
21+ } )
22+
23+ it ( 'should have tagsObject with only defined values' , ( ) => {
24+ const { tagsObject } = processTags
25+
26+ // All values in tagsObject should be defined
27+ Object . values ( tagsObject ) . forEach ( value => {
28+ assert . notStrictEqual ( value , undefined )
29+ } )
1630
17- assert . ok ( Object . hasOwn ( result , 'tags' ) )
18- assert . ok ( Object . hasOwn ( result , 'serialized' ) )
19- assert . ok ( Array . isArray ( result . tags ) )
20- assert . strictEqual ( typeof result . serialized , 'string' )
31+ // tagsObject should have the same keys as defined tags
32+ const definedTags = processTags . tags . filter ( ( [ , value ] ) => value !== undefined )
33+ assert . strictEqual ( Object . keys ( tagsObject ) . length , definedTags . length )
2134 } )
2235
2336 it ( 'should include all expected tag names' , ( ) => {
24- const result = getProcessTags ( )
25- const tagNames = result . tags . map ( ( [ name ] ) => name ) . sort ( )
37+ const tagNames = processTags . tags . map ( ( [ name ] ) => name )
2638
2739 assertObjectContains (
2840 tagNames ,
@@ -37,41 +49,56 @@ describe('process-tags', () => {
3749 } )
3850
3951 it ( 'should have entrypoint.type set to "script"' , ( ) => {
40- const result = getProcessTags ( )
41- const typeTag = result . tags . find ( ( [ name ] ) => name === 'entrypoint.type' )
52+ const typeTag = processTags . tags . find ( ( [ name ] ) => name === 'entrypoint.type' )
4253
4354 assert . ok ( Array . isArray ( typeTag ) )
4455 assert . strictEqual ( typeTag [ 1 ] , 'script' )
4556 } )
4657
4758 it ( 'should set entrypoint.workdir to the basename of cwd' , ( ) => {
48- const result = getProcessTags ( )
49- const workdirTag = result . tags . find ( ( [ name ] ) => name === 'entrypoint.workdir' )
59+ const workdirTag = processTags . tags . find ( ( [ name ] ) => name === 'entrypoint.workdir' )
5060
5161 assert . ok ( Array . isArray ( workdirTag ) )
5262 assert . strictEqual ( typeof workdirTag [ 1 ] , 'string' )
5363 assert . doesNotMatch ( workdirTag [ 1 ] , / \/ / )
5464 } )
5565
56- // note that these tests may fail if the tracer folder structure changes
57- it ( 'should set sensible values based on tracer project structure and be sorted alphabetically' , ( ) => {
58- const result = getProcessTags ( )
66+ it ( 'should set sensible values' , ( ) => {
67+ const basedirTag = processTags . tags . find ( ( [ name ] ) => name === 'entrypoint.basedir' )
68+ const nameTag = processTags . tags . find ( ( [ name ] ) => name === 'entrypoint.name' )
69+ const typeTag = processTags . tags . find ( ( [ name ] ) => name === 'entrypoint.type' )
70+ const workdirTag = processTags . tags . find ( ( [ name ] ) => name === 'entrypoint.workdir' )
71+ const packageNameTag = processTags . tags . find ( ( [ name ] ) => name === 'package.json.name' )
72+
73+ // Entrypoint values should be set (may vary depending on test runner)
74+ assert . ok ( basedirTag )
75+ assert . strictEqual ( typeof basedirTag [ 1 ] , 'string' )
76+ assert . ok ( nameTag )
77+ assert . strictEqual ( typeof nameTag [ 1 ] , 'string' )
78+
79+ assert . ok ( typeTag )
80+ assert . strictEqual ( typeTag [ 1 ] , 'script' )
81+
82+ assert . ok ( workdirTag )
83+ assert . strictEqual ( workdirTag [ 1 ] , 'dd-trace-js' )
5984
60- assert . deepStrictEqual ( result . tags , [
61- [ 'entrypoint.basedir' , 'test' ] ,
62- [ 'entrypoint.name' , 'process-tags.spec' ] ,
63- [ 'entrypoint.type' , 'script' ] ,
64- [ 'entrypoint.workdir' , 'dd-trace-js' ] ,
65- [ 'package.json.name' , 'dd-trace' ] ,
66- ] )
85+ // Package name should exist but may vary depending on test runner
86+ assert . ok ( packageNameTag )
87+ assert . strictEqual ( typeof packageNameTag [ 1 ] , 'string' )
6788 } )
6889
69- it ( 'should serialize tags correctly' , ( ) => {
70- const result = getProcessTags ( )
90+ it ( 'should sort tags alphabetically' , ( ) => {
91+ assert . strictEqual ( processTags . tags [ 0 ] [ 0 ] , 'entrypoint.basedir' )
92+ assert . strictEqual ( processTags . tags [ 1 ] [ 0 ] , 'entrypoint.name' )
93+ assert . strictEqual ( processTags . tags [ 2 ] [ 0 ] , 'entrypoint.type' )
94+ assert . strictEqual ( processTags . tags [ 3 ] [ 0 ] , 'entrypoint.workdir' )
95+ assert . strictEqual ( processTags . tags [ 4 ] [ 0 ] , 'package.json.name' )
96+ } )
7197
98+ it ( 'should serialize tags correctly' , ( ) => {
7299 // serialized should be comma-separated and not include undefined values
73- if ( result . serialized ) {
74- const parts = result . serialized . split ( ',' )
100+ if ( processTags . serialized ) {
101+ const parts = processTags . serialized . split ( ',' )
75102 assert . ok ( parts . length > 0 )
76103 parts . forEach ( part => {
77104 assert . match ( part , / : / )
@@ -280,11 +307,16 @@ describe('process-tags', () => {
280307 process . env = env
281308 delete require . cache [ require . resolve ( '../src/config' ) ]
282309 delete require . cache [ require . resolve ( '../src/span_processor' ) ]
310+ delete require . cache [ require . resolve ( '../src/process-tags' ) ]
283311 } )
284312
285313 it ( 'should enable process tags propagation when set to true' , ( ) => {
286314 process . env . DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED = 'true'
287315
316+ // Need to reload config first, then process-tags (which reads from config)
317+ delete require . cache [ require . resolve ( '../src/config' ) ]
318+ delete require . cache [ require . resolve ( '../src/process-tags' ) ]
319+
288320 getConfig = require ( '../src/config' )
289321 const config = getConfig ( )
290322
0 commit comments