Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(otel): ExtendedTask's otel enabled status set during init#4334

Merged
schloerke merged 7 commits intomainfrom
extended_task_otel
Dec 8, 2025
Merged

fix(otel): ExtendedTask's otel enabled status set during init#4334
schloerke merged 7 commits intomainfrom
extended_task_otel

Conversation

@schloerke
Copy link
Collaborator

Summary

This PR fixes how ExtendedTask determines whether to record OpenTelemetry spans. Previously, ExtendedTask checked the OpenTelemetry collection state at invoke() time, which could lead to inconsistent behavior. Now, the OTel recording state is captured when the ExtendedTask is initialized (new()), ensuring consistent span recording behavior regardless of runtime configuration changes.

Changes

  • Fixed OTel state capture timing: ExtendedTask now captures the is_recording_otel flag at initialization time rather than checking at invocation time
  • Added comprehensive test suite: New test file test-otel-extended-task.R with 219 lines of tests covering various OTel collection scenarios
  • Improved documentation: Added "OpenTelemetry Integration" section to ExtendedTask documentation explaining the initialization-time behavior
  • Refactored test helpers: Moved mock OTel helper functions to helper-otel.R for reuse across test files

Technical Details

The key change is in R/extended-task.R:169-170, where private$is_recording_otel is now set during initialization:

# Capture this value at init-time, not run-time
private$is_recording_otel <- has_otel_collect("reactivity")

And at invocation time in R/extended-task.R:204, we now check the captured value:

if (private$is_recording_otel) {
  private$otel_span <- start_otel_span(...)
}

Test Coverage

New tests verify:

  • OTel state is captured at initialization for all collection levels (all, reactivity, session, none)
  • Runtime changes to OTel configuration don't affect already-initialized tasks
  • Spans are only created when is_recording_otel is TRUE
  • Multiple invocations use the same captured OTel state

@schloerke schloerke marked this pull request as ready for review December 8, 2025 19:05
@schloerke
Copy link
Collaborator Author

Debugged IRL w/ @elnelson575

@schloerke schloerke merged commit 05b0f27 into main Dec 8, 2025
12 checks passed
@schloerke schloerke deleted the extended_task_otel branch December 8, 2025 19:56
schloerke added a commit that referenced this pull request Dec 8, 2025
* main:
  fix(otel): ExtendedTask's otel enabled status set during init (#4334)
  feat(otel): Add `withOtelCollect()` and `localOtelCollect()` (#4333)
@schloerke schloerke mentioned this pull request Dec 8, 2025
4 tasks
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.

1 participant