Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot read properties of undefined (reading 'toString')" when calling getTraceHeaders() #482

Closed
midu-git opened this issue Feb 2, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@midu-git
Copy link

midu-git commented Feb 2, 2024

Expected Behavior

Calling getTraceHeaders() should not error out and provide trace headers correctly.

Actual Behavior

We are using this guy from a lambda called on the s3 middleware. At least in some situations, we encounter this error

{
    errorType: "TypeError",
    errorMessage: "Cannot read properties of undefined (reading 'toString')",
    stack: [
        "TypeError: Cannot read properties of undefined (reading 'toString')",
        "    at TraceContextService.get (/opt/nodejs/node_modules/datadog-lambda-js/trace/trace-context-service.js:87:93)",
        "    at TraceListener.get (/opt/nodejs/node_modules/datadog-lambda-js/trace/listener.js:76:40)",
        "    at getTraceHeaders (/opt/nodejs/node_modules/datadog-lambda-js/index.js:363:33)",
        "    at injectDatadogHeadersIntoS3 (/shared/src/utils/tracing-utils.ts:71:28)",
        "    at next (/shared/src/utils/s3-utils.ts:219:17)",
        "    at <anonymous> (/node_modules/@smithy/middleware-apply-body-checksum/dist-cjs/applyMd5BodyChecksumMiddleware.js:29:12)",
        "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
    ],
};

We have identified the error to this code

public sampleMode(): number {
  return this.spanContext._sampling?.priority;
}

Basically, you allow a number to be returned, but it should be number | undefined.

Steps to Reproduce the Problem

Specifications

  • Datadog Lambda Layer version: layer:Datadog-Node18-x:105
  • Node version: 18

Stacktrace

      "TypeError: Cannot read properties of undefined (reading 'toString')",
      "    at TraceContextService.get (/opt/nodejs/node_modules/datadog-lambda-js/trace/trace-context-service.js:87:93)",
      "    at TraceListener.get (/opt/nodejs/node_modules/datadog-lambda-js/trace/listener.js:76:40)",
      "    at getTraceHeaders (/opt/nodejs/node_modules/datadog-lambda-js/index.js:363:33)",
      "    at injectDatadogHeadersIntoS3 (/shared/src/utils/tracing-utils.ts:71:28)",
      "    at next (/shared/src/utils/s3-utils.ts:219:17)",
      "    at <anonymous> (/node_modules/@smithy/middleware-apply-body-checksum/dist-cjs/applyMd5BodyChecksumMiddleware.js:29:12)",
      "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",

@duncanista duncanista added the bug Something isn't working label Feb 5, 2024
@duncanista
Copy link
Contributor

Hey @midu-git,

Thanks for reporting this!
It seems that back in the past, we were ALWAYS setting AUTO_KEEP (1), after we added W3C support, we started using whatever the user had. So now, we'll just mark to AUTO_KEEP when no sampling is found.

I created a PR for this, and will follow up as things progress!

@duncanista duncanista self-assigned this Feb 7, 2024
@astuyve
Copy link
Contributor

astuyve commented Feb 21, 2024

This should be fixed in v8.106.

@astuyve astuyve closed this as completed Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants