Skip to content

Generate trace IDs as ULIDs by default - #783

Merged
alexmojaki merged 20 commits into
mainfrom
uuid7
Jan 9, 2025
Merged

alexmojaki merged 20 commits into
mainfrom
uuid7

Conversation

@adriangb

@adriangb adriangb commented Jan 8, 2025 •

Copy link
Copy Markdown
Member

The idea is to use a ULID to generate trace IDs.
This has the huge benefit of making trace IDs sortable and correlated with time.
For our backend this means much faster queries and much less data to index them.

This should not cause any issues with other backends, sampling or anything else.

This is already the default for logs and has been proposed to become the default for traces.

Why not use UUID v7 or set the bits for UUID v4 compatibility?

Mainly for safety of current implementations.
Existing implementations (including the OTEL Python SDK) should expect no more than 64 bits or randomness (see here).
Using a pure ULID (80 bits of randomness) ensures compatibility, using a UUID would leave us with only 7 (contiguous lower) bytes of randomness at most.
In the future if OTEL adopts https://www.w3.org/TR/trace-context-2/#random-trace-id-flag we can revisit.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jan 8, 2025 •

Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: fec75d5
Status: ✅  Deploy successful!
Preview URL: https://6b76750d.logfire-docs.pages.dev
Branch Preview URL: https://uuid7.logfire-docs.pages.dev

View logs

@codecov

codecov Bot commented Jan 8, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (488f399) to head (fec75d5).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #783   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          137       138    +1     
  Lines        10985     11013   +28     
  Branches       780       781    +1     
=========================================
+ Hits         10985     11013   +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adriangb
adriangb requested review from alexmojaki and samuelcolvin and removed request for alexmojaki January 8, 2025 02:07
@adriangb adriangb changed the title Generate trace IDs as v7 UUIDs by default Generate trace IDs as ULIDs by default Jan 8, 2025
Comment thread tests/test_sampling.py Resolved
Comment thread tests/test_tail_sampling.py Resolved
Comment thread logfire/_internal/ulid.py Resolved
Comment thread logfire/_internal/utils.py Resolved
Comment thread tests/test_logfire.py Resolved
adriangb and others added 4 commits January 8, 2025 10:26
Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
@adriangb

adriangb commented Jan 8, 2025

Copy link
Copy Markdown
Member Author

@alexmojaki

Copy link
Copy Markdown
Contributor

The test was broken, it would always sort by the random part of the trace ID and never disambiguate by start time. Only 3.8 picked this up because f-string magic is disabled there. Otherwise the span name was always the f-string template.

@adriangb

adriangb commented Jan 8, 2025

Copy link
Copy Markdown
Member Author

The test was broken, it would always sort by the random part of the trace ID and never disambiguate by start time. Only 3.8 picked this up because f-string magic is disabled there. Otherwise the span name was always the f-string template.

Ah good call. Should have used message!

@alexmojaki
alexmojaki enabled auto-merge (squash) January 9, 2025 09:00
@alexmojaki
alexmojaki merged commit b690447 into main Jan 9, 2025
@alexmojaki
alexmojaki deleted the uuid7 branch January 9, 2025 09:29
@adriangb

adriangb commented Jan 9, 2025

Copy link
Copy Markdown
Member Author

Thanks for your help Alex!

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

Successfully merging this pull request may close these issues.

2 participants