Skip to content

Commit

Permalink
feat(plugin-http): sync. specs for statuscode
Browse files Browse the repository at this point in the history
closes open-telemetry#642

Signed-off-by: Olivier Albertini <[email protected]>
  • Loading branch information
OlivierAlbertini committed Jan 22, 2020
1 parent 8496fb2 commit 0639737
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/opentelemetry-plugin-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
Expand Down
44 changes: 20 additions & 24 deletions packages/opentelemetry-plugin-http/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,28 @@ export const getAbsoluteUrl = (
export const parseResponseStatus = (
statusCode: number
): Omit<Status, 'message'> => {
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 };
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 0639737

Please sign in to comment.