Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

Changes

The user-defined constructor in BatchSpanProcessorOptions made it a non-aggregate type, breaking C++20 designated initializers:

// This stopped working after the constructor was added
BatchSpanProcessorOptions{
    .max_queue_size = 100,
    .schedule_delay_millis = std::chrono::milliseconds(200),
    .max_export_batch_size = 50
}

Solution: Remove the constructor and use default member initializers with helper functions declared in header and defined in .cc files:

  • Add helper functions in nested namespace (e.g., batch_span_processor_options_env) declared with OPENTELEMETRY_EXPORT in header and defined in .cc file (fixes Windows single DLL build)
  • Use default member initializers calling these helper functions (restores aggregate status)
  • Fix incorrect default values: max_queue_size 2084→2048, export_timeout 3000ms→30000ms (aligns with OTel spec)
  • Apply the same pattern to BatchLogRecordProcessorOptions for consistency
  • Add comprehensive documentation explaining aggregate initialization behavior and environment variable defaults

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed
Original prompt

This section details on the original issue you should resolve

<issue_title>Batch span processor env variables breaks C++20 aggregate initialization</issue_title>
<issue_description>@marcalff @nikhilbhatia08, this PR breaks a bunch of existing code without providing a sensible alternative.

Prior to that we were using the following syntax using C++20 aggregate initialization:

 auto processor = otel::BatchSpanProcessorFactory::Create(
            std::move(exporter),
            otel::BatchSpanProcessorOptions{
                .max_queue_size = config.batch().max_queue_size(),
                .schedule_delay_millis = std::chrono::milliseconds(config.batch().schedule_delay().MilliSeconds()),
                .max_export_batch_size = config.batch().max_export_batch_size(),
            }
        );

Originally posted by @georgthegreat in #3661 (comment)

Solution - I believe the issue comes from adding a user-defined constructor, which means BatchSpanProcessorOptions is no longer an aggregate type. That disables C++20 designated initializers, so patterns like .max_queue_size = ... stop working even though they worked earlier.
We can fix this by removing the constructor and using default member initializers along with a small set of static helper functions for the environment variable logic. This restores aggregate initialization while keeping the original behavior intact.
</issue_description>

<agent_instructions>Solution - I believe the issue comes from adding a user-defined constructor, which means BatchSpanProcessorOptions is no longer an aggregate type. That disables C++20 designated initializers, so patterns like .max_queue_size = ... stop working even though they worked earlier.
We can fix this by removing the constructor and using default member initializers along with a small set of static helper functions for the environment variable logic. This restores aggregate initialization while keeping the original behavior intact.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 4, 2025 23:45
…on support

- Remove user-defined constructor that prevented C++20 designated initializers
- Add inline helper functions in batch_span_processor_options_env namespace
- Use default member initializers calling the helper functions
- Update tests with corrected default values (2048 for max_queue_size, 30000ms for export_timeout)
- Add test for aggregate initialization and C++20 designated initializers

Co-authored-by: lalitb <[email protected]>
Co-authored-by: lalitb <[email protected]>
Copilot AI changed the title [WIP] Fix batch span processor env variables for C++20 Fix BatchSpanProcessorOptions to restore C++20 aggregate initialization support Dec 4, 2025
Copilot AI requested a review from lalitb December 4, 2025 23:54
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.93%. Comparing base (ef71364) to head (e069099).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3780      +/-   ##
==========================================
+ Coverage   89.91%   89.93%   +0.02%     
==========================================
  Files         225      225              
  Lines        7165     7163       -2     
==========================================
- Hits         6442     6441       -1     
+ Misses        723      722       -1     
Files with missing lines Coverage Δ
sdk/src/logs/batch_log_record_processor_options.cc 100.00% <100.00%> (ø)
sdk/src/trace/batch_span_processor_options.cc 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

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

@georgthegreat
Copy link

@copilot, I suggest these commits to be squashed to avoid storing accidentally committed junk like forever.

1 similar comment
@lalitb
Copy link
Member

lalitb commented Dec 5, 2025

@copilot, I suggest these commits to be squashed to avoid storing accidentally committed junk like forever.

Copy link
Contributor Author

Copilot AI commented Dec 5, 2025

@copilot, I suggest these commits to be squashed to avoid storing accidentally committed junk like forever.

I'm unable to squash commits directly since that requires force pushing, which I don't have access to. However, this can be handled when merging by using GitHub's "Squash and merge" option, which will combine all commits into a single clean commit.

@lalitb
Copy link
Member

