Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit 8a6037e

Browse files
committed
Merge branch 'master' of github.com:epsagon/epsagon-node
2 parents 1fb86b1 + c0db0a8 commit 8a6037e

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/events/aws_sdk_v3.js

+53-3
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,62 @@ const DynamoDBv3EventCreator = {
293293
},
294294
};
295295

296+
const CloudWatchEventsv3EventCreator = {
297+
/**
298+
* Updates an event with the appropriate fields from an AWS CloudWatch Events command
299+
* @param {string} operation the operation we wrapped.
300+
* @param {Command} command the wrapped command
301+
* @param {proto.event_pb.Event} event The event to update the data on
302+
*/
303+
requestHandler(operation, command, event) {
304+
const parameters = command.input || {};
305+
const entry = parameters.Entries[0] || {};
306+
const resource = event.getResource();
307+
resource.setType('events');
308+
switch (operation) {
309+
case 'PutEventsCommand':
310+
resource.setName(entry.EventBusName || 'CloudWatch Events');
311+
eventInterface.addToMetadata(event, {
312+
'aws.cloudwatch.detail_type': entry.DetailType,
313+
'aws.cloudwatch.resources': entry.Resources,
314+
'aws.cloudwatch.source': entry.Source,
315+
}, {
316+
'aws.cloudwatch.detail': entry.Detail,
317+
});
318+
break;
319+
default:
320+
break;
321+
}
322+
},
323+
324+
/**
325+
* Updates an event with the appropriate fields from an AWS CloudWatch Events response
326+
* @param {string} operation the operation we wrapped.
327+
* @param {object} response The AWS.Response object
328+
* @param {proto.event_pb.Event} event The event to update the data on
329+
*/
330+
responseHandler(operation, response, event) {
331+
switch (operation) {
332+
case 'PutEventsCommand':
333+
eventInterface.addToMetadata(event, {
334+
'aws.cloudwatch.event_id': `${response.Entries[0].EventId}`,
335+
});
336+
break;
337+
338+
default:
339+
break;
340+
}
341+
},
342+
};
343+
296344
/**
297345
* a map between AWS resource names and their appropriate creator object.
298346
*/
299347
const specificEventCreators = {
300348
sns: SNSv3EventCreator,
301349
dynamodb: DynamoDBv3EventCreator,
302350
sqs: SQSv3EventCreator,
351+
eventbridge: CloudWatchEventsv3EventCreator,
303352
};
304353

305354
/**
@@ -324,13 +373,14 @@ function getOperationByCommand(command) {
324373
*/
325374
function AWSSDKv3Wrapper(wrappedFunction) {
326375
return function internalAWSSDKv3Wrapper(command) {
376+
let responsePromise = wrappedFunction.apply(this, [command]);
327377
try {
328378
const serviceIdentifier = this.config.serviceId.toLowerCase();
329379
const resourceName = '';
330380

331381
if (!(serviceIdentifier in specificEventCreators)) {
332382
// resource is not supported yet
333-
return wrappedFunction.apply(this, [command]);
383+
return responsePromise;
334384
}
335385

336386
const operation = getOperationByCommand(command);
@@ -351,7 +401,6 @@ function AWSSDKv3Wrapper(wrappedFunction) {
351401
]);
352402
awsEvent.setResource(resource);
353403

354-
let responsePromise = wrappedFunction.apply(this, [command]);
355404
specificEventCreators[serviceIdentifier].requestHandler(
356405
operation,
357406
command,
@@ -377,6 +426,7 @@ function AWSSDKv3Wrapper(wrappedFunction) {
377426
} catch (e) {
378427
tracer.addException(e);
379428
}
429+
return response;
380430
}).catch((error) => {
381431
console.log(error);
382432
try {
@@ -398,7 +448,7 @@ function AWSSDKv3Wrapper(wrappedFunction) {
398448
} catch (error) {
399449
tracer.addException(error);
400450
}
401-
return wrappedFunction.apply(this, [command]);
451+
return responsePromise;
402452
};
403453
}
404454

src/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ declare module 'epsagon' {
2323
batchSize?: number
2424
maxBatchSizeBytes?: number
2525
}): void
26-
export function label(key: string, value: string): void
26+
export function label(key: string, value: string | number | boolean): void
2727
export function unpatch(): void
2828
export function setError(error: Error): void
2929
export function setWarning(error: Error): void

0 commit comments

Comments
 (0)