Files
flare/BLADE_ROOT
CHEN Feng 92a08ae18b tracing: migrate opentracing-cpp → opentelemetry-cpp (API only) (#201)
* tracing: migrate opentracing-cpp -> opentelemetry-cpp (API only)

opentracing-cpp is deprecated/superseded by OpenTelemetry. flare ships no real
tracer -- it exposes a pluggable abstraction (TracingOpsProvider / QuickerSpan /
TracingOps) over the tracing-API types, with providers plugged in by users.
Re-base that abstraction on the opentelemetry-cpp **API** (header-only, v1.27.0)
and drop opentracing-cpp from both build systems.

Scope: API only -- no SDK/exporter, so no protobuf/grpc is pulled in and the
deliberately-pinned (abseil-free) protobuf 3.21.12 stays intact. The
abstraction and the opaque `bytes tracing_context` wire format are kept; only
the types/bodies change.

Source (flare/rpc/tracing/):
- tracing_ops_provider.h: re-typed virtuals; new flare-owned SpanStartOptions
  (parent SpanContext + SpanKind + timestamps + start attrs) replacing
  opentracing::StartSpanOptions/ChildOf. Extract -> std::optional<SpanContext>.
- tracing_ops.h/.cc: span_ is nostd::shared_ptr<trace::Span>; SetAttribute/
  AddEvent/End; SpanContext is a value type; buffered ops keep flare's owning
  variant and convert to (non-owning) AttributeValue only at flush.
- framework_tags.h -> constexpr std::string_view; string_view_interop.h ->
  ToStd/ToOtel (nostd<->std). Standard-tag table is a literal allowlist;
  span.kind moves from a tag to SpanStartOptions::kind.
- Call sites rpc_channel.cc / normal_connection_handler.cc updated; rpc_meta.proto
  comment updated (wire field unchanged).
- Tests/benchmark rewritten onto a recording fake otel::trace::Span (OTel's noop
  span can't be asserted on); integration test asserts span kind via the
  provider-recorded "span.kind" instead of an opentracing tag.

Build:
- blade: BLADE_ROOT vcpkg_config gains opentelemetry-cpp; thin wrapper
  //thirdparty/opentelemetry-cpp:api (refs opentelemetry_common -- the api
  component is header-only with no .a; that lib's include dir carries the api +
  absl headers). opentracing thirdparty dir removed.
- bazel: deps.bzl http_archive for opentelemetry-cpp 1.27.0 + api-only
  bazel/opentelemetry-cpp.BUILD (header-only, bundled nostd -> no abseil);
  patch_cmds drop the archive's nested BUILDs so the api headers can be globbed.
  opentracing BUILD/patch + .bazelignore/.gitattributes entries removed.

Verified: blade and bazel both build //flare/rpc/tracing/... and pass
tracing_ops_test + integration_test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ci: bazelignore thirdparty/opentelemetry-cpp (blade BUILD)

The repo-wide `bazel build ...` job parses every BUILD file; the blade thin
wrapper thirdparty/opentelemetry-cpp/BUILD uses blade-only syntax
(vcpkg#...:lib, visibility='PUBLIC'). Add it to .bazelignore (the opentracing
entry was removed but its replacement wasn't added).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* tracing: clang-format (v15) the migrated files

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore: drop accidentally-committed .claude/ tooling files

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* doc(tracing): note provider ABI contract for OpenTelemetry nostd types

The TracingOpsProvider interface uses OpenTelemetry API types
(nostd::shared_ptr<Span>, nostd::string_view, AttributeValue) directly.
The nostd:: backing is a compile-time choice (bundled / std via
OPENTELEMETRY_STL_VERSION / abseil) and the three are mutually
incompatible types, so a provider must be built with the same
OpenTelemetry configuration as flare. flare leaves the default nostd
in place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore: gitignore .claude/ (Claude Code local tooling)

Prevents accidentally re-committing .claude/settings*.json (cf. review
comments on PR #201).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* tracing: address PR #201 review follow-ups (non-blocking)

- forcibly_sampled now routes `flare.sampling_priority` through the
  provider's `SetFrameworkTag` translation (before `IsSampled`) instead of
  a raw `SetAttribute`, keeping the `flare.`-prefixed tag consistent with
  every other framework tag and letting providers honor the force-sample
  signal. Add `ext::kSamplingPriority`.
- An empty log key (single-arg `AddTracingLog`) now materializes as the
  default event name "log" so backends that group/display by event name
  don't render a blank one; document the per-log-event mapping.
- Guard `QuickerValue`'s reliance on P0608R3 (C++20) with a static_assert
  so a future standard downgrade can't silently bind `const char*` to bool.
- Reset `DummySpan`'s inline-static tags/logs at the start of the recording
  test so assertions can't observe leftovers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 00:36:01 +08:00

221 lines
9.9 KiB
Plaintext

global_config(
duplicated_source_action='error',
# Per-test wall timeout for normal hardware. Slower runners scale up via
# the `--test-timeout-multiplier` CLI flag (see .github/workflows/...).
# Profiled on M2 (release/-O2): the slowest tests today are CPU-heavy
# ones around 30-40s, all already exclusive=True so they don't fight
# for cores. 60s gives ~50% headroom over the slowest legit test;
# anything blowing past that is almost certainly hung.
test_timeout=60, # In seconds
glob_error_severity='error',
legacy_public_targets=load_value('build/blade/legacy_public_targets.conf'),
)
cc_test_config(
# `initial-exec` TLS does not work quite well on ppc64le if dynamic linking
# is used.
dynamic_link=lambda blade: not blade.build_type_is_debug()
and blade.cc_toolchain.target_arch != 'ppc64le',
# Doesn't work quite right on AArch64. (It does work on ppc64le, though.)
#
# Stacktrace suggests that it's related to global initialization order
# fiasco.
heap_check=lambda blade: (
'strict' if blade.cc_toolchain.target_arch != 'aarch64' else ''
),
gperftools_libs='thirdparty/gperftools:tcmalloc',
# On macOS pthread is part of libSystem and auto-linked; '#pthread' here
# would produce "ld: warning: ignoring duplicate libraries: '-lpthread'"
# on every cc_test. Restrict to Linux.
gtest_libs=lambda blade: ['thirdparty/googletest:gtest'] + (
['#pthread'] if blade.cc_toolchain.target_os == 'linux' else []),
gtest_main_libs=['thirdparty/googletest:gtest_main'],
pprof_path='thirdparty/gperftools/bin/pprof',
)
cc_config(
cppflags=lambda blade: [
'-gdwarf-2',
'-mcx16' if blade.cc_toolchain.target_arch == 'x86_64' else '',
'-fno-var-tracking',
'-gno-column-info',
# vcpkg's glog 0.7 headers require consumers to opt into the export
# macros (CMake config does this automatically; we consume headers
# directly). Defining it pulls in <glog/export.h> so the header's
# "included correctly" guard passes. Harmless for non-glog TUs.
'-DGLOG_USE_GLOG_EXPORT',
],
cflags='-std=gnu11',
cxxflags=lambda blade: [
'-std=gnu++2a',
# This option must be applied here. Options applied in `warnings` are
# not applied to generated source files (e.g., those generated by
# `protoc`.). In practice, `-Wpsabi` produces some diagnostics when
# compiling `.pb.cc` on ppc64le, this option suppress those diagnostics.
'-Wno-psabi' if blade.cc_toolchain.target_arch == 'ppc64le' else '',
],
# NOTE: Please keep all warnings in order in one same group.
warnings=[
'-Werror',
'-Wall',
'-Wextra',
# other useful warnings
'-Warray-bounds',
'-Wchar-subscripts',
'-Wcomment',
'-Wendif-labels',
'-Wformat',
# '-Wframe-larger-than=69632', # A 64k buffer and other small vars
'-Wmissing-include-dirs',
'-Wmultichar',
'-Wparentheses',
'-Wpointer-arith',
'-Wreturn-type',
'-Wsequence-point',
'-Wswitch',
'-Wunused-function',
'-Wunused-label',
'-Wunused-result',
'-Wunused-value',
'-Wwrite-strings',
# Suppress all warnings which we can't handle or are misreported.
# Even if some them are sure useful, too many warnings also overwhelm
# the true problems.
'-Wno-format-truncation',
'-Wno-float-equal',
# '-Wno-incompatible-pointer-types',
# Causes too many 'note's when it is disabled due to the size of the code
'-Wno-misleading-indentation',
'-Wno-missing-field-initializers',
'-Wno-sign-compare',
'-Wno-strict-aliasing',
'-Wno-unused-but-set-variable',
'-Wno-unused-local-typedefs',
'-Wno-unused-parameter',
],
# C++ only warning flags
cxx_warnings=[
'-Wnon-virtual-dtor',
'-Woverloaded-virtual',
# Suppress all warnings which we can't handle or are misreported.
'-Wno-deprecated',
'-Wno-invalid-offsetof',
],
extra_incs=lambda blade: [
# for all thirdparty packages
'thirdparty/',
'%s/thirdparty/' % blade.workspace.build_dir,
],
linkflags=(
lambda blade: [
# We need this in some platforms for `link_all_symbols=True` to work.
'-Wl,--no-as-needed',
'-lpthread',
]
if blade.cc_toolchain.target_os == 'linux'
else []
),
benchmark_libs=['//thirdparty/benchmark:benchmark'],
benchmark_main_libs=['//thirdparty/benchmark:benchmark_main'],
allowed_undeclared_hdrs=load_value('build/blade/allowed_undeclared_hdrs.conf'),
# header_inclusion_dependencies = True,
# TODO: (chen3feng): Upgrade to error in the future.
# I have to suppress these checks in the mac port changes due to the blade
# improvement triggered too much new reports.
hdr_dep_missing_severity='notice',
unused_deps_severity='notice',
)
cc_binary_config(
run_lib_paths=['//thirdparty/jdk/lib'],
)
cc_library_config(
generate_dynamic=True,
deterministic=True,
thin=lambda blade: blade.cc_toolchain.target_os == 'linux',
prebuilt_libpath_pattern='lib${bits}',
hdrs_missing_severity='error',
hdrs_missing_suppress=load_value('build/blade/hdrs_missing_suppress.conf'),
)
proto_library_config(
# protoc + libprotobuf from vcpkg (pinned to 3.21.12, the last abseil-free
# protobuf). vcpkg#protobuf resolves to the protoc blade installs, so the
# generated code matches the linked runtime.
protoc='vcpkg#protobuf',
protobuf_libs=['vcpkg#protobuf:protobuf'],
protobuf_path='',
protobuf_incs=[],
protoc_direct_dependencies=True,
# well_known_protos left empty: blade auto-discovers the google/protobuf/*
# protos from the vcpkg#protobuf include tree (blade-build#1339), so the list
# stays correct across protobuf versions without hand-maintenance here.
well_known_protos=[],
)
# vcpkg-provided third-party libraries (issue blade-build#1236). Hands-on
# migration of thirdparty/ libs to vcpkg; consumers keep using //thirdparty/X:Y
# (those BUILD files are thin wrappers over vcpkg#port:lib). Versions are pinned
# to match the previously vendored sources.
vcpkg_config(
baseline = '06a7fdd564234908731c59ac46a624f808e87b1c',
# root is intentionally unset: blade reads $VCPKG_ROOT, else finds `vcpkg` on
# PATH (CI relies on the runner's preinstalled vcpkg). Don't hardcode a path.
# linkage defaults to 'auto' (static for static-link consumers, shared on
# demand for dynamic-link ones), so process-global singletons -- protobuf's
# descriptor pool, the gflags/glog/gtest registries -- resolve to one shared
# instance across all dylibs with no annotation. Only non-default choices are
# called out below; see doc/*/build_rules/vcpkg.md for the linkage rules.
packages = {
# 3.21.12: the last protobuf before v22 made Abseil a hard dependency;
# flare predates the descriptor name()->string_view change (v23+).
'protobuf': {'version': '3.21.12'},
'fmt': '7.1.3',
# link_all_symbols: the static-link protoc plugins (dynamic_link=False)
# whole-archive the .a so gflags/glog's flag-registration static
# initializers run even when unreferenced.
'gflags': {'version': '2.2.2', 'link_all_symbols': True},
# GFLAGS_NOTHREADS=OFF dodges gflags-config.cmake's static-target template
# bug (glog's find_package(gflags) would ask for gflags_nothreads_static).
'glog': {'version': '0.7.1', 'link_all_symbols': True,
'cmake_options': ['-DGFLAGS_NOTHREADS=OFF']},
# include_prefix: flare includes these as "<lib>/<header>", but vcpkg
# ships their headers at the include/ top level.
'zlib': {'include_prefix': 'zlib'},
'lz4': {'include_prefix': 'lz4'},
'zstd': {'include_prefix': 'zstd'},
# snappy also needs RTTI on -- vcpkg forces -fno-rtti, but flare uses RTTI
# on snappy::Sink/Source.
'snappy': {'include_prefix': 'snappy',
'cmake_options': ['-DSNAPPY_WITH_RTTI=ON']},
'xxhash': {'include_prefix': 'xxhash'},
# link_all_symbols: consumers need yaml-cpp's symbols whole-archived in.
'yaml-cpp': {'link_all_symbols': True},
# 1.7.1: 1.8.0 deprecated DoNotOptimize(const&), which flare's
# *_benchmark.cc use under gcc -Werror=deprecated-declarations.
# linkage='static': google/benchmark has no shared build and needs none
# (each *_benchmark exe links it once); the default 'auto' would fail
# trying to build it shared.
'benchmark': {'version': '1.7.1', 'linkage': 'static'},
# vcpkg port name is `gtest`; 1.17.0 matches the previously vendored source.
'gtest': {'version': '1.17.0'},
# The curl cluster (#179). vcpkg has no openssl 1.1.1, so this upgrades to
# 3.x; flare's crypto/init code is adapted (io/util/openssl.cc drops the
# obsolete 1.0.x init/threading/ENGINE ceremony -- auto-init + thread-safe
# since 1.1; base/crypto's low-level MD5/SHA/HMAC compile with
# -Wno-deprecated-declarations, still valid until OpenSSL 4.0). All three
# use vcpkg's native include/<lib>/ layout (no include_prefix).
'openssl': {},
'nghttp2': {},
# curl: openssl TLS + nghttp2 http2 (zlib auto-detected from the install).
'curl': {'features': ['openssl', 'http2']},
# opentelemetry-cpp API for distributed tracing (replaces the vendored
# opentracing-cpp). Default features only -> no exporters, so no
# protobuf/grpc pulled in (keeps the abseil-free protobuf 3.21.12 pin
# intact). It pulls abseil + nlohmann-json, which coexist fine. flare
# consumes only the header-only `opentelemetry_api` target.
'opentelemetry-cpp': {},
},
)