Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff committed Jan 11, 2024
1 parent c4f39f2 commit 2969196
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/include/opentelemetry/trace/trace_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ class TraceFlags final
{
public:
static constexpr uint8_t kIsSampled = 1;
static constexpr uint8_t kIsRandom = 2;

TraceFlags() noexcept : rep_{0} {}

explicit TraceFlags(uint8_t flags) noexcept : rep_(flags) {}

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<char, 2> buffer) const noexcept
{
Expand Down
6 changes: 3 additions & 3 deletions bazel/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:/open-telemetry/opentelemetry-proto/archive/v1.0.0.tar.gz",
"https:/open-telemetry/opentelemetry-proto/archive/v1.1.0.tar.gz",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions exporters/otlp/src/otlp_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 8 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/multi_recordable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
6 changes: 6 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/recordable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/span_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -306,6 +313,7 @@ class SpanData final : public Recordable
opentelemetry::sdk::common::AttributeMap attribute_map_;
std::vector<SpanDataEvent> events_;
std::vector<SpanDataLink> links_;
opentelemetry::trace::TraceFlags flags_;
opentelemetry::trace::SpanKind span_kind_{opentelemetry::trace::SpanKind::kInternal};
const opentelemetry::sdk::resource::Resource *resource_;
const InstrumentationScope *instrumentation_scope_;
Expand Down
2 changes: 1 addition & 1 deletion third_party_release
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2969196

Please sign in to comment.