diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index 9d55dfd404..57519bad01 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -21,7 +21,16 @@ class Recordable final : public sdk::trace::Recordable void SetAttribute(nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept override; - void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override; + void AddEvent( + nostd::string_view name, + core::SystemTimestamp timestamp = core::SystemTimestamp(std::chrono::system_clock::now()), + const trace::KeyValueIterable &attributes = + trace::KeyValueIterableView>({})) noexcept override; + + void AddLink( + opentelemetry::trace::SpanContext span_context, + const trace::KeyValueIterable &attributes = + trace::KeyValueIterableView>({})) noexcept override; void SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept override; diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index 26555ea0b7..c721313ce6 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -111,11 +111,21 @@ void Recordable::SetAttribute(nostd::string_view key, } } -void Recordable::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept +void Recordable::AddEvent(nostd::string_view name, + core::SystemTimestamp timestamp, + const trace::KeyValueIterable &attributes) noexcept { auto *event = span_.add_events(); event->set_name(name.data(), name.size()); event->set_time_unix_nano(timestamp.time_since_epoch().count()); + // TODO: handle attributes +} + +void Recordable::AddLink(opentelemetry::trace::SpanContext span_context, + const trace::KeyValueIterable &attributes) noexcept +{ + (void)span_context; + (void)attributes; } void Recordable::SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept diff --git a/sdk/include/opentelemetry/sdk/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h index a2ac8984dc..489bfd5a03 100644 --- a/sdk/include/opentelemetry/sdk/trace/recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/recordable.h @@ -4,10 +4,15 @@ #include "opentelemetry/core/timestamp.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/trace/canonical_code.h" +#include "opentelemetry/trace/key_value_iterable.h" +#include "opentelemetry/trace/key_value_iterable_view.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/version.h" +#include + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -46,8 +51,23 @@ class Recordable * Add an event to a span. * @param name the name of the event * @param timestamp the timestamp of the event + * @param attributes the attributes associated with the event + */ + virtual void AddEvent( + nostd::string_view name, + core::SystemTimestamp timestamp = core::SystemTimestamp(std::chrono::system_clock::now()), + const trace_api::KeyValueIterable &attributes = + trace_api::KeyValueIterableView>({})) noexcept = 0; + + /** + * Add a link to a span. + * @param span_context the span context of the linked span + * @param attributes the attributes associated with the link */ - virtual void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept = 0; + virtual void AddLink( + opentelemetry::trace::SpanContext span_context, + const trace_api::KeyValueIterable &attributes = + trace_api::KeyValueIterableView>({})) noexcept = 0; /** * Set the status of the span. diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index ffe1db1878..47477fcaf7 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -194,9 +194,23 @@ class SpanData final : public Recordable attributes_[std::string(key)] = nostd::visit(converter_, value); } - void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override + void AddEvent( + nostd::string_view name, + core::SystemTimestamp timestamp = core::SystemTimestamp(std::chrono::system_clock::now()), + const trace_api::KeyValueIterable &attributes = + trace_api::KeyValueIterableView>({})) noexcept override { events_.push_back(SpanDataEvent(std::string(name), timestamp)); + // TODO: handle attributes + } + + void AddLink( + opentelemetry::trace::SpanContext span_context, + const trace_api::KeyValueIterable &attributes = + trace_api::KeyValueIterableView>({})) noexcept override + { + (void)span_context; + (void)attributes; } void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override