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 021bbbb commit 2a5e3bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
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 2a5e3bb

Please sign in to comment.