1616#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_MESSAGE_H
1717
1818#include " google/cloud/pubsub/version.h"
19+ #include " absl/strings/string_view.h"
1920#include < google/pubsub/v1/pubsub.pb.h>
2021#include < chrono>
2122#include < iosfwd>
@@ -41,9 +42,10 @@ std::size_t MessageSize(pubsub::Message const&);
4142std::size_t MessageProtoSize (::google::pubsub::v1::PubsubMessage const & m);
4243// For Open Telemetry tracing only. Inserts or sets an attribute on the message.
4344void SetAttribute (std::string const & key, std::string value, pubsub::Message&);
44- // For Open Telemetry tracing only. Gets the value for a given attribute key on
45- // the message.
46- std::string GetAttribute (std::string const & key, pubsub::Message& m);
45+ // For Open Telemetry tracing only. Returns the value for a given attribute key
46+ // on the message or the null string_view when not found. Note: the string_view
47+ // is only valid for the lifetime of the corresponding message.
48+ absl::string_view GetAttribute (std::string const & key, pubsub::Message& m);
4749
4850GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
4951} // namespace pubsub_internal
@@ -133,8 +135,8 @@ class Message {
133135 friend void pubsub_internal::SetAttribute (std::string const & key,
134136 std::string value,
135137 pubsub::Message&);
136- friend std::string pubsub_internal::GetAttribute (std::string const & key,
137- pubsub::Message&);
138+ friend absl::string_view pubsub_internal::GetAttribute (std::string const & key,
139+ pubsub::Message&);
138140
139141 // / Construct `Message` objects.
140142 friend class MessageBuilder ;
0 commit comments