Skip to content

Centralize shared OpenTelemetry code into source/extensions/common/opentelemetry/#44379

Open
mmorel-35 wants to merge 2 commits intoenvoyproxy:mainfrom
mmorel-35:common/opentelemetry
Open

Centralize shared OpenTelemetry code into source/extensions/common/opentelemetry/#44379
mmorel-35 wants to merge 2 commits intoenvoyproxy:mainfrom
mmorel-35:common/opentelemetry

Conversation

@mmorel-35
Copy link
Copy Markdown
Contributor

Centralizes shared OpenTelemetry types, utilities, and exporters into source/extensions/common/opentelemetry/, aligning the directory structure and naming conventions with opentelemetry-cpp.

Changes Made

SDK structure (mirrors opentelemetry-cpp)

  • Added sdk/common/types.h with a shared AttributeValue variant type (Sdk::Common namespace) and #include <cstdint>
  • Added sdk/trace/constants.h, sdk/logs/constants.h, and sdk/metrics/constants.h with per-signal OTLP service method and HTTP endpoint constants (Sdk::Trace, Sdk::Logs, Sdk::Metrics namespaces) — avoids empty placeholder files and provides real utility, mirroring the approach in Centralize OpenTelemetry Constants and Helpers in source/extensions/common/opentelemetry #41011

Exporters

  • Moved OTLP trace exporter (gRPC + HTTP) to exporters/otlp/ under Exporters::Otlp namespace; original tracer headers retained as forwarding/compat headers
  • Added exporters/otlp/environment.h/cc with Exporters::Otlp::GetUserAgent() — mirrors GetOtlpDefaultUserAgent() from opentelemetry-cpp's otlp_environment.h; used by both gRPC and HTTP exporters as it is an exporter identity concern, not HTTP-specific

Attribute utilities (mirrors opentelemetry-cpp)

  • Moved populate_attribute_utils.h/cc to exporters/otlp/ under Exporters::Otlp namespace — mirrors OtlpPopulateAttributeUtils from opentelemetry-cpp, which lives alongside the OTLP exporters
  • Renamed getStringKeyValue()makeKeyValue()
  • otlp_utils.h / otlp_utils_lib kept as backward-compatibility forwarding shims with using OtlpUtils = PopulateAttributeUtils
  • Fixed populateAnyValue() to handle all 17 AttributeValue alternatives, including array types for bool/int/uint/int64/double/uint64/bytes (previously fell into IS_ENVOY_BUG); uint64 values exceeding INT64_MAX are now clamped rather than silently wrapping to negative

Cross-extension dependency fix

  • stat_sinks/open_telemetry/open_telemetry_http_impl.cc now depends on common/opentelemetry directly instead of access_loggers/open_telemetry
  • Updated grpc_trace_exporter.cc, grpc_access_log_impl.cc, and open_telemetry_impl.cc to consume the new sdk/{trace,logs,metrics}/constants.h rather than inline string literals

Type safety & correctness

  • Added resource_spans_size() / scope_spans_size() guards in logExportedSpans() to prevent out-of-bounds proto access
  • OtelAttributes changed from std::map to absl::flat_hash_map; compile-time static_assert added to test

Tests & docs

  • Moved populate_attribute_utils_test.cc to test/extensions/common/opentelemetry/exporters/otlp/ to mirror source layout
  • Split tests into ExporterEnvironmentTest + PopulateAttributeUtilsTest; renamed test cases to match new API names (MakeKeyValue, GetUserAgent)
  • Added #include <type_traits>, #include "absl/strings/match.h" to tests
  • Updated README.md to document new API names and locations (PopulateAttributeUtils in exporters/otlp/, Exporters::Otlp::GetUserAgent(), environment_lib, and the new sdk/{trace,logs,metrics}_constants_lib targets)
  • Updated changelog

@mmorel-35 mmorel-35 changed the title Centralize shared OpenTelemetry code into `source/extensions/common/o… Centralize shared OpenTelemetry code into source/extensions/common/opentelemetry/ Apr 10, 2026
@mmorel-35
Copy link
Copy Markdown
Contributor Author

/cc @kyessenov

It's based on #41011 , hopefully the comments you've already provided are addressed there.

…pentelemetry/`

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

fix: correct clang-format issues and add opentelemetry changelog entry
@mmorel-35 mmorel-35 force-pushed the common/opentelemetry branch from b7e8cc7 to e6ab146 Compare April 13, 2026 19:00
@mmorel-35 mmorel-35 marked this pull request as ready for review April 13, 2026 19:02
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