1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #include "opentelemetry/nostd/unique_ptr.h"
10 namespace nostd
= opentelemetry::nostd
;
11 namespace common
= opentelemetry::common
;
12 namespace trace
= opentelemetry::trace
;
13 namespace context
= opentelemetry::context
;
17 class Span final
: public trace::Span
20 Span(std::shared_ptr
<Tracer
> &&tracer
,
21 nostd::string_view name
,
22 const common::KeyValueIterable
& /*attributes*/,
23 const trace::SpanContextKeyValueIterable
& /*links*/,
24 const trace::StartSpanOptions
& /*options*/) noexcept
25 : tracer_
{std::move(tracer
)}, name_
{name
}, span_context_
{trace::SpanContext::GetInvalid()}
27 std::cout
<< "StartSpan: " << name
<< "\n";
30 ~Span() { std::cout
<< "~Span\n"; }
32 // opentelemetry::trace::Span
33 void SetAttribute(nostd::string_view
/*name*/,
34 const common::AttributeValue
& /*value*/) noexcept override
37 void AddEvent(nostd::string_view
/*name*/) noexcept override
{}
39 void AddEvent(nostd::string_view
/*name*/,
40 common::SystemTimestamp
/*timestamp*/) noexcept override
43 void AddEvent(nostd::string_view
/*name*/,
44 common::SystemTimestamp
/*timestamp*/,
45 const common::KeyValueIterable
& /*attributes*/) noexcept override
48 void SetStatus(trace::StatusCode
/*code*/, nostd::string_view
/*description*/) noexcept override
51 void UpdateName(nostd::string_view
/*name*/) noexcept override
{}
53 void End(const trace::EndSpanOptions
& /*options*/) noexcept override
{}
55 bool IsRecording() const noexcept override
{ return true; }
57 trace::SpanContext
GetContext() const noexcept override
{ return span_context_
; }
60 std::shared_ptr
<Tracer
> tracer_
;
62 trace::SpanContext span_context_
;
66 Tracer::Tracer(nostd::string_view
/*output*/) {}
68 nostd::shared_ptr
<trace::Span
> Tracer::StartSpan(nostd::string_view name
,
69 const common::KeyValueIterable
&attributes
,
70 const trace::SpanContextKeyValueIterable
&links
,
71 const trace::StartSpanOptions
&options
) noexcept
73 return nostd::shared_ptr
<trace::Span
>{
74 new (std::nothrow
) Span
{this->shared_from_this(), name
, attributes
, links
, options
}};