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

Decimal Trace ID format in logs #4524

Open
francircle opened this issue Jul 17, 2024 · 3 comments
Open

Decimal Trace ID format in logs #4524

francircle opened this issue Jul 17, 2024 · 3 comments

Comments

@francircle
Copy link

francircle commented Jul 17, 2024

Hi team,

According to Datadog docs, the trace ID has 128 bits by default, which is equivalent to 32 hex characters like 66884212000000004443333311122222.

I am able to see traceId like this in datadog, but for my winston logger, which instrumented by using dd-trace plugin like this

tracer.use('winston', {
    enabled: true,
  });

I see the trace id in dd object is in another format, it's a 19-digit decimal string like 5295287788888597036.

After I dug in the source code in dd-trace-js, I found this piece of logic

toTraceId (get128bitId = false) {
  if (get128bitId) {
    return this._traceId.toBuffer().length <= 8 && this._trace.tags[TRACE_ID_128]
      ? this._trace.tags[TRACE_ID_128] + this._traceId.toString(16).padStart(16, '0')
      : this._traceId.toString(16).padStart(32, '0')
  }
  return this._traceId.toString(10)
}

toSpanId (get128bitId = false) {
  if (get128bitId) {
    return this._spanId.toString(16).padStart(16, '0')
  }
  return this._spanId.toString(10)
}

I saw the 19-digit decimal string is actually the lower half of trace ID in decimal format. I wonder why it returns decimal string by default instead of the 32 hex chars traceId like we see in datadog dashboard and why is the get128bitId is false by default. Is there any reason behind this? Thanks!

@francircle francircle changed the title Hexadecimal/Decimal Trace ID format conversion Decimal Trace ID format in logs Jul 17, 2024
@jaridmargolin
Copy link

I found that this can be altered by setting the environment variable DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED=true but it looks like it may contain some bugs. I just sent the following message in the Datadog slack apm chanel: https://datadoghq.slack.com/archives/C3SH3KCQG/p1722447251471329

@francircle
Copy link
Author

@jaridmargolin thanks for sharing this. What kind of bugs you encountered?

@jaridmargolin
Copy link

Datadog submitted a patch that fixed the issue I was seeing: 3e179d0

You should now be free to use DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED=true. I'm not entirely sure why it isn't exposed as a config option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants