TraceID - TypeError: Cannot read property 'FromString' of undefined
paulskipprhudson opened this issue · comments
I'm trying to generate consistent Trace ID's across lambda invocations (in and event streaming platform).
However, I'm getting and error when calling static FromString
method.
import * as AWSXray from 'aws-xray-sdk-core';
const foo = 'foo'
const bar = 'bar'
AWSXray.TraceID.FromString(`${foo}${bar}`).toString()
/**
* trace-id-test.ts:6
* AWSXray.TraceID.FromString(`${foo}${bar}`).toString()
* ^
* TypeError: Cannot read property 'FromString' of undefined
*/
and
import { TraceID } from 'aws-xray-sdk-core';
const foo = 'foo'
const bar = 'bar'
TraceID.FromString(`${foo}${bar}`).toString()
/**
* trace-id-test.ts:16
* TraceID.FromString(`${foo}${bar}`).toString()
* ^
* TypeError: Cannot read property 'FromString' of undefined
*/
As best I can tell, I'm following the implementation in the tests: https://github.com/aws/aws-xray-sdk-node/blob/master/packages/core/test-d/index.test-d.ts
Many thanks for any pointers and help!
node -v v14.19.3
aws-xray-sdk-core ^3.4.0
Looks like this is an import issue. From what I can tell at first glance there is a typo in the second code snippet that may be causing this: the ID part of TraceID should've been capitalized.
By directly importing the TraceID
class, using AWSXray.TraceID
is no longer necessary. Maybe try this?
import { TraceID } from 'aws-xray-sdk-core';
TraceID.FromString(`${timestring}${iemi}`).toString()
Sorry, that was terrible reporting from me with a copy paste error in the import.
I've corrected the initial report.