-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(otel): Use
HTTP_URL
attribute for client requests (#8539)
Turns out, `HTTP_TARGET` is always the relative path, even for outgoing requests, which omits the host. So we handle this specifically now here. While at it (and as I'm working a bit in this codebase), I also renamed the files from kebap-case to camelCase, to align with the rest of the codebase better - unless there was a specific reason to use that here @AbhiPrasad ? Closes #8535
- Loading branch information
Showing
6 changed files
with
279 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
packages/opentelemetry-node/test/utils/parseOtelSpanDescription.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { SpanKind } from '@opentelemetry/api'; | ||
import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; | ||
|
||
import { getSanitizedUrl } from '../../src/utils/parseOtelSpanDescription'; | ||
|
||
describe('getSanitizedUrl', () => { | ||
it.each([ | ||
[ | ||
'works without attributes', | ||
{}, | ||
SpanKind.CLIENT, | ||
{ | ||
urlPath: undefined, | ||
url: undefined, | ||
fragment: undefined, | ||
query: undefined, | ||
}, | ||
], | ||
[ | ||
'uses url without query for client request', | ||
{ | ||
[SemanticAttributes.HTTP_URL]: 'http://example.com/?what=true', | ||
[SemanticAttributes.HTTP_METHOD]: 'GET', | ||
[SemanticAttributes.HTTP_TARGET]: '/?what=true', | ||
[SemanticAttributes.HTTP_HOST]: 'example.com:80', | ||
[SemanticAttributes.HTTP_STATUS_CODE]: 200, | ||
}, | ||
SpanKind.CLIENT, | ||
{ | ||
urlPath: 'http://example.com/', | ||
url: 'http://example.com/', | ||
fragment: undefined, | ||
query: '?what=true', | ||
}, | ||
], | ||
[ | ||
'uses url without hash for client request', | ||
{ | ||
[SemanticAttributes.HTTP_URL]: 'http://example.com/sub#hash', | ||
[SemanticAttributes.HTTP_METHOD]: 'GET', | ||
[SemanticAttributes.HTTP_TARGET]: '/sub#hash', | ||
[SemanticAttributes.HTTP_HOST]: 'example.com:80', | ||
[SemanticAttributes.HTTP_STATUS_CODE]: 200, | ||
}, | ||
SpanKind.CLIENT, | ||
{ | ||
urlPath: 'http://example.com/sub', | ||
url: 'http://example.com/sub', | ||
fragment: '#hash', | ||
query: undefined, | ||
}, | ||
], | ||
[ | ||
'uses route if available for client request', | ||
{ | ||
[SemanticAttributes.HTTP_URL]: 'http://example.com/?what=true', | ||
[SemanticAttributes.HTTP_METHOD]: 'GET', | ||
[SemanticAttributes.HTTP_TARGET]: '/?what=true', | ||
[SemanticAttributes.HTTP_ROUTE]: '/my-route', | ||
[SemanticAttributes.HTTP_HOST]: 'example.com:80', | ||
[SemanticAttributes.HTTP_STATUS_CODE]: 200, | ||
}, | ||
SpanKind.CLIENT, | ||
{ | ||
urlPath: '/my-route', | ||
url: 'http://example.com/', | ||
fragment: undefined, | ||
query: '?what=true', | ||
}, | ||
], | ||
[ | ||
'falls back to target for client request if url not available', | ||
{ | ||
[SemanticAttributes.HTTP_METHOD]: 'GET', | ||
[SemanticAttributes.HTTP_TARGET]: '/?what=true', | ||
[SemanticAttributes.HTTP_HOST]: 'example.com:80', | ||
[SemanticAttributes.HTTP_STATUS_CODE]: 200, | ||
}, | ||
SpanKind.CLIENT, | ||
{ | ||
urlPath: '/', | ||
url: undefined, | ||
fragment: undefined, | ||
query: undefined, | ||
}, | ||
], | ||
[ | ||
'uses target without query for server request', | ||
{ | ||
[SemanticAttributes.HTTP_URL]: 'http://example.com/?what=true', | ||
[SemanticAttributes.HTTP_METHOD]: 'GET', | ||
[SemanticAttributes.HTTP_TARGET]: '/?what=true', | ||
[SemanticAttributes.HTTP_HOST]: 'example.com:80', | ||
[SemanticAttributes.HTTP_STATUS_CODE]: 200, | ||
}, | ||
SpanKind.SERVER, | ||
{ | ||
urlPath: '/', | ||
url: 'http://example.com/', | ||
fragment: undefined, | ||
query: '?what=true', | ||
}, | ||
], | ||
[ | ||
'uses target without hash for server request', | ||
{ | ||
[SemanticAttributes.HTTP_URL]: 'http://example.com/?what=true', | ||
[SemanticAttributes.HTTP_METHOD]: 'GET', | ||
[SemanticAttributes.HTTP_TARGET]: '/sub#hash', | ||
[SemanticAttributes.HTTP_HOST]: 'example.com:80', | ||
[SemanticAttributes.HTTP_STATUS_CODE]: 200, | ||
}, | ||
SpanKind.SERVER, | ||
{ | ||
urlPath: '/sub', | ||
url: 'http://example.com/', | ||
fragment: undefined, | ||
query: '?what=true', | ||
}, | ||
], | ||
[ | ||
'uses route for server request if available', | ||
{ | ||
[SemanticAttributes.HTTP_URL]: 'http://example.com/?what=true', | ||
[SemanticAttributes.HTTP_METHOD]: 'GET', | ||
[SemanticAttributes.HTTP_TARGET]: '/?what=true', | ||
[SemanticAttributes.HTTP_ROUTE]: '/my-route', | ||
[SemanticAttributes.HTTP_HOST]: 'example.com:80', | ||
[SemanticAttributes.HTTP_STATUS_CODE]: 200, | ||
}, | ||
SpanKind.SERVER, | ||
{ | ||
urlPath: '/my-route', | ||
url: 'http://example.com/', | ||
fragment: undefined, | ||
query: '?what=true', | ||
}, | ||
], | ||
])('%s', (_, attributes, kind, expected) => { | ||
const actual = getSanitizedUrl(attributes, kind); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); |