Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. //inside aws console
  2.  
  3. const { datadog } = __webpack_require__(416);
  4. const tracer = __webpack_require__(1172);
  5. const openTracing = __webpack_require__(13);
  6.  
  7. let awsXRay = __webpack_require__(94);
  8.  
  9. let activityTracer = tracer.init({service: 'activity_writer_lambda', env: 'beta', analytics: true});
  10.  
  11. const bulkIndex = activityTracer.wrap("bulkIndex", (client, data) => {
  12. let activeSpan = activityTracer.scope().active();
  13. activeSpan.setOperationName("lambda-test-danny");
  14. const bulkBody = [];
  15. const insert_time = new Date().getTime();
  16.  
  17. if (isDebugMode) {
  18. console.log('Batch to send to E.S : ' + JSON.stringify(data));
  19. }
  20.  
  21. //some logic
  22.  
  23. data.forEach(item => {
  24.  
  25. bulkBody.push({
  26.  
  27. index: {
  28. _index: indexFieldsResolver.getIndexName(item),
  29. _type: 'all',
  30. _id: indexFieldsResolver.getId(item)
  31. }
  32.  
  33. });
  34.  
  35. const activity = indexFieldsResolver.convertActivity(item);
  36. activity.insert_time = insert_time;
  37. bulkBody.push(activity);
  38.  
  39. });
  40.  
  41. data.forEach(item => {
  42. console.info('**********************************************************')
  43. activeSpan.setTag('activity.id', item.activityId);
  44. console.info('-----------------------------' + activeSpan);
  45. awsXRay.captureFunc("AI-beta-elasticsearch-activities-writer", (subsegment) => {
  46. subsegment.addMetadata('id', item.activityId, 'activity');
  47.  
  48. });
  49.  
  50. });
  51.  
  52. }
  53.  
  54. })
  55.  
  56. […] //rest of function
  57.  
  58. }
  59.  
  60. function EsBulkIndexer() {
  61.  
  62. return {
  63.  
  64. index: index
  65.  
  66. };
  67.  
  68. async function index(client, records) {
  69. return bulkIndex(client, records); //function we trace
  70. }
  71. }
  72.  
  73. module.exports = datadog((event, context, callback) => {
  74.  
  75. EsBulkIndexer();
  76.  
  77. }, {mergeDatadogXrayTraces: true, apiKey: <api_key>});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement