From f8694cfbb121c5864e0ff837bb7cead0e48894bd Mon Sep 17 00:00:00 2001 From: Olivier Albertini Date: Sat, 30 Nov 2019 10:59:25 -0500 Subject: [PATCH] fix(plugin-http): http.url attribute closes #579 Signed-off-by: Olivier Albertini --- packages/opentelemetry-plugin-http/src/utils.ts | 2 +- .../opentelemetry-plugin-http/test/utils/assertSpan.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-plugin-http/src/utils.ts b/packages/opentelemetry-plugin-http/src/utils.ts index fbada00b1fa..b09d637ec53 100644 --- a/packages/opentelemetry-plugin-http/src/utils.ts +++ b/packages/opentelemetry-plugin-http/src/utils.ts @@ -40,7 +40,7 @@ export const getAbsoluteUrl = ( const port = (reqUrlObject.port || '').toString(); const path = reqUrlObject.path || '/'; let host = - headers.host || reqUrlObject.hostname || headers.host || 'localhost'; + reqUrlObject.host || reqUrlObject.hostname || headers.host || 'localhost'; // if there is no port in host and there is a port // it should be displayed if it's not 80 and 443 (default ports) diff --git a/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts b/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts index eccf35bc7a8..712498432e6 100644 --- a/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts +++ b/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts @@ -69,7 +69,7 @@ export const assertSpan = ( span.attributes[AttributeNames.HTTP_STATUS_CODE], validations.httpStatusCode ); - assert.ok(span.endTime); + assert.strictEqual(span.links.length, 0); assert.strictEqual(span.events.length, 0); @@ -79,6 +79,13 @@ export const assertSpan = ( utils.parseResponseStatus(validations.httpStatusCode) ); + assert.ok( + span.attributes[AttributeNames.HTTP_URL].indexOf( + span.attributes[AttributeNames.HTTP_HOSTNAME] + ) > -1, + 'should be consistent' + ); + assert.ok(span.endTime, 'must be finished'); assert.ok(hrTimeToNanoseconds(span.duration), 'must have positive duration'); if (validations.reqHeaders) {