Skip to content

refactor(common): decouple call_context.h from opentelemetry_context.h - #16557

Open
colinmoy wants to merge 1 commit into
googleapis:mainfrom
colinmoy:refactor-call-context-otel
Open

colinmoy wants to merge 1 commit into
googleapis:mainfrom
colinmoy:refactor-call-context-otel

Conversation

@colinmoy

@colinmoy colinmoy commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

google/cloud/stream_range.h includes google/cloud/internal/call_context.h, which previously included opentelemetry_context.h and transitively pulled <opentelemetry/...> headers into every translation unit using StreamRange<T>. This breaks builds that use Clang header modules and strict layering checks when OpenTelemetry headers are not modularized.

Forward-declaring opentelemetry::context::Context in call_context.h and moving CallContext/ScopedCallContext out-of-line into opentelemetry_context.cc avoids leaking OpenTelemetry headers through call_context.h.

@colinmoy
colinmoy requested review from a team as code owners October 9, 2026 21:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request moves the implementation of CallContext and ScopedCallContext from the header call_context.h to opentelemetry_context.cc to reduce header dependencies. The review feedback highlights a critical ABI and ODR violation hazard introduced by forward-declaring OpenTelemetry types with conditional preprocessor checks in a public header. To resolve this, the reviewer recommends using std::any for type-erasing OTelContext in the header, along with corresponding updates using std::any_cast and including <any> in the source file.

Comment thread google/cloud/internal/call_context.h
Comment thread google/cloud/internal/opentelemetry_context.cc
Comment thread google/cloud/internal/opentelemetry_context.cc
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.32%. Comparing base (d932dd6) to head (ae2ad1c).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
google/cloud/internal/opentelemetry_context.cc 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16557      +/-   ##
==========================================
- Coverage   92.35%   92.32%   -0.03%     
==========================================
  Files        2262     2261       -1     
  Lines      217027   217045      +18     
==========================================
- Hits       200425   200390      -35     
- Misses      16602    16655      +53     

☔ View full report in Codecov by Harness.
📢 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.

This branch was successfully deployed

1 active deployment
false — ae2ad1c4 Deployed Oct 9, 2026 by colinmoy via Save PR ref #12379
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