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

Use tracing library to generate spans #918

Merged
merged 12 commits into from
Mar 3, 2025
Merged

Conversation

joshwlewis
Copy link
Member

@joshwlewis joshwlewis commented Feb 27, 2025

Alternative to #917 -- personally, I prefer this one. This sets up tracing so that it emits trace data into our opentelemetry file exporter pipeline while correctly honoring the cascade of events from kodon, through libcnb, and buildpack specific spans.

Using tracing for recording span data in CNBs looks like this:

{
  // This span will be nested within libcnb.rs-generated span
  let _span_guard = tracing::span!(Level::INFO, "download-go", version = go_version).entered();
  do_the_download();
  // This event will be affiliated with the 'download-go' span
  tracing::event!(Level::INFO, "downloaded");
}
// The _span_guard is out of scope, so the 'download-go' span is ended

tracing is a widely used library, even within libraries. This seems like the more rust-like approach. #917 by comparison is the more opentelemetry-like approach and closer to that standard.

As an added bonus the tracing library automatically adds code.lineno, code.filepath, code.namespace attributes to spans and events.

There are some changes to the shape of the tracing data - some span names, some attributes have changed. Most of this is because we are accepting tracing-opentelemetry conventions.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@joshwlewis joshwlewis added enhancement New feature or request libcnb labels Feb 27, 2025
@colincasey
Copy link
Contributor

Ooh, I like this more than #917.

@joshwlewis joshwlewis marked this pull request as ready for review March 3, 2025 18:26
@joshwlewis joshwlewis requested a review from a team as a code owner March 3, 2025 18:26
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

Thank you! I really like the approach of using the tracing crate - it seems this will be easier for individual language CNBs to adopt :-)

@joshwlewis joshwlewis merged commit 93fa8b6 into main Mar 3, 2025
4 checks passed
@joshwlewis joshwlewis deleted the jwl/tracing-opentelemetry branch March 3, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request libcnb
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants