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

fix: use the correct tracing id and attributes in logs when nested within a tracing span #2924

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SF-Zhou
Copy link

@SF-Zhou SF-Zhou commented Apr 10, 2025

Fixes #2824 and #1378.

Changes

#2438 has already extracted the trace ID and span ID information from the tracing span, but has not handled the attributes. For instance:

tracing::error_span!("outer-span", field1 = true, field2 = 233).in_scope(|| {
    tracing::error!("event");
});

in tracing::error!("event"), the body is processed, but field1 and field2 are ignored. This commit attempts to fix that issue.

Additionally, when using distributed tracing and calling set_parent to set the context, the currently obtained trace_id was incorrect. This PR also fixes this issue.

This fix has been validated in online production environments. For users with the same requirements, they can temporarily opt to use the patched opentelemetry-appender-tracing-patched crate.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@SF-Zhou SF-Zhou requested a review from a team as a code owner April 10, 2025 06:19
@SF-Zhou SF-Zhou changed the title appender-tracing: include attributes in logs when nested in tracing c… appender-tracing: include attributes in logs when nested in tracing context Apr 10, 2025
@SF-Zhou SF-Zhou changed the title appender-tracing: include attributes in logs when nested in tracing context appender-tracing: include attributes in logs when nested in tracing crate's span Apr 10, 2025
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

Attention: Patch coverage is 89.04110% with 8 lines in your changes missing coverage. Please review.

Project coverage is 81.3%. Comparing base (10cf02c) to head (55799ee).

Files with missing lines Patch % Lines
opentelemetry-appender-tracing/src/layer.rs 83.3% 8 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2924   +/-   ##
=====================================
  Coverage   81.3%   81.3%           
=====================================
  Files        126     126           
  Lines      24254   24312   +58     
=====================================
+ Hits       19736   19785   +49     
- Misses      4518    4527    +9     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SF-Zhou SF-Zhou changed the title appender-tracing: include attributes in logs when nested in tracing crate's span fix: include attributes in logs when nested in tracing crate's span Apr 10, 2025
@scottgerring
Copy link
Contributor

Hey @SF-Zhou thanks for opening the PR!
Can you give a few more details on what exactly led to this?

@SF-Zhou
Copy link
Author

SF-Zhou commented Apr 10, 2025

Hey @SF-Zhou thanks for opening the PR! Can you give a few more details on what exactly led to this?

Sure. The description of the PR has been updated.

@SF-Zhou SF-Zhou changed the title fix: include attributes in logs when nested in tracing crate's span fix: use the correct tracing id and attributes in logs when nested within a tracing span Apr 10, 2025
@SF-Zhou SF-Zhou force-pushed the patch branch 4 times, most recently from 8a40208 to 1f41d19 Compare April 12, 2025 03:13
@scottgerring
Copy link
Contributor

@bantonsson I think your eyes on this would be helpful!

@scottgerring scottgerring requested a review from bantonsson April 14, 2025 11:26
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.

[Bug]: traceId not correctly set for logs when using set_parent with opentelemetry-appender-tracing
2 participants