|
1 | 1 | #pragma once
|
2 | 2 |
|
| 3 | +#include <cstdint> |
| 4 | + |
3 | 5 | #include "opentelemetry/core/timestamp.h"
|
| 6 | +#include "opentelemetry/nostd/string_view.h" |
| 7 | +#include "opentelemetry/trace/canonical_code.h" |
4 | 8 |
|
5 | 9 | namespace opentelemetry
|
6 | 10 | {
|
7 | 11 | namespace trace
|
8 | 12 | {
|
| 13 | +enum class SpanKind |
| 14 | +{ |
| 15 | + kInternal, |
| 16 | + kServer, |
| 17 | + kClient, |
| 18 | + kProducer, |
| 19 | + kConsumer, |
| 20 | +}; |
9 | 21 | /**
|
10 |
| - * StartSpanOptions provides options to set properties of span at the time of starting a new span. |
| 22 | + * StartSpanOptions provides options to set properties of a Span at the time of its creation |
11 | 23 | */
|
12 | 24 | struct StartSpanOptions
|
13 | 25 | {
|
14 |
| - // Sets the start time of a span. |
| 26 | + // Optionally sets the start time of a Span. |
15 | 27 | //
|
16 |
| - // If the start time of a span is set, timestamps from both the system clock and steady clock |
17 |
| - // should be provided. |
| 28 | + // If the start time of a Span is set, timestamps from both the system clock and steady clock |
| 29 | + // must be provided. |
18 | 30 | //
|
19 |
| - // Timestamps from the steady clock can be used to most accurately measure a span's |
20 |
| - // duration, while timestamps from the system clock can be used to most accurately place a span's |
21 |
| - // time point relative to other spans collected across a distributed system. |
| 31 | + // Timestamps from the steady clock can be used to most accurately measure a Span's |
| 32 | + // duration, while timestamps from the system clock can be used to most accurately place a Span's |
| 33 | + // time point relative to other Spans collected across a distributed system. |
22 | 34 | core::SystemTimestamp start_system_time;
|
23 | 35 | core::SteadyTimestamp start_steady_time;
|
| 36 | + |
| 37 | + // TODO: |
| 38 | + // Span(Context?) parent; |
| 39 | + // SpanContext remote_parent; |
| 40 | + // Links |
| 41 | + // Attributes |
| 42 | + SpanKind kind = SpanKind::kInternal; |
24 | 43 | };
|
25 | 44 |
|
26 | 45 | class Tracer;
|
27 | 46 |
|
28 | 47 | /**
|
29 |
| - * A span represents a single operation within a trace. |
| 48 | + * A Span represents a single operation within a Trace. |
30 | 49 | */
|
31 | 50 | class Span
|
32 | 51 | {
|
33 | 52 | public:
|
| 53 | + // Note that Spans should be created using the Tracer class. Please refer to |
| 54 | + // tracer.h for documentation. |
| 55 | + Span() = default; |
| 56 | + |
| 57 | + // The Span destructor End()s the Span, if it hasn't been ended already. |
34 | 58 | virtual ~Span() = default;
|
35 | 59 |
|
| 60 | + // Not copiable or movable. |
| 61 | + Span(const Span &) = delete; |
| 62 | + Span(Span &&) = delete; |
| 63 | + Span &operator=(const Span &) = delete; |
| 64 | + Span &operator=(Span &&) = delete; |
| 65 | + |
| 66 | + // TODO |
| 67 | + // Sets an attribute on the Span. If the Span previously contained a mapping for |
| 68 | + // the key, the old value is replaced. |
| 69 | + // |
| 70 | + // If an empty string is used as the value, the attribute will be silently |
| 71 | + // dropped. Note: this behavior could change in the future. |
| 72 | + // virtual void SetAttribute(nostd::string_view key, AttributeValue&& value) = 0; |
| 73 | + |
| 74 | + // Adds an event to the Span. |
| 75 | + virtual void AddEvent(nostd::string_view name) noexcept = 0; |
| 76 | + |
| 77 | + // Adds an event to the Span, with a custom timestamp. |
| 78 | + virtual void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept = 0; |
| 79 | + virtual void AddEvent(nostd::string_view name, core::SteadyTimestamp timestamp) noexcept = 0; |
| 80 | + |
| 81 | + // TODO |
| 82 | + // Adds an event to the Span, with a custom timestamp, and attributes. |
| 83 | + // virtual void AddEvent(nostd::string_view name, core::SteadyTimestamp |
| 84 | + // timestamp, nostd::span<const std::pair<nostd::string_view name, AttributeValue |
| 85 | + // value>> attributes) noexcept = 0; |
| 86 | + |
| 87 | + // Sets the status of the span. The default status is OK. Only the value of the last call will be |
| 88 | + // recorded, and implementations are free to ignore previous calls. |
| 89 | + virtual void SetStatus(CanonicalCode code, nostd::string_view description) noexcept = 0; |
| 90 | + |
| 91 | + // Updates the name of the Span. If used, this will override the name provided |
| 92 | + // during creation. |
| 93 | + virtual void UpdateName(nostd::string_view name) noexcept = 0; |
| 94 | + |
| 95 | + // Mark the end of the Span. Only the timing of the first End call for a given Span will |
| 96 | + // be recorded, and implementations are free to ignore all further calls. |
| 97 | + virtual void End() noexcept = 0; |
| 98 | + |
| 99 | + // TODO |
| 100 | + // virtual void End(EndSpanOptions&& opts) noexcept = 0; |
| 101 | + |
| 102 | + // TODO |
| 103 | + // SpanContext context() const noexcept = 0; |
| 104 | + |
| 105 | + // Returns true if this Span is recording tracing events (e.g. SetAttribute, |
| 106 | + // AddEvent). |
| 107 | + virtual bool IsRecording() const noexcept = 0; |
| 108 | + |
36 | 109 | virtual Tracer &tracer() const noexcept = 0;
|
37 | 110 | };
|
38 | 111 | } // namespace trace
|
|
0 commit comments