]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/opentracing-cpp/mocktracer/test/json_test.cpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / opentracing-cpp / mocktracer / test / json_test.cpp
CommitLineData
f67539c2
TL
1#include <opentracing/mocktracer/in_memory_recorder.h>
2#include <opentracing/mocktracer/json.h>
3#include <opentracing/mocktracer/tracer.h>
4#include <algorithm>
5#include <cctype>
6
7#define CATCH_CONFIG_MAIN
8#include <opentracing/catch2/catch.hpp>
9using namespace opentracing;
10using namespace mocktracer;
11
12TEST_CASE("json") {
13 auto recorder = new InMemoryRecorder{};
14 MockTracerOptions tracer_options;
15 tracer_options.recorder.reset(recorder);
16 auto tracer = std::shared_ptr<opentracing::Tracer>{
17 new MockTracer{std::move(tracer_options)}};
18
19 SpanContextData span_context_data;
20 span_context_data.trace_id = 123;
21 span_context_data.span_id = 456;
22 span_context_data.baggage = {{"b1", "v1"}, {"b2", "v2"}};
23
24 SpanData span_data;
25 span_data.span_context = span_context_data;
26 span_data.references = {{SpanReferenceType::ChildOfRef, 123, 457}};
27 span_data.operation_name = "o1";
28 span_data.start_timestamp =
29 std::chrono::system_clock::time_point{} + std::chrono::hours{51};
30 span_data.duration = std::chrono::microseconds{92};
31 span_data.tags = {{"t1", 123}, {"t2", "cat"}};
32 span_data.logs = {{span_data.start_timestamp, {{"l1", 1}, {"l2", 1.5}}}};
33 std::ostringstream oss;
34 ToJson(oss, {span_data});
35
36 std::string expected_serialization = R"(
37 [{
38 "span_context": {
39 "trace_id": "000000000000007b",
40 "span_id": "00000000000001c8",
41 "baggage": {
42 "b1": "v1",
43 "b2": "v2"
44 }
45 },
46 "references": [{
47 "reference_type": "CHILD_OF",
48 "trace_id": "000000000000007b",
49 "span_id": "00000000000001c9"
50 }],
51 "operation_name": "o1",
52 "start_timestamp": 183600000000,
53 "duration": 92,
54 "tags": {
55 "t1": 123,
56 "t2": "cat"
57 },
58 "logs": [{
59 "timestamp": 183600000000,
60 "fields": [{
61 "key": "l1",
62 "value": 1
63 }, {
64 "key": "l2",
65 "value": 1.5
66 }]
67 }]
68 }])";
69 expected_serialization.erase(
70 std::remove_if(expected_serialization.begin(),
71 expected_serialization.end(),
72 [](char c) { return std::isspace(c); }),
73 expected_serialization.end());
74
75 CHECK(oss.str() == expected_serialization);
76}