@@ -1869,32 +1869,89 @@ describe("diagnostics-otel service", () => {
18691869 }
18701870 } ) ;
18711871
1872- test ( "falls back to default OTLP agents when env proxy agent creation fails" , async ( ) => {
1872+ test . each ( [
1873+ [ "traces" , { traces : true } , "unsupported proxy protocol" ] ,
1874+ [ "metrics" , { metrics : true } , "invalid proxy URL" ] ,
1875+ [ "logs" , { logs : true } , "unsupported proxy protocol" ] ,
1876+ ] as const ) (
1877+ "refuses direct %s export when the configured proxy cannot initialize" ,
1878+ async ( _signal , signals , errorMessage ) => {
1879+ createNodeProxyAgentMock . mockImplementation ( ( ) => {
1880+ throw new Error ( errorMessage ) ;
1881+ } ) ;
1882+
1883+ await expect (
1884+ startOtelService ( { endpoint : "https://collector.example.com/otlp" , ...signals } ) ,
1885+ ) . rejects . toThrow (
1886+ "Configured telemetry proxy is invalid or unsupported; refusing direct export" ,
1887+ ) ;
1888+
1889+ expect ( traceExporterCtor ) . not . toHaveBeenCalled ( ) ;
1890+ expect ( metricExporterCtor ) . not . toHaveBeenCalled ( ) ;
1891+ expect ( logExporterCtor ) . not . toHaveBeenCalled ( ) ;
1892+ } ,
1893+ ) ;
1894+
1895+ test ( "redacts proxy credentials from telemetry startup failures" , async ( ) => {
1896+ const proxyPassword = "qa-otel-proxy-password-sentinel" ;
18731897 createNodeProxyAgentMock . mockImplementation ( ( ) => {
1874- throw new Error ( "unsupported proxy protocol" ) ;
1898+ throw new Error ( `Invalid proxy URL: "https://operator: ${ proxyPassword } @proxy.example.com"` ) ;
18751899 } ) ;
18761900
1877- const { ctx } = await startOtelService ( {
1901+ const failure = await startOtelService ( {
18781902 endpoint : "https://collector.example.com/otlp" ,
18791903 traces : true ,
1880- metrics : true ,
1881- logs : true ,
1882- } ) ;
1904+ } ) . catch ( ( error : unknown ) => error ) ;
18831905
1884- expect ( firstExporterOptions ( traceExporterCtor ) . httpAgentOptions ) . toBeUndefined ( ) ;
1885- expect ( firstExporterOptions ( metricExporterCtor ) . httpAgentOptions ) . toBeUndefined ( ) ;
1886- expect ( firstExporterOptions ( logExporterCtor ) . httpAgentOptions ) . toBeUndefined ( ) ;
1887- expect ( ctx . logger . warn ) . toHaveBeenCalledWith (
1888- "diagnostics-otel: env proxy agent unavailable for OTLP traces exporter; falling back to default Node agent" ,
1889- ) ;
1890- expect ( ctx . logger . warn ) . toHaveBeenCalledWith (
1891- "diagnostics-otel: env proxy agent unavailable for OTLP metrics exporter; falling back to default Node agent" ,
1892- ) ;
1893- expect ( ctx . logger . warn ) . toHaveBeenCalledWith (
1894- "diagnostics-otel: env proxy agent unavailable for OTLP logs exporter; falling back to default Node agent" ,
1895- ) ;
1906+ expect ( failure ) . toBeInstanceOf ( Error ) ;
1907+ expect ( failure ) . toMatchObject ( {
1908+ message : "Configured telemetry proxy is invalid or unsupported; refusing direct export" ,
1909+ } ) ;
1910+ expect ( failure ) . not . toHaveProperty ( "cause" ) ;
1911+ expect ( String ( failure ) ) . not . toContain ( proxyPassword ) ;
1912+ expect ( traceExporterCtor ) . not . toHaveBeenCalled ( ) ;
18961913 } ) ;
18971914
1915+ test . each ( [
1916+ {
1917+ disabledSignal : "traces" ,
1918+ enabledSignal : "metrics" ,
1919+ disabledEndpoint : "tracesEndpoint" ,
1920+ signals : { traces : false , metrics : true } ,
1921+ } ,
1922+ {
1923+ disabledSignal : "metrics" ,
1924+ enabledSignal : "traces" ,
1925+ disabledEndpoint : "metricsEndpoint" ,
1926+ signals : { traces : true , metrics : false } ,
1927+ } ,
1928+ ] as const ) (
1929+ "does not resolve proxy settings for disabled $disabledSignal export" ,
1930+ async ( { disabledSignal, enabledSignal, disabledEndpoint, signals } ) => {
1931+ createNodeProxyAgentMock . mockImplementation ( ( { targetUrl } : { targetUrl : string } ) => {
1932+ if ( targetUrl . includes ( `disabled-${ disabledSignal } .example.com` ) ) {
1933+ throw new Error ( "invalid disabled-signal proxy" ) ;
1934+ }
1935+ return nodeProxyAgent ;
1936+ } ) ;
1937+
1938+ await startOtelService ( {
1939+ endpoint : "https://collector.example.com/otlp" ,
1940+ ...signals ,
1941+ configure : ( ctx ) => {
1942+ ctx . config . diagnostics ! . otel ! [ disabledEndpoint ] =
1943+ `https://disabled-${ disabledSignal } .example.com/otlp` ;
1944+ } ,
1945+ } ) ;
1946+
1947+ expect ( createNodeProxyAgentCalls ( ) ) . toEqual ( [
1948+ expect . objectContaining ( {
1949+ targetUrl : `https://collector.example.com/otlp/v1/${ enabledSignal } ` ,
1950+ } ) ,
1951+ ] ) ;
1952+ } ,
1953+ ) ;
1954+
18981955 test ( "leaves OTLP HTTP exporters on their default agents when env proxy is bypassed" , async ( ) => {
18991956 await startOtelService ( {
19001957 endpoint : "https://collector.example.com/otlp" ,
0 commit comments