dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

tracer.extract is not being deterministic on baggage propagation unit tests

Open santunioni opened this issue 1 year ago • 3 comments

Expected behaviour

  • tracer.extract should return the correct traceId, given propagated baggage.
  • tracer.extract should be deterministic.

Look at this code. This test should pass because I am extracting the propagated baggage here by reverse engineering the way you patch the SNS Message Attributes here. I collected the message sample from a SQS subscribed to a SNS topic with raw message delivery disabled.

Actual behaviour

  • tracer.extract is not returning the correct traceId!
  • tracer.extract is not being deterministic

The test fails. Not only it fails but it fails in a non-deterministic way. Everytime I run it I receive a different traceId, which is very concerning.

I expected at least a deterministic failure if somehow I am using the library wrong, but please don't hesitate to tell me if that is the case. I would be glad to fix it or accept a PR of you fixing it.

Steps to reproduce Download the code I linked (it's open source), unmark the test as .skip and run it. You can also copy & paste if you like.

Environment

  • Operation system: macOS Ventura 13.4 (but I believe it's not applicable)
  • Node.js version: v18.16.0
  • Tracer version: 4.3.0
  • Agent version: Not applicable
  • Relevant library versions:

santunioni avatar Jun 29 '23 11:06 santunioni

I am testing in my personal library but this code is used in a critical problem for my company. It is veeeeeery critical to us to have a reliably propagated traceId because we store it in our analytics databases for fraud auditing.

santunioni avatar Jun 29 '23 11:06 santunioni

More input:

After adding more tests I see that all of them fail with the same randomly returned value: https://github.com/santunioni/dxqueue/blob/main/src/datadog/sqs-baggage-propagation.unit.ts

That indicates that datadog is creating this traceId in the test runner scope instead of extracting it from the baggage. But why?

santunioni avatar Jun 29 '23 16:06 santunioni

I decided to test in production and the baggage propagation worked as expected. Therefore there is no need for urgent intervention here.

But can you tell me why the tests fail?

santunioni avatar Jun 30 '23 00:06 santunioni