From 2969196f086ccb5e24355caa2fa63aae734cbe05 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 11 Jan 2024 23:06:20 +0100 Subject: [PATCH] Fixes #2487 --- api/include/opentelemetry/trace/trace_flags.h | 3 +++ bazel/repository.bzl | 6 +++--- .../opentelemetry/exporters/otlp/otlp_recordable.h | 2 ++ exporters/otlp/src/otlp_recordable.cc | 7 +++++++ sdk/include/opentelemetry/sdk/trace/multi_recordable.h | 8 ++++++++ sdk/include/opentelemetry/sdk/trace/recordable.h | 6 ++++++ sdk/include/opentelemetry/sdk/trace/span_data.h | 8 ++++++++ third_party/opentelemetry-proto | 2 +- third_party_release | 2 +- 9 files changed, 39 insertions(+), 5 deletions(-) diff --git a/api/include/opentelemetry/trace/trace_flags.h b/api/include/opentelemetry/trace/trace_flags.h index 1f7bf4f9b3..a64727fed2 100644 --- a/api/include/opentelemetry/trace/trace_flags.h +++ b/api/include/opentelemetry/trace/trace_flags.h @@ -19,6 +19,7 @@ class TraceFlags final { public: static constexpr uint8_t kIsSampled = 1; + static constexpr uint8_t kIsRandom = 2; TraceFlags() noexcept : rep_{0} {} @@ -26,6 +27,8 @@ class TraceFlags final bool IsSampled() const noexcept { return rep_ & kIsSampled; } + bool IsRandom() const noexcept { return rep_ & kIsRandom; } + // Populates the buffer with the lowercase base16 representation of the flags. void ToLowerBase16(nostd::span buffer) const noexcept { diff --git a/bazel/repository.bzl b/bazel/repository.bzl index 7e09e299cf..0fde88dc5c 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -100,10 +100,10 @@ def opentelemetry_cpp_deps(): http_archive, name = "com_github_opentelemetry_proto", build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD", - sha256 = "a13a1a7b76a1f22a0ca2e6c293e176ffef031413ab8ba653a82a1dbc286a3a33", - strip_prefix = "opentelemetry-proto-1.0.0", + sha256 = "df491a05f3fcbf86cc5ba5c9de81f6a624d74d4773d7009d573e37d6e2b6af64", + strip_prefix = "opentelemetry-proto-1.1.0", urls = [ - "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.0.0.tar.gz", + "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.1.0.tar.gz", ], ) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h index 76e8856330..88e7cd91cf 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h @@ -53,6 +53,8 @@ class OtlpRecordable final : public opentelemetry::sdk::trace::Recordable void SetName(nostd::string_view name) noexcept override; + void SetTraceFlags(opentelemetry::trace::TraceFlags flags) noexcept override; + void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override; diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index a3ab4327f2..f9cee24677 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -140,6 +140,13 @@ void OtlpRecordable::SetName(nostd::string_view name) noexcept span_.set_name(name.data(), name.size()); } +void OtlpRecordable::SetTraceFlags(opentelemetry::trace::TraceFlags flags) noexcept +{ + uint32_t all_flags = flags.flags() & opentelemetry::proto::trace::v1::SPAN_FLAGS_TRACE_FLAGS_MASK; + + span_.set_flags(all_flags); +} + void OtlpRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept { proto::trace::v1::Span_SpanKind proto_span_kind = diff --git a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h index 8519591286..e8ad3ea39c 100644 --- a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h @@ -112,6 +112,14 @@ class MultiRecordable : public Recordable } } + void SetTraceFlags(opentelemetry::trace::TraceFlags flags) noexcept override + { + for (auto &recordable : recordables_) + { + recordable.second->SetTraceFlags(flags); + } + } + void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override { for (auto &recordable : recordables_) diff --git a/sdk/include/opentelemetry/sdk/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h index cb73ef5f64..f4ac53fe2e 100644 --- a/sdk/include/opentelemetry/sdk/trace/recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/recordable.h @@ -135,6 +135,12 @@ class Recordable */ virtual void SetName(nostd::string_view name) noexcept = 0; + /** + * Set the trace flags of the span. + * @param flags the flags to set + */ + virtual void SetTraceFlags(opentelemetry::trace::TraceFlags flags) noexcept = 0; + /** * Set the spankind of the span. * @param span_kind the spankind to set diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index ef2c57a092..4bd11f06ed 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -136,6 +136,8 @@ class SpanData final : public Recordable */ opentelemetry::nostd::string_view GetName() const noexcept { return name_; } + opentelemetry::trace::TraceFlags GetFlags() const noexcept { return flags_; } + /** * Get the kind of this span * @return the kind of this span @@ -273,6 +275,11 @@ class SpanData final : public Recordable name_ = std::string(name.data(), name.length()); } + void SetTraceFlags(opentelemetry::trace::TraceFlags flags) noexcept override + { + flags_ = flags; + } + void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override { span_kind_ = span_kind; @@ -306,6 +313,7 @@ class SpanData final : public Recordable opentelemetry::sdk::common::AttributeMap attribute_map_; std::vector events_; std::vector links_; + opentelemetry::trace::TraceFlags flags_; opentelemetry::trace::SpanKind span_kind_{opentelemetry::trace::SpanKind::kInternal}; const opentelemetry::sdk::resource::Resource *resource_; const InstrumentationScope *instrumentation_scope_; diff --git a/third_party/opentelemetry-proto b/third_party/opentelemetry-proto index c4dfbc51f3..4ca4f0335c 160000 --- a/third_party/opentelemetry-proto +++ b/third_party/opentelemetry-proto @@ -1 +1 @@ -Subproject commit c4dfbc51f3cd4089778555a2ac5d9bc093ed2956 +Subproject commit 4ca4f0335c63cda7ab31ea7ed70d6553aee14dce diff --git a/third_party_release b/third_party_release index 817d9b728e..7689cd8638 100644 --- a/third_party_release +++ b/third_party_release @@ -19,7 +19,7 @@ benchmark=v1.7.1 googletest=1.13.0 ms-gsl=v3.1.0-67-g6f45293 nlohmann-json=v3.11.2 -opentelemetry-proto=v1.0.0 +opentelemetry-proto=v1.1.0 opentracing-cpp=v1.6.0 prometheus-cpp=v1.1.0 vcpkg=2022.08.15