1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #include "opentelemetry/common/attribute_value.h"
6 #include "opentelemetry/trace/canonical_code.h"
7 #include "opentelemetry/trace/span.h"
8 #include "opentelemetry/trace/span_context.h"
10 OPENTELEMETRY_BEGIN_NAMESPACE
15 * DefaultSpan provides a non-operational Span that propagates
16 * the tracer context by wrapping it inside the Span object.
19 class DefaultSpan
: public Span
22 // Returns an invalid span.
23 static DefaultSpan
GetInvalid() { return DefaultSpan(SpanContext::GetInvalid()); }
25 trace::SpanContext
GetContext() const noexcept
{ return span_context_
; }
27 bool IsRecording() const noexcept
{ return false; }
29 void SetAttribute(nostd::string_view
/* key */,
30 const common::AttributeValue
& /* value */) noexcept
33 void AddEvent(nostd::string_view
/* name */) noexcept
{}
35 void AddEvent(nostd::string_view
/* name */, common::SystemTimestamp
/* timestamp */) noexcept
{}
37 void AddEvent(nostd::string_view
/* name */,
38 common::SystemTimestamp
/* timestamp */,
39 const common::KeyValueIterable
& /* attributes */) noexcept
42 void AddEvent(nostd::string_view name
, const common::KeyValueIterable
&attributes
) noexcept
44 this->AddEvent(name
, std::chrono::system_clock::now(), attributes
);
47 void SetStatus(StatusCode
/* status */, nostd::string_view
/* description */) noexcept
{}
49 void UpdateName(nostd::string_view
/* name */) noexcept
{}
51 void End(const EndSpanOptions
& /* options */ = {}) noexcept
{}
53 nostd::string_view
ToString() const noexcept
{ return "DefaultSpan"; }
55 DefaultSpan(SpanContext span_context
) noexcept
: span_context_(span_context
) {}
57 // movable and copiable
58 DefaultSpan(DefaultSpan
&&spn
) noexcept
: span_context_(spn
.GetContext()) {}
59 DefaultSpan(const DefaultSpan
&spn
) noexcept
: span_context_(spn
.GetContext()) {}
62 SpanContext span_context_
;
66 OPENTELEMETRY_END_NAMESPACE