Skip to content

Conversation

@PerfectSlayer
Copy link
Contributor

@PerfectSlayer PerfectSlayer commented Mar 17, 2023

What Does This Do

This PR introduces the support for 128-bit TraceId.
A flag was introduced trace.128.bit.traceid.generation.enabled to generate 64-bit or 128-bit TraceIds.

Motivation

Provide better interoperability with external tracing systems.

Additional Notes

I will keep iterating on the DDTraceId API to get it smaller and cleaner as possible.
I think I can also improve cached string for ID, caching only padded representation (B3 has TraceIdWithOriginal implementation that can help with its custom format cache).

Two others issues will be filled about:

  • Improving support for Haystack 128-bit TraceId,
  • How should we handle XRay 128-bit TraceId and its timestamp (like: can we use or own format to map the e2e start time?)

And another PR is dedicated to bring 128-bit TraceId logging support: #4938

@PerfectSlayer PerfectSlayer added the tag: do not merge Do not merge changes label Mar 17, 2023
@PerfectSlayer PerfectSlayer changed the title DRAFT - Add support for 128-bit TraceId (6to7) WIP: Add support for 128-bit TraceId (6to7) Mar 17, 2023
@PerfectSlayer PerfectSlayer force-pushed the bbujon/128b-traceid-next branch 2 times, most recently from 2ac08b4 to ee8b38f Compare March 20, 2023 16:47
@PerfectSlayer PerfectSlayer added comp: core Tracer core and removed tag: do not merge Do not merge changes labels Mar 21, 2023
@PerfectSlayer PerfectSlayer marked this pull request as ready for review March 21, 2023 18:09
@PerfectSlayer PerfectSlayer requested a review from a team as a code owner March 21, 2023 18:09
@PerfectSlayer PerfectSlayer changed the title WIP: Add support for 128-bit TraceId (6to7) Add support for 128-bit TraceId (6to7) Mar 21, 2023
@PerfectSlayer PerfectSlayer force-pushed the bbujon/128b-traceid-next branch from bb627e9 to b025e32 Compare March 22, 2023 13:08
Copy link
Contributor

@bantonsson bantonsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Left some comments and ramblings. I'll get around to looking at the propagation next.

@PerfectSlayer PerfectSlayer force-pushed the bbujon/128b-traceid-next branch 4 times, most recently from ec14449 to 1de538b Compare March 24, 2023 17:30
@PerfectSlayer PerfectSlayer force-pushed the bbujon/128b-traceid-next branch 2 times, most recently from cdad9ad to 19b8601 Compare March 28, 2023 18:10
…it to 128-bit TraceId

It will prevent returning invalid TraceId when truncating 128-bit TraceId.
Having same hashcode for unequal objects can lead to performance issues.
Enable caching by default
Only B3 without padding feature and original string will have to compute hex string without cache.
@PerfectSlayer PerfectSlayer force-pushed the bbujon/128b-traceid-next branch from 8593279 to 95f05ae Compare April 3, 2023 07:10
@PerfectSlayer PerfectSlayer removed the request for review from a team April 3, 2023 10:33
@PerfectSlayer PerfectSlayer merged commit 68a05ad into master Apr 3, 2023
@PerfectSlayer PerfectSlayer deleted the bbujon/128b-traceid-next branch April 3, 2023 10:34
@github-actions github-actions bot added this to the 1.12.0 milestone Apr 3, 2023
@PerfectSlayer PerfectSlayer changed the title Add support for 128-bit TraceId (6to7) [6to7] Add support for 128-bit TraceId Apr 4, 2023
this.str = s = Long.toUnsignedString(this.lowOrderBits);
}
return s;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite sure I'm missing something here... but I'm really curious and I want to understand it, why you create an additional variable there instead of just operating with the class property? something like:

  @Override
  public String toString() {
    if (this.str == null) {
      this.str = Long.toUnsignedString(this.lowOrderBits);
    }
    return this.str;
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @odin-delrio, as the author of the original code in DDTraceId I can say that it's about helping the compiler. The javac compiler is rather dumb in the respect that it will do exactly what you tell it.
In the code in this PR, there will be one read from the str field, and one store to the str field (if it was null), while the code you proposed will have two reads from the str field no matter what (and of course one store if it was null). Local variables are free compared to objects and field access.
Yes, this will be optimized away by the JIT eventually, but being mindful of the cost of field access and method calls is ingrained in my way of thinking.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @bantonsson, thanks a lot for the detailed explanation ❤️!!! (I was not even sure if I would get a response to a random question like this, but I was reading the code and my curiosity made me raise the question).

I didn't know that reading from a field implied a higher cost than reading from a local variable, now it makes sense to me.

@LeifW
Copy link

LeifW commented Nov 20, 2024

How are we supposed to get these 128-bit TraceIds back out? The toTraceId() on OTSpanContext calls .toString() on the DDTraceId, which the Javadoc for says "Returns a 64-bit only decimal String representation of the DDTraceId".
That is - how do we get the original 128-bit hexadecimal TraceId?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants