summaryrefslogtreecommitdiffstats
path: root/contrib/libs/opentelemetry-cpp/api/include/opentelemetry/trace/default_span.h
blob: a6e7b1d6b835bc7bed57d1dc9f3148df81abd084 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{

/**
 * DefaultSpan provides a non-operational Span that propagates
 * the tracer context by wrapping it inside the Span object.
 */

class DefaultSpan : public Span
{
public:
  ~DefaultSpan() noexcept override = default;

  // Returns an invalid span.
  static DefaultSpan GetInvalid() { return DefaultSpan(SpanContext::GetInvalid()); }

  trace::SpanContext GetContext() const noexcept override { return span_context_; }

  bool IsRecording() const noexcept override { return false; }

  void SetAttribute(nostd::string_view /* key */,
                    const common::AttributeValue & /* value */) noexcept override
  {}

  void AddEvent(nostd::string_view /* name */) noexcept override {}

  void AddEvent(nostd::string_view /* name */,
                common::SystemTimestamp /* timestamp */) noexcept override
  {}

  void AddEvent(nostd::string_view /* name */,
                const common::KeyValueIterable & /* attributes */) noexcept override
  {}

  void AddEvent(nostd::string_view /* name */,
                common::SystemTimestamp /* timestamp */,
                const common::KeyValueIterable & /* attributes */) noexcept override
  {}

#if OPENTELEMETRY_ABI_VERSION_NO >= 2
  void AddLink(const SpanContext & /* target */,
               const common::KeyValueIterable & /* attrs */) noexcept override
  {}

  void AddLinks(const SpanContextKeyValueIterable & /* links */) noexcept override {}
#endif

  void SetStatus(StatusCode /* status */, nostd::string_view /* description */) noexcept override {}

  void UpdateName(nostd::string_view /* name */) noexcept override {}

  void End(const EndSpanOptions & /* options */) noexcept override {}

  nostd::string_view ToString() const noexcept { return "DefaultSpan"; }

  DefaultSpan(SpanContext span_context) noexcept : span_context_(std::move(span_context)) {}

  // movable and copiable
  DefaultSpan(const DefaultSpan &other) noexcept : span_context_(other.span_context_) {}

  DefaultSpan &operator=(const DefaultSpan &other) noexcept
  {
    if (this == &other)
    {
      return *this;
    }
    span_context_ = other.span_context_;
    return *this;
  }

  DefaultSpan(DefaultSpan &&other) noexcept : span_context_(std::move(other.span_context_)) {}

  DefaultSpan &operator=(DefaultSpan &&other) noexcept
  {
    if (this == &other)
    {
      return *this;
    }
    span_context_ = std::move(other.span_context_);
    return *this;
  }

private:
  SpanContext span_context_;
};

}  // namespace trace
OPENTELEMETRY_END_NAMESPACE