Skip to content

Fix: ETW span ownership lifetime#4070

Open
fmutlu68 wants to merge 7 commits into
open-telemetry:mainfrom
fmutlu68:fix-etw-span-ownership
Open

Fix: ETW span ownership lifetime#4070
fmutlu68 wants to merge 7 commits into
open-telemetry:mainfrom
fmutlu68:fix-etw-span-ownership

Conversation

@fmutlu68
Copy link
Copy Markdown
Contributor

@fmutlu68 fmutlu68 commented May 8, 2026

Fixes #3849

Changes

  • Hold shared ownership of the ETW tracer in Span to prevent dangling references
  • Update span creation to pass shared ownership
  • Testing: ./ci/do_ci.sh cmake.c++17.test

@fmutlu68 fmutlu68 changed the title Fix ETW span ownership lifetime Fix: ETW span ownership lifetime May 10, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.10%. Comparing base (3057616) to head (1f76b52).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4070   +/-   ##
=======================================
  Coverage   82.10%   82.10%           
=======================================
  Files         385      385           
  Lines       15989    15989           
=======================================
  Hits        13126    13126           
  Misses       2863     2863           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fmutlu68
Copy link
Copy Markdown
Contributor Author

Could you please have a look here ? also @ThomsonTan It passes all tests

@lalitb
Copy link
Copy Markdown
Member

lalitb commented May 21, 2026

ETW exporter is a bit different from other exporters: the tracer name maps to the ETW provider name/GUID, so creating multiple tracers for the same name is not the intended hot-path pattern. Applications should normally create one tracer per ETW provider name and reuse it for the process/component lifetime.

Because of that, I’d prefer not to fix this by adding shared_from_this()/shared_ptr ownership work to every span creation. StartSpan() is the high-throughput path for ETW. Could we instead document the intended ETW tracer reuse model and/or have TracerProvider retain created tracers so the lifetime protection is handled at setup/GetTracer() time rather than per span?

Also @ThomsonTan suggestions would be helpful, as he has more experience on this.

@fmutlu68
Copy link
Copy Markdown
Contributor Author

ETW exporter is a bit different from other exporters: the tracer name maps to the ETW provider name/GUID, so creating multiple tracers for the same name is not the intended hot-path pattern. Applications should normally create one tracer per ETW provider name and reuse it for the process/component lifetime.

Because of that, I’d prefer not to fix this by adding shared_from_this()/shared_ptr ownership work to every span creation. StartSpan() is the high-throughput path for ETW. Could we instead document the intended ETW tracer reuse model and/or have TracerProvider retain created tracers so the lifetime protection is handled at setup/GetTracer() time rather than per span?

Also @ThomsonTan suggestions would be helpful, as he has more experience on this.

Thanks for the thorough explanation, I completely agree regarding the hot-path overhead; atomic reference counting in StartSpan() is not ideal for high-throughput ETW logging. The alternative approach makes perfect sense. I will revert the shared_from_this()/shared_ptr changes on the Tracer/Span and instead have the TracerProvider retain ownership of the created Tracers (e.g., via an internal map) to ensure lifetime protection at setup/GetTracer() time. I'll push the updated implementation shortly.

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.

ETW Exporter: Crash When Ending ETW Exporter Span

3 participants