Skip to content

Commit 9093a98

Browse files
authored
more Span accessors, for use in Envoy's unit tests (#22)
1 parent 5e23abb commit 9093a98

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/datadog/span.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ TimePoint Span::start_time() const { return data_->start; }
7676

7777
bool Span::error() const { return data_->error; }
7878

79+
const std::string& Span::service_name() const { return data_->service; }
80+
81+
const std::string& Span::service_type() const { return data_->service_type; }
82+
83+
const std::string& Span::name() const { return data_->name; }
84+
85+
const std::string& Span::resource_name() const { return data_->resource; }
86+
7987
Optional<StringView> Span::lookup_tag(StringView name) const {
8088
if (tags::is_internal(name)) {
8189
return nullopt;

src/datadog/span.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ class Span {
106106
// Return whether this span has been marked as an error having occurred during
107107
// its extent.
108108
bool error() const;
109+
// Return the name of the service associated with this span, e.g.
110+
// "ingress-nginx-useast1".
111+
const std::string& service_name() const;
112+
// Return the type of the service associated with this span, e.g. "web".
113+
const std::string& service_type() const;
114+
// Return the name of the operation associated with the operation that this
115+
// span represents, e.g. "handle.request", "execute.query", or "healthcheck".
116+
const std::string& name() const;
117+
// Return the name of the resource associated with the operation that this
118+
// span represents, e.g. "/api/v1/info" or "select count(*) from users".
119+
const std::string& resource_name() const;
109120

110121
// Return the value of the tag having the specified `name`, or return null if
111122
// there is no such tag.

test/test_span.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ TEST_CASE(".error() and .set_error*()") {
303303
}
304304
}
305305

306-
TEST_CASE("property setters") {
306+
TEST_CASE("property setters and getters") {
307+
// Verify that modifications made by `Span::set_...` are visible both in the
308+
// corresponding getter method and in the resulting span data sent to the
309+
// collector.
307310
TracerConfig config;
308311
config.defaults.service = "testsvc";
309312
auto collector = std::make_shared<MockCollector>();
@@ -318,6 +321,7 @@ TEST_CASE("property setters") {
318321
{
319322
auto span = tracer.create_span();
320323
span.set_service_name("wobble");
324+
REQUIRE(span.service_name() == "wobble");
321325
}
322326
auto& span = collector->first_span();
323327
REQUIRE(span.service == "wobble");
@@ -327,6 +331,7 @@ TEST_CASE("property setters") {
327331
{
328332
auto span = tracer.create_span();
329333
span.set_service_type("wobble");
334+
REQUIRE(span.service_type() == "wobble");
330335
}
331336
auto& span = collector->first_span();
332337
REQUIRE(span.service_type == "wobble");
@@ -336,6 +341,7 @@ TEST_CASE("property setters") {
336341
{
337342
auto span = tracer.create_span();
338343
span.set_name("wobble");
344+
REQUIRE(span.name() == "wobble");
339345
}
340346
auto& span = collector->first_span();
341347
REQUIRE(span.name == "wobble");
@@ -345,6 +351,7 @@ TEST_CASE("property setters") {
345351
{
346352
auto span = tracer.create_span();
347353
span.set_resource_name("wobble");
354+
REQUIRE(span.resource_name() == "wobble");
348355
}
349356
auto& span = collector->first_span();
350357
REQUIRE(span.resource == "wobble");

0 commit comments

Comments
 (0)