microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
321 stars 138 forks source link

[BUG] Custom proxy with error "Expecting a valid host string in proxy settings, but found" #1329

Closed hintdesk closed 1 month ago

hintdesk commented 1 month ago

Description/Screenshot In my company we have set a corporate proxy. To connect to Internet the application has to use this proxy. The proxy has the format of "http://proxy.companyname.i:port". I have set that proxy over env variable http_proxy und https_proxy. Currently I receive this error

Configuring Azure AppInsights Failed to start default client: [object Error]{ stack: 'Error: Expecting a valid host string in proxy settings, but found "proxy.companyname.i". 2024-05-15T13:03:52.037201912Z at getUrlFromProxySettings (/app/node_modules/@azure/core-rest-pipeline/dist/commonjs/policies/proxyPolicy.js:129:15) at proxyPolicy (/app/node_modules/@azure/core-rest-pipeline/dist/commonjs/policies/proxyPolicy.js:177:11) 2024-05-15T13:03:52.037210399Z at createPipelineFromOptions (/app/node_modules/@azure/core-rest-pipeline/dist/commonjs/createPipelineFromOptions.js:30:61) at createClientPipeline (/app/node_modules/@azure/core-client/dist/commonjs/pipeline.js:16:73) at createDefaultPipeline (/app/node_modules/@azure/core-client/dist/commonjs/serviceClient.js:157:51) at new ServiceClient (/app/node_modules/@azure/core-client/dist/commonjs/serviceClient.js:53:45) at new ApplicationInsightsClient (/app/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:1824:9) 2024-05-15T13:03:52.037227236Z at new HttpSender (/app/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:2782:34) at new AzureMonitorMetricExporter (/app/node_modules/@azure/monitor-opentelemetry-exporter/dist/index.js:3591:24) at new MetricHandler (/app/node_modules/@azure/monitor-opentelemetry/dist/index.js:3220:31)', message: 'Expecting a valid host string in proxy settings, but found "proxy.companyname.i".', name: 'Error' [] AppInsights ProxyHttpUrl: http://proxy.companyname.i:port AppInsights new ProxyHttpUrl: http://proxy.companyname.i:port `

Steps to Reproduce

if (process.env.APPLICATIONINSIGHTS_CONNECTION_STRING) { console.log('Configuring Azure AppInsights'); appInsights .setup(process.env.APPLICATIONINSIGHTS_CONNECTION_STRING) .setAutoDependencyCorrelation(false) .setAutoCollectRequests(true) .setAutoCollectPerformance(false, false) .setAutoCollectExceptions(true) .setAutoCollectDependencies(false) .setAutoCollectConsole(false) .start(); }

Expected behavior What should I have to do to tell ApplicationInsights SDK that "proxy.companayname.i:port" is a valid host?

JacksonWeber commented 1 month ago

@hintdesk This looks to be related to Node.js's URL class and how it parses URLs. ApplicationInsights 3.X SDK relies on the Azure SDK's core-rest-pipeline, which in turn parses the proxy URL here. While this works fine for the string http://proxy.companyname.i, the method fails on proxy.companyname.i (which is what the method receives there as it's given the proxy's host string instead of the full URL). I'll file an issue on the core-rest-pipeline side as it seems like this issue would affect anyone attempting to pass in valid proxy URLs with multiple . characters.