Skip to content

Commit 77723e4

Browse files
committed
existing tests now compiling and passing again
1 parent 1d4a168 commit 77723e4

File tree

6 files changed

+105
-193
lines changed

6 files changed

+105
-193
lines changed

src/datadog/tracer_config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Expected<std::vector<PropagationStyle>> parse_propagation_styles(
7878

7979
const auto dupe =
8080
std::find(styles.begin(), styles.end() - 1, styles.back());
81-
if (dupe == styles.end()) {
81+
if (dupe == styles.end() - 1) {
8282
return nullopt; // no duplicate
8383
}
8484

src/datadog/tracer_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct TracerConfig {
6363
// All styles indicated by `injection_styles` are used for injection.
6464
// `injection_styles` is overridden by the `DD_TRACE_PROPAGATION_STYLE_INJECT`
6565
// and `DD_TRACE_PROPAGATION_STYLE` environment variables.
66-
std::vector<PropagationStyle> injection_styles;
66+
std::vector<PropagationStyle> injection_styles = {PropagationStyle::DATADOG};
6767

6868
// `extraction_styles` indicates with which tracing systems trace propagation
6969
// will be compatible when extracting (receiving) trace context.
@@ -73,7 +73,7 @@ struct TracerConfig {
7373
// `extraction_styles` is overridden by the
7474
// `DD_TRACE_PROPAGATION_STYLE_EXTRACT` and `DD_TRACE_PROPAGATION_STYLE`
7575
// environment variables.
76-
std::vector<PropagationStyle> extraction_styles;
76+
std::vector<PropagationStyle> extraction_styles = {PropagationStyle::DATADOG};
7777

7878
// `report_hostname` indicates whether the tracer will include the result of
7979
// `gethostname` with traces sent to the collector.

test/span.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,7 @@ TEST_CASE("injection") {
375375
config.defaults.service = "testsvc";
376376
config.collector = std::make_shared<MockCollector>();
377377
config.logger = std::make_shared<MockLogger>();
378-
config.injection_styles.datadog = true;
379-
config.injection_styles.b3 = true;
380-
config.injection_styles.none = false;
378+
config.injection_styles = {PropagationStyle::DATADOG, PropagationStyle::B3};
381379

382380
auto finalized_config = finalize_config(config);
383381
REQUIRE(finalized_config);
@@ -455,9 +453,7 @@ TEST_CASE("injection can be disabled using the \"none\" style") {
455453
config.defaults.name = "spanny";
456454
config.collector = std::make_shared<MockCollector>();
457455
config.logger = std::make_shared<MockLogger>();
458-
config.injection_styles.datadog = false;
459-
config.injection_styles.b3 = false;
460-
config.injection_styles.none = true; // this one
456+
config.injection_styles = {PropagationStyle::NONE};
461457

462458
const auto finalized_config = finalize_config(config);
463459
REQUIRE(finalized_config);

test/test.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
#pragma once
2+
13
#define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
24
#define CATCH_CONFIG_CPP17_STRING_VIEW
35
#define CATCH_CONFIG_CPP17_VARIANT
46
#define CATCH_CONFIG_CPP17_OPTIONAL
57
#define CATCH_CONFIG_CPP17_BYTE
68

9+
#include <datadog/expected.h>
10+
711
#include <iosfwd>
812
#include <string>
913
#include <utility>
@@ -16,3 +20,18 @@ std::ostream& operator<<(std::ostream& stream,
1620
const std::pair<const std::string, std::string>& item);
1721

1822
} // namespace std
23+
24+
namespace datadog {
25+
namespace tracing {
26+
27+
template <typename Value>
28+
std::ostream& operator<<(std::ostream& stream,
29+
const Expected<Value>& expected) {
30+
if (expected) {
31+
return stream << "?"; // don't know in general
32+
}
33+
return stream << expected.error();
34+
}
35+
36+
} // namespace tracing
37+
} // namespace datadog

test/tracer.cpp

Lines changed: 28 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -259,155 +259,82 @@ TEST_CASE("span extraction") {
259259
SECTION("extraction failures") {
260260
struct TestCase {
261261
std::string name;
262-
bool extract_datadog;
263-
bool extract_b3;
262+
std::vector<PropagationStyle> extraction_styles;
264263
std::unordered_map<std::string, std::string> headers;
265264
// Null means "don't expect an error."
266265
Optional<Error::Code> expected_error;
267266
};
268267

269268
auto test_case = GENERATE(values<TestCase>({
270-
{"no span", true, false, {}, Error::NO_SPAN_TO_EXTRACT},
269+
{"no span", {PropagationStyle::DATADOG}, {}, Error::NO_SPAN_TO_EXTRACT},
271270
{"missing trace ID",
272-
true,
273-
false,
271+
{PropagationStyle::DATADOG},
274272
{{"x-datadog-parent-id", "456"}},
275273
Error::MISSING_TRACE_ID},
276274
{"missing parent span ID",
277-
true,
278-
false,
275+
{PropagationStyle::DATADOG},
279276
{{"x-datadog-trace-id", "123"}},
280277
Error::MISSING_PARENT_SPAN_ID},
281278
{"missing parent span ID, but it's ok because origin",
282-
true,
283-
false,
279+
{PropagationStyle::DATADOG},
284280
{{"x-datadog-trace-id", "123"}, {"x-datadog-origin", "anything"}},
285281
nullopt},
286-
{"datadog and B3 agree",
287-
true,
288-
true,
289-
{{"x-datadog-trace-id", "15"},
290-
{"x-b3-traceid", "f"},
291-
{"x-datadog-parent-id", "14"},
292-
{"x-b3-spanid", "e"}},
293-
nullopt},
294-
{"datadog and B3 disagree on trace ID",
295-
true,
296-
true,
297-
{{"x-datadog-trace-id", "15"},
298-
{"x-b3-traceid", "f0"},
299-
{"x-datadog-parent-id", "14"},
300-
{"x-b3-spanid", "e"}},
301-
Error::INCONSISTENT_EXTRACTION_STYLES},
302-
{"datadog and B3 disagree on trace ID (2)",
303-
true,
304-
true,
305-
{{"x-datadog-trace-id", "15"},
306-
{"x-datadog-parent-id", "14"},
307-
{"x-b3-spanid", "e"}},
308-
Error::INCONSISTENT_EXTRACTION_STYLES},
309-
{"datadog and B3 disagree on parent ID",
310-
true,
311-
true,
312-
{{"x-datadog-trace-id", "15"},
313-
{"x-b3-traceid", "f"},
314-
{"x-datadog-parent-id", "13"},
315-
{"x-b3-spanid", "e"}},
316-
Error::INCONSISTENT_EXTRACTION_STYLES},
317-
{"datadog and B3 disagree on parent ID (2)",
318-
true,
319-
true,
320-
{{"x-datadog-trace-id", "15"},
321-
{"x-b3-traceid", "f"},
322-
{"x-datadog-parent-id", "13"}},
323-
Error::INCONSISTENT_EXTRACTION_STYLES},
324-
{"datadog and B3 disagree on sampling priority",
325-
true,
326-
true,
327-
{{"x-datadog-trace-id", "15"},
328-
{"x-b3-traceid", "f"},
329-
{"x-datadog-parent-id", "14"},
330-
{"x-b3-spanid", "e"},
331-
{"x-datadog-sampling-priority", "2"},
332-
{"x-b3-sampled", "1"}},
333-
Error::INCONSISTENT_EXTRACTION_STYLES},
334-
{"datadog and B3 disagree on sampling priority (2)",
335-
true,
336-
true,
337-
{{"x-datadog-trace-id", "15"},
338-
{"x-b3-traceid", "f"},
339-
{"x-datadog-parent-id", "14"},
340-
{"x-b3-spanid", "e"},
341-
{"x-datadog-sampling-priority", "2"}},
342-
Error::INCONSISTENT_EXTRACTION_STYLES},
343282
{"bad x-datadog-trace-id",
344-
true,
345-
false,
283+
{PropagationStyle::DATADOG},
346284
{{"x-datadog-trace-id", "f"}, {"x-datadog-parent-id", "456"}},
347285
Error::INVALID_INTEGER},
348286
{"bad x-datadog-trace-id (2)",
349-
true,
350-
false,
287+
{PropagationStyle::DATADOG},
351288
{{"x-datadog-trace-id", "99999999999999999999999999"},
352289
{"x-datadog-parent-id", "456"}},
353290
Error::OUT_OF_RANGE_INTEGER},
354291
{"bad x-datadog-parent-id",
355-
true,
356-
false,
292+
{PropagationStyle::DATADOG},
357293
{{"x-datadog-parent-id", "f"}, {"x-datadog-trace-id", "456"}},
358294
Error::INVALID_INTEGER},
359295
{"bad x-datadog-parent-id (2)",
360-
true,
361-
false,
296+
{PropagationStyle::DATADOG},
362297
{{"x-datadog-parent-id", "99999999999999999999999999"},
363298
{"x-datadog-trace-id", "456"}},
364299
Error::OUT_OF_RANGE_INTEGER},
365300
{"bad x-datadog-sampling-priority",
366-
true,
367-
false,
301+
{PropagationStyle::DATADOG},
368302
{{"x-datadog-parent-id", "123"},
369303
{"x-datadog-trace-id", "456"},
370304
{"x-datadog-sampling-priority", "keep"}},
371305
Error::INVALID_INTEGER},
372306
{"bad x-datadog-sampling-priority (2)",
373-
true,
374-
false,
307+
{PropagationStyle::DATADOG},
375308
{{"x-datadog-parent-id", "123"},
376309
{"x-datadog-trace-id", "456"},
377310
{"x-datadog-sampling-priority", "99999999999999999999999999"}},
378311
Error::OUT_OF_RANGE_INTEGER},
379312
{"bad x-b3-traceid",
380-
false,
381-
true,
313+
{PropagationStyle::B3},
382314
{{"x-b3-traceid", "0xdeadbeef"}, {"x-b3-spanid", "def"}},
383315
Error::INVALID_INTEGER},
384316
{"bad x-b3-traceid (2)",
385-
false,
386-
true,
317+
{PropagationStyle::B3},
387318
{{"x-b3-traceid", "ffffffffffffffffffffffffffffff"},
388319
{"x-b3-spanid", "def"}},
389320
Error::OUT_OF_RANGE_INTEGER},
390321
{"bad x-b3-spanid",
391-
false,
392-
true,
322+
{PropagationStyle::B3},
393323
{{"x-b3-spanid", "0xdeadbeef"}, {"x-b3-traceid", "def"}},
394324
Error::INVALID_INTEGER},
395325
{"bad x-b3-spanid (2)",
396-
false,
397-
true,
326+
{PropagationStyle::B3},
398327
{{"x-b3-spanid", "ffffffffffffffffffffffffffffff"},
399328
{"x-b3-traceid", "def"}},
400329
Error::OUT_OF_RANGE_INTEGER},
401330
{"bad x-b3-sampled",
402-
false,
403-
true,
331+
{PropagationStyle::B3},
404332
{{"x-b3-traceid", "abc"},
405333
{"x-b3-spanid", "def"},
406334
{"x-b3-sampled", "true"}},
407335
Error::INVALID_INTEGER},
408336
{"bad x-b3-sampled (2)",
409-
false,
410-
true,
337+
{PropagationStyle::B3},
411338
{{"x-b3-traceid", "abc"},
412339
{"x-b3-spanid", "def"},
413340
{"x-b3-sampled", "99999999999999999999999999"}},
@@ -416,8 +343,7 @@ TEST_CASE("span extraction") {
416343

417344
CAPTURE(test_case.name);
418345

419-
config.extraction_styles.datadog = test_case.extract_datadog;
420-
config.extraction_styles.b3 = test_case.extract_b3;
346+
config.extraction_styles = test_case.extraction_styles;
421347
auto finalized_config = finalize_config(config);
422348
REQUIRE(finalized_config);
423349
Tracer tracer{*finalized_config};
@@ -449,8 +375,7 @@ TEST_CASE("span extraction") {
449375
SECTION("extracted span has the expected properties") {
450376
struct TestCase {
451377
std::string name;
452-
bool extract_datadog;
453-
bool extract_b3;
378+
std::vector<PropagationStyle> extraction_styles;
454379
std::unordered_map<std::string, std::string> headers;
455380
std::uint64_t expected_trace_id;
456381
Optional<std::uint64_t> expected_parent_id;
@@ -459,47 +384,41 @@ TEST_CASE("span extraction") {
459384

460385
auto test_case = GENERATE(values<TestCase>({
461386
{"datadog style",
462-
true,
463-
false,
387+
{PropagationStyle::DATADOG},
464388
{{"x-datadog-trace-id", "123"},
465389
{"x-datadog-parent-id", "456"},
466390
{"x-datadog-sampling-priority", "2"}},
467391
123,
468392
456,
469393
2},
470394
{"datadog style without sampling priority",
471-
true,
472-
false,
395+
{PropagationStyle::DATADOG},
473396
{{"x-datadog-trace-id", "123"}, {"x-datadog-parent-id", "456"}},
474397
123,
475398
456,
476399
nullopt},
477400
{"datadog style without sampling priority and without parent ID",
478-
true,
479-
false,
401+
{PropagationStyle::DATADOG},
480402
{{"x-datadog-trace-id", "123"}, {"x-datadog-origin", "whatever"}},
481403
123,
482404
nullopt,
483405
nullopt},
484406
{"B3 style",
485-
false,
486-
true,
407+
{PropagationStyle::B3},
487408
{{"x-b3-traceid", "abc"},
488409
{"x-b3-spanid", "def"},
489410
{"x-b3-sampled", "0"}},
490411
0xabc,
491412
0xdef,
492413
0},
493414
{"B3 style without sampling priority",
494-
false,
495-
true,
415+
{PropagationStyle::B3},
496416
{{"x-b3-traceid", "abc"}, {"x-b3-spanid", "def"}},
497417
0xabc,
498418
0xdef,
499419
nullopt},
500420
{"Datadog and B3 style together",
501-
true,
502-
true,
421+
{PropagationStyle::DATADOG, PropagationStyle::B3},
503422
{{"x-datadog-trace-id", "255"},
504423
{"x-datadog-parent-id", "14"},
505424
{"x-datadog-sampling-priority", "0"},
@@ -510,8 +429,7 @@ TEST_CASE("span extraction") {
510429
14,
511430
0},
512431
{"Datadog and B3 style together without sampling priority",
513-
true,
514-
true,
432+
{PropagationStyle::DATADOG, PropagationStyle::B3},
515433
{{"x-datadog-trace-id", "255"},
516434
{"x-datadog-parent-id", "14"},
517435
{"x-b3-traceid", "ff"},
@@ -523,8 +441,7 @@ TEST_CASE("span extraction") {
523441

524442
CAPTURE(test_case.name);
525443

526-
config.extraction_styles.datadog = test_case.extract_datadog;
527-
config.extraction_styles.b3 = test_case.extract_b3;
444+
config.extraction_styles = test_case.extraction_styles;
528445
auto finalized_config = finalize_config(config);
529446
REQUIRE(finalized_config);
530447
Tracer tracer{*finalized_config};
@@ -553,9 +470,7 @@ TEST_CASE("span extraction") {
553470
}
554471

555472
SECTION("extraction can be disabled using the \"none\" style") {
556-
config.extraction_styles.datadog = false;
557-
config.extraction_styles.b3 = false;
558-
config.extraction_styles.none = true; // this one
473+
config.extraction_styles = {PropagationStyle::NONE};
559474

560475
const auto finalized_config = finalize_config(config);
561476
REQUIRE(finalized_config);

0 commit comments

Comments
 (0)