diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index 820fa991c9..6ebe0511aa 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -20,7 +20,7 @@ class Recordable final : public sdk::trace::Recordable const proto::trace::v1::Span &span() const noexcept { return span_; } /** Dynamically converts the resource of this span into a proto. */ - void PopulateProtoResource(proto::resource::v1::Resource *resource) const noexcept; + proto::resource::v1::Resource ProtoResource() const noexcept; void SetIdentity(const opentelemetry::trace::SpanContext &span_context, opentelemetry::trace::SpanId parent_span_id) noexcept override; diff --git a/exporters/otlp/src/otlp_exporter.cc b/exporters/otlp/src/otlp_exporter.cc index 9f96b298d4..7a1a56c26c 100644 --- a/exporters/otlp/src/otlp_exporter.cc +++ b/exporters/otlp/src/otlp_exporter.cc @@ -32,13 +32,8 @@ void PopulateRequest(const nostd::span> if (!has_resource) { - std::unique_ptr proto_resource{ - new proto::resource::v1::Resource}; - - rec->PopulateProtoResource(proto_resource.get()); - - resource_span->set_allocated_resource(proto_resource.release()); - has_resource = true; + *resource_span->mutable_resource() = rec->ProtoResource(); + has_resource = true; } } } diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index 08220f0be9..666a370574 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -216,15 +216,18 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, } } -void Recordable::PopulateProtoResource(proto::resource::v1::Resource *proto) const noexcept +proto::resource::v1::Resource Recordable::ProtoResource() const noexcept { + proto::resource::v1::Resource proto; if (resource_) { for (const auto &kv : resource_->GetAttributes()) { - PopulateAttribute(proto->add_attributes(), kv.first, kv.second); + PopulateAttribute(proto.add_attributes(), kv.first, kv.second); } } + + return proto; } void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept