@@ -12,8 +12,19 @@ const ENTRYPOINT_PATH = require.main?.filename || ''
1212// entrypoint.basedir = baz
1313// package.json.name = <from package.json>
1414
15- // process tags are constant throughout the lifetime of a process
16- function getProcessTags ( ) {
15+ /**
16+ * Sanitize a process tag value
17+ *
18+ * @param {string } value
19+ * @returns {string }
20+ */
21+ function sanitize ( value ) {
22+ return String ( value )
23+ . toLowerCase ( )
24+ . replaceAll ( / [ ^ a - z A - Z 0 - 9 / _ . - ] + / g, '_' )
25+ }
26+
27+ function buildProcessTags ( config ) {
1728 // Lazy load pkg to avoid issues with require.main during test initialization
1829 const pkg = require ( '../pkg' )
1930
@@ -35,6 +46,13 @@ function getProcessTags () {
3546 [ 'package.json.name' , pkg . name || undefined ] ,
3647 ]
3748
49+ // If config dependent tags keep growing, we should consider moving this into a function
50+ if ( config ?. isServiceNameInferred ) {
51+ tags . push ( [ 'svc.auto' , config . service ] )
52+ } else if ( config ) {
53+ tags . push ( [ 'svc.user' , true ] )
54+ }
55+
3856 const tagsArray = [ ]
3957 const tagsObject = { }
4058
@@ -46,38 +64,27 @@ function getProcessTags () {
4664 }
4765 }
4866
49- const serialized = tagsArray . join ( ',' )
50-
51- return {
52- tags,
53- serialized,
54- tagsObject,
55- tagsArray,
56- }
67+ processTags . tags = tags
68+ processTags . serialized = tagsArray . join ( ',' )
69+ processTags . tagsObject = tagsObject
70+ processTags . tagsArray = tagsArray
5771}
5872
59- // Export the singleton
60- module . exports = getProcessTags ( )
61-
62- module . exports . TRACING_FIELD_NAME = '_dd.tags.process'
63- module . exports . DSM_FIELD_NAME = 'ProcessTags'
64- module . exports . PROFILING_FIELD_NAME = 'process_tags'
65- module . exports . DYNAMIC_INSTRUMENTATION_FIELD_NAME = 'process_tags'
66- module . exports . TELEMETRY_FIELD_NAME = 'process_tags'
67- module . exports . REMOTE_CONFIG_FIELD_NAME = 'process_tags'
68- module . exports . CRASH_TRACKING_FIELD_NAME = 'process_tags'
69- module . exports . CLIENT_TRACE_STATISTICS_FIELD_NAME = 'ProcessTags'
70-
71- /**
72- * Sanitize a process tag value
73- *
74- * @param {string } value
75- * @returns {string }
76- */
77- function sanitize ( value ) {
78- return String ( value )
79- . toLowerCase ( )
80- . replaceAll ( / [ ^ a - z A - Z 0 - 9 / _ . - ] + / g, '_' )
73+ // Singleton with constant defaults so pre-init reads don't blow up
74+ const processTags = module . exports = {
75+ initialize ( config ) {
76+ // check if one of the properties added during build exist and if so return
77+ if ( processTags . tags ) return
78+ buildProcessTags ( config )
79+ } ,
80+
81+ TRACING_FIELD_NAME : '_dd.tags.process' ,
82+ DSM_FIELD_NAME : 'ProcessTags' ,
83+ PROFILING_FIELD_NAME : 'process_tags' ,
84+ DYNAMIC_INSTRUMENTATION_FIELD_NAME : 'process_tags' ,
85+ TELEMETRY_FIELD_NAME : 'process_tags' ,
86+ REMOTE_CONFIG_FIELD_NAME : 'process_tags' ,
87+ CRASH_TRACKING_FIELD_NAME : 'process_tags' ,
88+ CLIENT_TRACE_STATISTICS_FIELD_NAME : 'ProcessTags' ,
89+ sanitize,
8190}
82-
83- module . exports . sanitize = sanitize
0 commit comments