From 0639737d77f40e00eeb8e9bd2dcc4fd094ecf6d2 Mon Sep 17 00:00:00 2001 From: Olivier Albertini Date: Wed, 22 Jan 2020 11:56:25 -0500 Subject: [PATCH] feat(plugin-http): sync. specs for statuscode closes #642 Signed-off-by: Olivier Albertini --- packages/opentelemetry-plugin-http/README.md | 1 + .../opentelemetry-plugin-http/src/utils.ts | 44 +++++++++---------- .../test/functionals/http-enable.test.ts | 14 +++++- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/packages/opentelemetry-plugin-http/README.md b/packages/opentelemetry-plugin-http/README.md index 69d196b5cdd..59c7fa31e52 100644 --- a/packages/opentelemetry-plugin-http/README.md +++ b/packages/opentelemetry-plugin-http/README.md @@ -55,6 +55,7 @@ Http plugin has few options available to choose from. You can set the following: | [`ignoreIncomingPaths`](https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-plugin-http/src/types.ts#L28) | `IgnoreMatcher[]` | Http plugin will not trace all incoming requests that match paths | | [`ignoreOutgoingUrls`](https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-plugin-http/src/types.ts#L28) | `IgnoreMatcher[]` | Http plugin will not trace all outgoing requests that match urls | | [`serverName`](https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-plugin-http/src/types.ts#L28) | `string` | The primary server name of the matched virtual host. | + ## Useful links - For more information on OpenTelemetry, visit: - For more about OpenTelemetry JavaScript: diff --git a/packages/opentelemetry-plugin-http/src/utils.ts b/packages/opentelemetry-plugin-http/src/utils.ts index f49a9978d4b..5093bd7320b 100644 --- a/packages/opentelemetry-plugin-http/src/utils.ts +++ b/packages/opentelemetry-plugin-http/src/utils.ts @@ -63,32 +63,28 @@ export const getAbsoluteUrl = ( export const parseResponseStatus = ( statusCode: number ): Omit => { - if (statusCode < 200 || statusCode > 504) { - return { code: CanonicalCode.UNKNOWN }; - } else if (statusCode >= 200 && statusCode < 400) { + if (statusCode < 400) { return { code: CanonicalCode.OK }; - } else { - switch (statusCode) { - case 400: - return { code: CanonicalCode.INVALID_ARGUMENT }; - case 504: - return { code: CanonicalCode.DEADLINE_EXCEEDED }; - case 404: - return { code: CanonicalCode.NOT_FOUND }; - case 403: - return { code: CanonicalCode.PERMISSION_DENIED }; - case 401: - return { code: CanonicalCode.UNAUTHENTICATED }; - case 429: - return { code: CanonicalCode.RESOURCE_EXHAUSTED }; - case 501: - return { code: CanonicalCode.UNIMPLEMENTED }; - case 503: - return { code: CanonicalCode.UNAVAILABLE }; - default: - return { code: CanonicalCode.UNKNOWN }; - } + } else if (statusCode === 404) { + return { code: CanonicalCode.NOT_FOUND }; + } else if (statusCode === 403) { + return { code: CanonicalCode.PERMISSION_DENIED }; + } else if (statusCode === 401) { + return { code: CanonicalCode.UNAUTHENTICATED }; + } else if (statusCode === 429) { + return { code: CanonicalCode.RESOURCE_EXHAUSTED }; + } else if (statusCode === 501) { + return { code: CanonicalCode.UNIMPLEMENTED }; + } else if (statusCode === 503) { + return { code: CanonicalCode.UNAVAILABLE }; + } else if (statusCode === 504) { + return { code: CanonicalCode.DEADLINE_EXCEEDED }; + } else if (statusCode < 500) { + return { code: CanonicalCode.INVALID_ARGUMENT }; + } else if (statusCode < 512 || statusCode === 598 || statusCode === 599) { + return { code: CanonicalCode.INTERNAL }; } + return { code: CanonicalCode.UNKNOWN }; }; /** diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index 4efaa6920d1..75353e2c212 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -280,7 +280,19 @@ describe('HttpPlugin', () => { assert.strictEqual(spans.length, 0); }); - const httpErrorCodes = [400, 401, 403, 404, 429, 501, 503, 504, 500, 505]; + const httpErrorCodes = [ + 400, + 401, + 403, + 404, + 429, + 501, + 503, + 504, + 500, + 505, + 597, + ]; for (let i = 0; i < httpErrorCodes.length; i++) { it(`should test span for GET requests with http error ${httpErrorCodes[i]}`, async () => {