lalitb commented Dec 5, 2025

@copilot - please fix these:

23 | inline constexpr const char *kMaxQueueSizeEnv = "OTEL_BSP_MAX_QUEUE_SIZE";

do not use inline variables in C++14.

Move constants inside inline functions to avoid using inline variables
which are a C++17 feature not available in C++14.

Co-authored-by: lalitb <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 5, 2025

@copilot - please fix these:

23 | inline constexpr const char *kMaxQueueSizeEnv = "OTEL_BSP_MAX_QUEUE_SIZE";...

Fixed in 100ed3b. Moved constants inside inline functions instead of using inline constexpr variables, which are a C++17 feature.

@lalitb lalitb requested a review from Copilot December 6, 2025 04:41
@lalitb lalitb marked this pull request as ready for review December 6, 2025 04:41
@lalitb lalitb requested a review from a team as a code owner December 6, 2025 04:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a regression in BatchSpanProcessorOptions where a user-defined constructor broke C++20 designated initializers (aggregate initialization). The solution removes the constructor and uses default member initializers with inline helper functions to preserve environment variable reading behavior while restoring aggregate type status.

Key changes:

  • Refactored BatchSpanProcessorOptions to be an aggregate type compatible with C++20 designated initializers
  • Moved environment variable reading logic to inline functions in a new batch_span_processor_options_env namespace
  • Corrected default values: max_queue_size (2084→2048) and export_timeout (3000ms→30000ms) to align with OpenTelemetry spec

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
sdk/include/opentelemetry/sdk/trace/batch_span_processor_options.h Removed constructor, added inline helper functions in batch_span_processor_options_env namespace, converted to aggregate type with default member initializers
sdk/src/trace/batch_span_processor_options.cc Emptied file (kept for ABI compatibility) with explanatory comment
sdk/test/trace/batch_span_processor_test.cc Updated default value tests (2048, 30000ms), added new tests for aggregate initialization and C++20 designated initializers
.gitignore Added CodeQL build artifacts (unrelated to main PR purpose)

@marcalff
Copy link
Member

marcalff commented Dec 6, 2025

See comments in #3778 (comment)

This change has implications for the single dll, and for file configuration.

@lalitb
Copy link
Member

lalitb commented Dec 7, 2025

@copilot - the changes in this PR seems to be breaking the windows with single dll. Please do the changes as suggested below:

estore aggregate initialization by:

  1. Remove the constructor declaration from the header files
  2. Add helper functions in a nested namespace (e.g., batch_span_processor_options_env) that are:
  • Declared in the header with [OPENTELEMETRY_EXPORT]
  • Defined in the .cc file (NOT inlined in header)
  1. Use default member initializers that call these helper functions

Files to modify:

  • batch_span_processor_options.h
  • batch_span_processor_options.cc
  • batch_log_record_processor_options.h
  • batch_log_record_processor_options.cc
  • batch_span_processor_test.cc (update expected default values: max_queue_size=2048, export_timeout=30000ms)

- Move env helper function implementations from header to .cc files
- Declare helper functions with OPENTELEMETRY_EXPORT in header
- Apply the same pattern to BatchLogRecordProcessorOptions
- Add comprehensive documentation to both options structs
- Fix "to to" typo in BatchSpanProcessorOptions documentation

This fixes the Windows single DLL build issue by avoiding inline
functions in header files that are called from default member
initializers.

Co-authored-by: lalitb <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot - the changes in this PR seems to be breaking the windows with single dll. Please do the changes as suggested below:

...

Fixed in e069099. Moved helper function implementations to .cc files with OPENTELEMETRY_EXPORT declarations in headers. Applied the same pattern to BatchLogRecordProcessorOptions as well.

Copilot AI changed the title Fix BatchSpanProcessorOptions to restore C++20 aggregate initialization support Fix BatchSpanProcessorOptions and BatchLogRecordProcessorOptions to restore C++20 aggregate initialization support Dec 7, 2025
@marcalff marcalff changed the title Fix BatchSpanProcessorOptions and BatchLogRecordProcessorOptions to restore C++20 aggregate initialization support [SDK] Fix BatchSpanProcessorOptions and BatchLogRecordProcessorOptions to restore C++20 aggregate initialization support Dec 9, 2025
@marcalff marcalff merged commit 179e4b0 into main Dec 9, 2025
131 checks passed
@marcalff marcalff deleted the copilot/fix-batch-processor-initialization branch December 9, 2025 07:57
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.

Batch span processor env variables breaks C++20 aggregate initialization

4 participants