@@ -121,7 +121,7 @@ describe("resolveOtelExportConfig", () => {
121121 }
122122 } ) ;
123123
124- test ( "service name: env > settings > default" , ( ) => {
124+ test ( "service name: env > settings > attrs > default" , ( ) => {
125125 const fromSettings = resolveOtelExportConfig (
126126 baseSettings ( { endpoint : "https://c.example" , serviceName : "from-settings" } ) ,
127127 { } ,
@@ -137,6 +137,65 @@ describe("resolveOtelExportConfig", () => {
137137 expect ( fromEnv . ok && fromEnv . config . enabled && fromEnv . config . serviceName ) . toBe ( "from-env" ) ;
138138 } ) ;
139139
140+ test ( "service.name: attrs used when env and settings serviceName unset" , ( ) => {
141+ const result = resolveOtelExportConfig (
142+ baseSettings ( {
143+ endpoint : "https://c.example" ,
144+ resourceAttributes : { "service.name" : "from-attrs" } ,
145+ } ) ,
146+ { } ,
147+ ) ;
148+ expect ( result . ok ) . toBe ( true ) ;
149+ if ( result . ok && result . config . enabled ) {
150+ expect ( result . config . serviceName ) . toBe ( "from-attrs" ) ;
151+ expect ( result . config . resourceAttributes [ "service.name" ] ) . toBe ( "from-attrs" ) ;
152+ }
153+ } ) ;
154+
155+ test ( "service.name: env wins over settings and attrs, always synced to attrs" , ( ) => {
156+ const result = resolveOtelExportConfig (
157+ baseSettings ( {
158+ endpoint : "https://c.example" ,
159+ serviceName : "from-settings" ,
160+ resourceAttributes : { "service.name" : "from-attrs" } ,
161+ } ) ,
162+ { [ OTEL_ENV . serviceName ] : "from-env" } ,
163+ ) ;
164+ expect ( result . ok ) . toBe ( true ) ;
165+ if ( result . ok && result . config . enabled ) {
166+ expect ( result . config . serviceName ) . toBe ( "from-env" ) ;
167+ expect ( result . config . resourceAttributes [ "service.name" ] ) . toBe ( "from-env" ) ;
168+ }
169+ } ) ;
170+
171+ test ( "service.name: settings wins over attrs, always synced to attrs" , ( ) => {
172+ const result = resolveOtelExportConfig (
173+ baseSettings ( {
174+ endpoint : "https://c.example" ,
175+ serviceName : "from-settings" ,
176+ resourceAttributes : { "service.name" : "from-attrs" } ,
177+ } ) ,
178+ { } ,
179+ ) ;
180+ expect ( result . ok ) . toBe ( true ) ;
181+ if ( result . ok && result . config . enabled ) {
182+ expect ( result . config . serviceName ) . toBe ( "from-settings" ) ;
183+ expect ( result . config . resourceAttributes [ "service.name" ] ) . toBe ( "from-settings" ) ;
184+ }
185+ } ) ;
186+
187+ test ( "service.name: env OTEL_RESOURCE_ATTRIBUTES service.name used when no env/settings name" , ( ) => {
188+ const result = resolveOtelExportConfig ( baseSettings ( { endpoint : "https://c.example" } ) , {
189+ [ OTEL_ENV . resourceAttributes ] : "service.name=from-env-attrs,team=corbits" ,
190+ } ) ;
191+ expect ( result . ok ) . toBe ( true ) ;
192+ if ( result . ok && result . config . enabled ) {
193+ expect ( result . config . serviceName ) . toBe ( "from-env-attrs" ) ;
194+ expect ( result . config . resourceAttributes [ "service.name" ] ) . toBe ( "from-env-attrs" ) ;
195+ expect ( result . config . resourceAttributes . team ) . toBe ( "corbits" ) ;
196+ }
197+ } ) ;
198+
140199 test ( "resource attributes merge with env winning on conflict" , ( ) => {
141200 const result = resolveOtelExportConfig (
142201 baseSettings ( {
@@ -290,4 +349,38 @@ describe("otelConfigForDump", () => {
290349 test ( "disabled dump view is empty of secrets" , ( ) => {
291350 expect ( otelConfigForDump ( { enabled : false } ) ) . toEqual ( { enabled : false } ) ;
292351 } ) ;
352+
353+ test ( "redacts high-risk resource attribute values in dump view" , ( ) => {
354+ const resolved = resolveOtelExportConfig (
355+ baseSettings ( {
356+ endpoint : "https://collector.example" ,
357+ resourceAttributes : {
358+ "deployment.environment" : "prod" ,
359+ "api_key" : "should-not-leak" ,
360+ "auth.token" : "tok-secret" ,
361+ "db.password" : "p@ss" ,
362+ team : "corbits" ,
363+ } ,
364+ } ) ,
365+ { } ,
366+ ) ;
367+ expect ( resolved . ok ) . toBe ( true ) ;
368+ if ( ! resolved . ok || ! resolved . config . enabled ) throw new Error ( "expected enabled config" ) ;
369+
370+ // Live export config keeps raw values for the exporter.
371+ expect ( resolved . config . resourceAttributes . api_key ) . toBe ( "should-not-leak" ) ;
372+
373+ const dump = otelConfigForDump ( resolved . config ) ;
374+ expect ( dump . enabled ) . toBe ( true ) ;
375+ if ( ! dump . enabled ) throw new Error ( "expected enabled dump" ) ;
376+ expect ( dump . resourceAttributes [ "deployment.environment" ] ) . toBe ( "prod" ) ;
377+ expect ( dump . resourceAttributes . team ) . toBe ( "corbits" ) ;
378+ expect ( dump . resourceAttributes . api_key ) . toBe ( "[redacted]" ) ;
379+ expect ( dump . resourceAttributes [ "auth.token" ] ) . toBe ( "[redacted]" ) ;
380+ expect ( dump . resourceAttributes [ "db.password" ] ) . toBe ( "[redacted]" ) ;
381+ const serialized = JSON . stringify ( dump ) ;
382+ expect ( serialized ) . not . toContain ( "should-not-leak" ) ;
383+ expect ( serialized ) . not . toContain ( "tok-secret" ) ;
384+ expect ( serialized ) . not . toContain ( "p@ss" ) ;
385+ } ) ;
293386} ) ;
0 commit comments