Skip to content

Commit 4ceaca3

Browse files
committed
feat: Recognize ALB events
1 parent 81d7e4a commit 4ceaca3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

node/packages/aws-lambda-sdk/instrument/lib/is-api-event.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const apiEventTypes = new Set([
77
'aws.apigatewayv2.http.v1',
88
'aws.apigatewayv2.http.v2',
99
'aws.lambda.url',
10+
'aws.elasticloadbalancing.http',
1011
]);
1112

1213
module.exports = () => apiEventTypes.has(awsLambdaSpan.tags.get('aws.lambda.event_type'));

node/packages/aws-lambda-sdk/instrument/lib/resolve-event-tags.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ const httpApiV2EventMap = [
9090
'isBase64Encoded',
9191
];
9292

93+
const albEventMap = [
94+
'path',
95+
'httpMethod',
96+
'headers',
97+
'queryStringParameters',
98+
['requestContext', ['elb']],
99+
'body',
100+
'isBase64Encoded',
101+
];
102+
93103
const sqsEventMap = [
94104
[
95105
'Records',
@@ -246,6 +256,29 @@ module.exports = (event) => {
246256
);
247257
return;
248258
}
259+
if (doesObjectMatchMap(event, albEventMap)) {
260+
// Application Load Balancer event
261+
awsLambdaSpan.tags.setMany(
262+
{
263+
event_source: 'aws.elasticloadbalancing',
264+
event_type: 'aws.elasticloadbalancing.http',
265+
},
266+
{ prefix: 'aws.lambda' }
267+
);
268+
awsLambdaSpan.tags.setMany(
269+
{
270+
method: event.httpMethod,
271+
protocol: 'http', // Not provided by ALB, yet required property
272+
host: 'unknown', // Not provided by ALB, yet required property
273+
path: event.path,
274+
query_parameter_names: Object.keys(event.queryStringParameters || {}),
275+
request_header_names: Object.keys(event.headers || {}),
276+
},
277+
{ prefix: 'aws.lambda.http' }
278+
);
279+
awsLambdaSpan.tags.set('aws.lambda.http_router.path', event.path);
280+
return;
281+
}
249282

250283
if (doesObjectMatchMap(event, sqsEventMap)) {
251284
// SQS Queue event

0 commit comments

Comments
 (0)