Skip to content

[SDK] Create instrumentation scope library - #4351

Open
dbarker wants to merge 5 commits into
open-telemetry:mainfrom
dbarker:cmake_create_instrumentation_scope_target
Open

[SDK] Create instrumentation scope library#4351
dbarker wants to merge 5 commits into
open-telemetry:mainfrom
dbarker:cmake_create_instrumentation_scope_target

Conversation

@dbarker

@dbarker dbarker commented Aug 3, 2026

Copy link
Copy Markdown
Member

Contributes to #1429

This PR creates CMake and Bazel targets for the instrumentation scope library. This is an important target to provide as it supports users in linking to just what they need use the InstrumentationScope object in their projects (e.g. building custom configurators, etc.). Also supports moving SDK code out of headers and into .cc files (#1429).

With this change users can link directly to the library with:

   target_link_libraries(my_library PRIVATE opentelemetry-cpp::instrumentation_scope)

The library will also be a public transitive link provided by metrics, trace, and logs targets.

Changes

  • moves instrumentation_scope.h impl to instrumentation_scope.cc and creates library targets with CMake and Bazel

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

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.63%. Comparing base (60c3d11) to head (a8ebe1f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4351      +/-   ##
==========================================
+ Coverage   82.61%   82.63%   +0.02%     
==========================================
  Files         511      512       +1     
  Lines       20132    20140       +8     
==========================================
+ Hits        16631    16641      +10     
+ Misses       3501     3499       -2     
Files with missing lines Coverage Δ
...y/sdk/instrumentationscope/instrumentation_scope.h 100.00% <ø> (ø)
.../src/instrumentationscope/instrumentation_scope.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.

@dbarker
dbarker marked this pull request as ready for review August 3, 2026 21:18
@dbarker
dbarker requested a review from a team as a code owner August 3, 2026 21:18

Copilot AI 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.

Pull request overview

This PR introduces a standalone SDK “instrumentation scope” library target (CMake + Bazel) and moves InstrumentationScope method implementations out of the public header into a compiled .cc, enabling consumers to link only what they need and supporting the ongoing effort to shift SDK implementation into source files.

Changes:

  • Added new opentelemetry_instrumentation_scope CMake target and corresponding Bazel //sdk/src/instrumentationscope library.
  • Moved InstrumentationScope implementation from instrumentation_scope.h into instrumentation_scope.cc.
  • Made metrics/trace/logs targets depend transitively on the new instrumentation scope library and updated tests/build wiring accordingly.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/test/instrumentationscope/CMakeLists.txt Switches the test executable to link against the new instrumentation scope library target.
sdk/test/instrumentationscope/BUILD Adds Bazel deps so the instrumentation scope tests link against the new library (and related common code).
sdk/src/trace/CMakeLists.txt Adds opentelemetry_instrumentation_scope as a PUBLIC dependency of the trace SDK library.
sdk/src/trace/BUILD Adds Bazel dependency on //sdk/src/instrumentationscope for the trace SDK library.
sdk/src/metrics/CMakeLists.txt Adds opentelemetry_instrumentation_scope as a PUBLIC dependency of the metrics SDK library.
sdk/src/metrics/BUILD Adds Bazel dependency on //sdk/src/instrumentationscope for the metrics SDK library.
sdk/src/logs/CMakeLists.txt Adds opentelemetry_instrumentation_scope as a PUBLIC dependency of the logs SDK library.
sdk/src/logs/BUILD Adds Bazel dependency on //sdk/src/instrumentationscope for the logs SDK library.
sdk/src/instrumentationscope/instrumentation_scope.cc New compiled implementation of InstrumentationScope APIs previously inline in the header.
sdk/src/instrumentationscope/CMakeLists.txt New CMake target definition for opentelemetry_instrumentation_scope (with install/pkg-config support).
sdk/src/instrumentationscope/BUILD New Bazel cc_library for the instrumentation scope implementation.
sdk/src/CMakeLists.txt Adds the new instrumentationscope subdirectory to the SDK build.
sdk/include/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h Converts previously-inline methods to declarations only (implementation moved to .cc).
sdk/CMakeLists.txt Registers the new SDK component so it’s exported/installed with other SDK libraries.
CHANGELOG.md Adds a changelog entry for the new SDK instrumentation scope library target.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +4 to +8
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include <unordered_map>
#include <utility>
#include <vector>
#include "opentelemetry/nostd/variant.h"
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.

2 participants