Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 1, 2025

The logs SDK previously required the trace feature to be enabled, even when only logs functionality was needed. This was unintended behavior that prevented users from using logs independently.

Problem

The issue occurred because:

  1. Logs SDK code imported trace-specific functionality (TraceContextExt) without feature guards
  2. Trace context extraction from active spans was always attempted, even when trace wasn't available
  3. The From<&SpanContext> implementation for TraceContext was always compiled

This meant that attempting to use only the logs feature would fail to compile when trace was explicitly disabled.

Solution

This PR makes the following changes:

  1. Add conditional compilation for trace imports: Wrapped trace-related imports behind #[cfg(feature = "trace")] guards
  2. Make trace context extraction conditional: The logs SDK now only attempts to extract trace context from active spans when the trace feature is enabled
  3. Guard TraceContext implementation: The From<&SpanContext> implementation is now only compiled when the trace feature is available

The workspace dependency consolidation in main already handles the default-features = false requirement, so no Cargo.toml changes were needed.

Behavior

After this change:

  • ✅ Logs SDK compiles and works correctly without the trace feature
  • ✅ Manual trace context setting works regardless of trace feature availability
  • ✅ Automatic trace context extraction from active spans works when trace feature is enabled
  • ✅ All existing functionality is preserved when both features are enabled
  • ✅ No breaking changes to existing APIs

Example

// This now works without requiring trace feature
use opentelemetry_sdk::logs::{SdkLoggerProvider, SimpleLogProcessor};
use opentelemetry::logs::{Logger, LoggerProvider, LogRecord, Severity};

let logger_provider = SdkLoggerProvider::builder()
    .build();

let logger = logger_provider.logger("my-app");
let mut log_record = logger.create_log_record();
log_record.set_severity_number(Severity::Info);
log_record.set_body("Hello, logs!".into());
logger.emit(log_record);

Fixes #3096.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 1, 2025

CLA Missing ID CLA Not Signed

- Remove default-features from opentelemetry dependency in SDK
- Conditionally compile trace context extraction in logs
- Move trace-related imports behind feature gates
- Ensure logs work without trace feature while maintaining compatibility

Co-authored-by: cijothomas <[email protected]>
Copilot AI changed the title [WIP] Logs feature requires Trace feature Fix logs feature dependency on trace feature Aug 1, 2025
Copilot AI requested a review from cijothomas August 1, 2025 17:23
Copilot finished work on behalf of cijothomas August 1, 2025 17:23
@cijothomas
Copy link
Member

@copilot please rebase from main

Copy link
Contributor Author

Copilot AI commented Aug 1, 2025

@copilot please rebase from main

Rebased successfully onto latest main (2ebde27). The rebase resolved conflicts with the workspace dependency consolidation while preserving the default-features = false fix for the logs feature.

Copilot finished work on behalf of cijothomas August 1, 2025 18:20
@cijothomas
Copy link
Member

@copilot Resolve merge conflicts. main now already has the required changes to cargo.toml so this PR can revert its change.

Copy link
Contributor Author

Copilot AI commented Aug 1, 2025

@copilot Resolve merge conflicts. main now already has the required changes to cargo.toml so this PR can revert its change.

Resolved the merge conflicts successfully. You're absolutely right - the main branch now has the workspace dependency configuration with default-features = false for opentelemetry, so I reverted the Cargo.toml changes and kept only the code changes that make trace context extraction conditional.

The solution now works by:

  1. Using the workspace dependency which already has default-features = false
  2. Applying conditional compilation #[cfg(feature = "trace")] to trace-specific code
  3. Making trace context extraction optional when trace feature is disabled

Verified with successful builds and tests:

  • ✅ Logs work without trace feature (79 unit tests pass)
  • ✅ Logs + trace work together correctly
  • ✅ All existing functionality preserved

Commit: b7282fb

Copilot finished work on behalf of cijothomas August 1, 2025 19:35
@codecov
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.1%. Comparing base (b11f04e) to head (4ef7c6f).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3097   +/-   ##
=====================================
  Coverage   80.1%   80.1%           
=====================================
  Files        126     126           
  Lines      21957   21957           
=====================================
  Hits       17603   17603           
  Misses      4354    4354           

☔ 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.

@cijothomas cijothomas closed this Aug 1, 2025
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.

Logs feature requires Trace feature

2 participants