Skip to content

[Draft] Add bundle version of utf8_range to validate attribute values #3512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

owent
Copy link
Member

@owent owent commented Jul 1, 2025

Fixes #3491

Changes

  • Add bundle version of utf8_range to validate attribute values

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

@Copilot Copilot AI review requested due to automatic review settings July 1, 2025 12:40
@owent owent requested a review from a team as a code owner July 1, 2025 12:40
Copy link

netlify bot commented Jul 1, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit bc84e9b
🔍 Latest deploy log https://app.netlify.com/projects/opentelemetry-cpp-api-docs/deploys/6863d736ffc44c00087c633b

Copy link

@Copilot 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 introduces a bundled UTF-8 validation library (utf8_range) and integrates it into attribute validation throughout the SDK, ensuring that span, resource, and instrumentation-scope attributes containing invalid UTF-8 are filtered out with warnings.

  • Add attribute_validity module wrapping the new utf8_range library
  • Integrate attribute validation/filtering into Span, Resource, and InstrumentationScope
  • Add build rules for utf8_range and update CMake/Bazel files accordingly

Reviewed Changes

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

Show a summary per file
File Description
sdk/src/common/internal/utf8_range/uft8_range.cc Added bundled UTF-8 validation implementation
sdk/src/common/internal/utf8_range/utf8_range.h Declared public API for UTF-8 validation (IsValid, ValidPrefix)
sdk/src/common/attribute_validity.cc Wrapped validation logic around SDK attribute values
sdk/src/common/BUILD Added utf8_range and attribute_validity libraries
sdk/src/common/CMakeLists.txt Updated to include new source in common build
sdk/src/trace/span.cc Applied attribute validation in Span::SetAttribute and AddLink
sdk/src/resource/resource.cc Applied attribute validation in Resource constructor
sdk/include/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h Applied attribute validation in instrumentation scope factories and setters
sdk/test/instrumentationscope/CMakeLists.txt Updated linkage to include opentelemetry_common
sdk/test/instrumentationscope/BUILD Added dependency on attribute_validity for tests
Comments suppressed due to low confidence (2)

sdk/src/common/internal/utf8_range/uft8_range.cc:1

  • The source file is named uft8_range.cc, which looks like a typo. Renaming it to utf8_range.cc would align with the header (utf8_range.h) and improve consistency.
// Copyright 2023 Google LLC

sdk/src/common/BUILD:6

  • The new utf8_range library adds core validation logic but there are no accompanying unit tests verifying valid and invalid UTF-8 sequences. Consider adding tests under sdk/test/common/ to cover edge cases.
cc_library(

@@ -22,7 +24,20 @@ namespace resource

Resource::Resource(const ResourceAttributes &attributes, const std::string &schema_url) noexcept
: attributes_(attributes), schema_url_(schema_url)
Copy link
Preview

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

Initializing attributes_ with the full map and then selectively re-adding valid entries in the constructor means invalid entries remain in attributes_. Consider default-initializing attributes_ empty and only inserting valid key–value pairs.

Suggested change
: attributes_(attributes), schema_url_(schema_url)
: attributes_(), schema_url_(schema_url)

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented Jul 1, 2025

Codecov Report

Attention: Patch coverage is 33.51064% with 125 lines in your changes missing coverage. Please review.

Project coverage is 88.49%. Comparing base (3b42db5) to head (bc84e9b).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
sdk/src/common/attribute_validity.cc 25.76% 49 Missing ⚠️
sdk/src/common/internal/utf8_range/uft8_range.cc 38.47% 40 Missing ⚠️
...lude/opentelemetry/sdk/common/attribute_validity.h 27.28% 24 Missing ⚠️
...y/sdk/instrumentationscope/instrumentation_scope.h 41.67% 7 Missing ⚠️
sdk/src/resource/resource.cc 66.67% 3 Missing ⚠️
sdk/src/trace/span.cc 33.34% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3512      +/-   ##
==========================================
- Coverage   89.96%   88.49%   -1.47%     
==========================================
  Files         219      222       +3     
  Lines        7051     7235     +184     
==========================================
+ Hits         6343     6402      +59     
- Misses        708      833     +125     
Files with missing lines Coverage Δ
sdk/src/trace/span.cc 87.92% <33.34%> (-1.86%) ⬇️
sdk/src/resource/resource.cc 88.24% <66.67%> (-8.06%) ⬇️
...y/sdk/instrumentationscope/instrumentation_scope.h 86.00% <41.67%> (-14.00%) ⬇️
...lude/opentelemetry/sdk/common/attribute_validity.h 27.28% <27.28%> (ø)
sdk/src/common/internal/utf8_range/uft8_range.cc 38.47% <38.47%> (ø)
sdk/src/common/attribute_validity.cc 25.76% <25.76%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Need validation/debug logs for protobuf setters
1 participant