Skip to content

Commit

Permalink
Use user URL if validation returns empty endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN committed Jul 28, 2021
1 parent fd2410c commit 2dba5e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/opentelemetry-exporter-collector-grpc/src/util.ts
Expand Up @@ -113,6 +113,14 @@ export function validateAndNormalizeUrl(url: string): string {
url = `https://${url}`;
}
const target = new URL(url);

if (target.host === '') {
diag.warn(
'Parsing URL failed to return a valid host. Returning raw url.'
);
return url
}

if (target.pathname && target.pathname !== '/') {
diag.warn(
'URL path should not be set when using grpc, the path part of the URL will be ignored.'
Expand All @@ -123,5 +131,6 @@ export function validateAndNormalizeUrl(url: string): string {
'URL protocol should be http(s):// or grpc(s)://. Using grpc://.'
);
}
return target.host;

return target.host
}
Expand Up @@ -62,6 +62,12 @@ describe('validateAndNormalizeUrl()', () => {
expected: 'api.datacat.io',
warn: 'URL path should not be set when using grpc, the path part of the URL will be ignored.',
},
{
name: 'missing scheme should fallback to provided url',
input: 'example-localhost:1234',
expected: 'example-localhost:1234',
warn: 'Parsing URL failed to return a valid host. Returning raw url.',
},
];
tests.forEach(test => {
it(test.name, () => {
Expand Down

0 comments on commit 2dba5e6

Please sign in to comment.