X-Ray segment longer than lambda function execution time
- Dominant language
- JavaScript
- Stars
- 280
- Forks
- 157
- PR merge metrics
- No merged PRs in 30d
Description
We have a serverless typescript lambda function which makes API calls to other APIs.
We are using the aws-xray-sdk to instrument downstream API calls that are made with axios.
Currently using version 3.3.3 of the SDK.
We are seeing the execution time of those downstream API calls as substantially higher that the actual lambda function execution time and the downstream APIs does not see a lambda execution time corresponding to this execution time.
In the example below the API call is listed as 1.06 seconds execution time but the function only executed for 275ms.
What could be causing this discrepancy?

Cloudwatch log message also show 269 ms execution time.
```
REPORT RequestId: 1bd3866d-a4ff-4d12-9e42-8fddc98853a4 Duration: 268.37 ms Billed Duration: 269 ms Memory Size: 512 MB Max Memory Used: 138 MB
XRAY TraceId: 1-6163f603-7b02f3fd233c022a431a11d1 SegmentId: 6c8548f51f835b8b Sampled: true
```
Code snippets for the implementation of tracing.
```
import express from 'express';
import AWSXRay from 'aws-xray-sdk';
import { AxiosRequestConfig } from 'axios';
import Redis from '@libs/cache/cache';
import InstrumentedCache from '@libs/cache/instrumentedCache';
import serverlessExpress from '@vendia/serverless-express';
const http = require('http');
const https = require('https');
AWSXRay.captureHTTPsGlobal(http, false);
AWSXRay.captureHTTPsGlobal(https, false);
AWSXRay.capturePromise();
const axiosConfig: AxiosRequestConfig = {
httpAgent: new http.Agent(),
httpsAgent: new https.Agent(),
};
```
```
app.use(AWSXRay.express.openSegment('mc-moderation-api'));
app.use(connectToCache(instrumentedRedis));
app.use(disconnectFromCache(instrumentedRedis));
app.use('/', router);
app.disable('x-powered-by');
app.use(AWSXRay.express.closeSegment());
app.use(unknownRouteHandler);
app.use(unexpectedErrorHandler);
```
Contributor guide
Assessment
This issue has not been assessed yet.