|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | const coerceNaturalNumber = require('type/natural-number/coerce');
|
| 4 | +const isApiEvent = require('./is-api-event'); |
4 | 5 |
|
5 | 6 | const awsLambdaSpan = require('./sdk').traceSpans.awsLambda;
|
6 | 7 |
|
7 | 8 | module.exports = (response) => {
|
8 |
| - switch (awsLambdaSpan.tags.get('aws.lambda.event_type')) { |
9 |
| - case 'aws.apigateway.rest': |
10 |
| - case 'aws.apigatewayv2.http.v1': |
11 |
| - case 'aws.apigatewayv2.http.v2': |
12 |
| - case 'aws.lambda.url': |
13 |
| - { |
14 |
| - let statusCode = response && response.statusCode; |
15 |
| - if (statusCode == null) { |
16 |
| - awsLambdaSpan.tags.set('aws.lambda.http.error_code', 'MISSING_STATUS_CODE'); |
17 |
| - break; |
18 |
| - } |
19 |
| - if (typeof statusCode === 'string') statusCode = Number(statusCode); |
20 |
| - if ( |
21 |
| - coerceNaturalNumber(statusCode) === statusCode && |
22 |
| - statusCode >= 100 && |
23 |
| - statusCode < 600 |
24 |
| - ) { |
25 |
| - awsLambdaSpan.tags.set('aws.lambda.http.status_code', statusCode); |
26 |
| - } else { |
27 |
| - awsLambdaSpan.tags.set('aws.lambda.http.error_code', 'INVALID_STATUS_CODE'); |
28 |
| - } |
29 |
| - } |
30 |
| - break; |
31 |
| - default: |
| 9 | + if (isApiEvent()) { |
| 10 | + let statusCode = response && response.statusCode; |
| 11 | + if (statusCode == null) { |
| 12 | + awsLambdaSpan.tags.set('aws.lambda.http.error_code', 'MISSING_STATUS_CODE'); |
| 13 | + return; |
| 14 | + } |
| 15 | + if (typeof statusCode === 'string') statusCode = Number(statusCode); |
| 16 | + if (coerceNaturalNumber(statusCode) === statusCode && statusCode >= 100 && statusCode < 600) { |
| 17 | + awsLambdaSpan.tags.set('aws.lambda.http.status_code', statusCode); |
| 18 | + } else { |
| 19 | + awsLambdaSpan.tags.set('aws.lambda.http.error_code', 'INVALID_STATUS_CODE'); |
| 20 | + } |
32 | 21 | }
|
33 | 22 | };
|
0 commit comments