1

I have been trying to incorporate AWS Xray in an API written in Typescript with HAPI framework. I have been using Hapi Xray plugin to append segment property to be appended on Request Object. On doing this, I am able to see the xray traces being logged correctly which looks like this

] UDP message sent: {"trace_id":"1-5dd03512-d121706a724d3ef4d680d613","id":"3ce8baf950c74044","start_time":1573926161.723,"name":"myAPI Name","service":{"runtime":"node","runtime_version":"v10.16.0","version":"1.10.1","name":"my-api"},"aws":{"ecs":{"container":"cf95a5a8b538"},"xray":{"sdk":"X-Ray for Node.js","sdk_version":"2.4.0","package":"aws-xray-sdk"}},"origin":"AWS::ECS::Container","http":{"request":{"method":"GET","user_agent":"PostmanRuntime/7.19.0","client_ip":"172.29.0.1","url":"http://localhost:8080/myapi/urlParam"}},"annotations":{"SegmentName":"otherData"},"end_time":1573926161.816}

But in this process, I am seeing this error.

2019-11-16 12:42:41.957 -05:00 [ERROR] Error: No sub/segment specified. A sub/segment must be provided for manual mode.
    at Object.contextMissingLogError [as contextMissing] (/app/node_modules/aws-xray-sdk-core/lib/context_utils.js:26:19)
    at Object.resolveSegment (/app/node_modules/aws-xray-sdk-core/lib/context_utils.js:77:43)
    at features.constructor.captureAWSRequest [as customRequestHandler] (/app/node_modules/aws-xray-sdk-core/lib/patchers/aws_p.js:66:29)
    at features.constructor.addAllRequestListeners (/app/node_modules/aws-sdk/lib/service.js:279:34)
    at features.constructor.makeRequest (/app/node_modules/aws-sdk/lib/service.js:203:10)
    at features.constructor.svc.(anonymous function) [as getItem] (/app/node_modules/aws-sdk/lib/service.js:673:23)
    at DocumentClient.makeServiceRequest (/app/node_modules/aws-sdk/lib/dynamodb/document_client.js:97:42)
    at DocumentClient.get (/app/node_modules/aws-sdk/lib/dynamodb/document_client.js:263:17)
    at DatabaseClient.get (/app/rocket-db/build/DatabaseClient.js:31:36)

Has someone else seen something like this? Any help would be appreciated.

1 Answers1

0

It appears you're using manual mode and not passing a reference to an active segment or subsegment when making requests to an instrumented AWS client. I'd recommend either using automatic mode so you don't have to worry about manually passing segment references around, which can get tedious when making AWS calls.

If you have a strong preference for manual mode, see these docs. You must make all requests to instrumented AWS Clients with an additional key-value pair in your params, where the key is Semgent and the value is a reference to an active segment or subsegment.

William Armiros
  • 267
  • 1
  • 10