Skip to content

Commit 9375819

Browse files
committed
First pass
1 parent a388e87 commit 9375819

File tree

21 files changed

+66
-64
lines changed

21 files changed

+66
-64
lines changed

api/include/opentelemetry/baggage/baggage_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ inline nostd::shared_ptr<Baggage> GetBaggage(const context::Context &context) no
2727
}
2828

2929
inline context::Context SetBaggage(context::Context &context,
30-
nostd::shared_ptr<Baggage> baggage) noexcept
30+
const nostd::shared_ptr<Baggage>& baggage) noexcept
3131
{
3232
return context.SetValue(kBaggageHeader, baggage);
3333
}

api/include/opentelemetry/context/context.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ class Context
2929
// hold a shared_ptr to the head of the DataList linked list
3030
template <class T>
3131
Context(const T &keys_and_values) noexcept
32-
{
33-
head_ = nostd::shared_ptr<DataList>{new DataList(keys_and_values)};
34-
}
32+
: head_{nostd::shared_ptr<DataList>{new DataList(keys_and_values)}}
33+
{}
3534

3635
// Creates a context object from a key and value, this will
3736
// hold a shared_ptr to the head of the DataList linked list
3837
Context(nostd::string_view key, ContextValue value) noexcept
39-
{
40-
head_ = nostd::shared_ptr<DataList>{new DataList(key, value)};
41-
}
38+
: head_{nostd::shared_ptr<DataList>{new DataList(key, value)}}
39+
{}
4240

4341
// Accepts a new iterable and then returns a new context that
4442
// contains the new key and value data. It attaches the
@@ -92,22 +90,21 @@ class Context
9290

9391
private:
9492
// A linked list to contain the keys and values of this context node
95-
class DataList
93+
struct DataList
9694
{
97-
public:
98-
char *key_;
95+
char *key_ = nullptr;
9996

100-
nostd::shared_ptr<DataList> next_;
97+
size_t key_length_ = 0UL;
10198

102-
size_t key_length_;
99+
nostd::shared_ptr<DataList> next_;
103100

104101
ContextValue value_;
105102

106-
DataList() { next_ = nullptr; }
103+
DataList() : next_{nullptr} {}
107104

108105
// Builds a data list off of a key and value iterable and returns the head
109106
template <class T>
110-
DataList(const T &keys_and_vals) : key_{nullptr}, next_(nostd::shared_ptr<DataList>{nullptr})
107+
DataList(const T &keys_and_vals) : next_(nostd::shared_ptr<DataList>{nullptr})
111108
{
112109
bool first = true;
113110
auto *node = this;
@@ -133,8 +130,14 @@ class Context
133130
key_ = new char[key.size()];
134131
key_length_ = key.size();
135132
memcpy(key_, key.data(), key.size() * sizeof(char));
136-
value_ = value;
137133
next_ = nostd::shared_ptr<DataList>{nullptr};
134+
value_ = value;
135+
}
136+
137+
DataList(const DataList &other)
138+
: key_length_(other.key_length_), next_(other.next_), value_(other.value_)
139+
{
140+
memcpy(key_, other.key_, other.key_length_ * sizeof(char));
138141
}
139142

140143
DataList &operator=(DataList &&other) noexcept

api/include/opentelemetry/context/propagation/global_propagator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class OPENTELEMETRY_EXPORT GlobalTextMapPropagator
3232
return nostd::shared_ptr<TextMapPropagator>(GetPropagator());
3333
}
3434

35-
static void SetGlobalPropagator(nostd::shared_ptr<TextMapPropagator> prop) noexcept
35+
static void SetGlobalPropagator(const nostd::shared_ptr<TextMapPropagator>& prop) noexcept
3636
{
3737
std::lock_guard<common::SpinLockMutex> guard(GetLock());
3838
GetPropagator() = prop;

api/include/opentelemetry/context/runtime_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class OPENTELEMETRY_EXPORT RuntimeContext
152152
*
153153
* @param storage a custom runtime context storage
154154
*/
155-
static void SetRuntimeContextStorage(nostd::shared_ptr<RuntimeContextStorage> storage) noexcept
155+
static void SetRuntimeContextStorage(const nostd::shared_ptr<RuntimeContextStorage>& storage) noexcept
156156
{
157157
GetStorage() = storage;
158158
}

api/include/opentelemetry/logs/event_id.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace logs
1919
class EventId
2020
{
2121
public:
22-
EventId(int64_t id, nostd::string_view name) noexcept : id_{id}
22+
EventId(int64_t id, nostd::string_view name) noexcept
23+
: id_{id}, name_{nostd::unique_ptr<char[]>{new char[name.length() + 1]}}
2324
{
24-
name_ = nostd::unique_ptr<char[]>{new char[name.length() + 1]};
2525
std::copy(name.begin(), name.end(), name_.get());
2626
name_.get()[name.length()] = 0;
2727
}

api/include/opentelemetry/logs/provider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT Provider
3939
/**
4040
* Changes the singleton LoggerProvider.
4141
*/
42-
static void SetLoggerProvider(nostd::shared_ptr<LoggerProvider> tp) noexcept
42+
static void SetLoggerProvider(const nostd::shared_ptr<LoggerProvider>& tp) noexcept
4343
{
4444
std::lock_guard<common::SpinLockMutex> guard(GetLock());
4545
GetProvider() = tp;
@@ -60,7 +60,7 @@ class OPENTELEMETRY_EXPORT Provider
6060
/**
6161
* Changes the singleton EventLoggerProvider.
6262
*/
63-
static void SetEventLoggerProvider(nostd::shared_ptr<EventLoggerProvider> tp) noexcept
63+
static void SetEventLoggerProvider(const nostd::shared_ptr<EventLoggerProvider>& tp) noexcept
6464
{
6565
std::lock_guard<common::SpinLockMutex> guard(GetLock());
6666
GetEventProvider() = tp;

api/include/opentelemetry/trace/context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ inline bool IsRootSpan(const context::Context &context) noexcept
3434
}
3535

3636
// Set Span into explicit context
37-
inline context::Context SetSpan(context::Context &context, nostd::shared_ptr<Span> span) noexcept
37+
inline context::Context SetSpan(context::Context &context,
38+
const nostd::shared_ptr<Span> &span) noexcept
3839
{
3940
return context.SetValue(kSpanKey, span);
4041
}

api/include/opentelemetry/trace/default_span.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DefaultSpan : public Span
6363

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

66-
DefaultSpan(SpanContext span_context) noexcept : span_context_(span_context) {}
66+
DefaultSpan(const SpanContext& span_context) noexcept : span_context_(span_context) {}
6767

6868
// movable and copiable
6969
DefaultSpan(DefaultSpan &&spn) noexcept : Span(), span_context_(spn.GetContext()) {}

api/include/opentelemetry/trace/provider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OPENTELEMETRY_EXPORT Provider
3636
/**
3737
* Changes the singleton TracerProvider.
3838
*/
39-
static void SetTracerProvider(nostd::shared_ptr<TracerProvider> tp) noexcept
39+
static void SetTracerProvider(const nostd::shared_ptr<TracerProvider>& tp) noexcept
4040
{
4141
std::lock_guard<common::SpinLockMutex> guard(GetLock());
4242
GetProvider() = tp;

api/include/opentelemetry/trace/span_context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SpanContext final
4141
SpanId span_id,
4242
TraceFlags trace_flags,
4343
bool is_remote,
44-
nostd::shared_ptr<TraceState> trace_state = TraceState::GetDefault()) noexcept
44+
const nostd::shared_ptr<TraceState>& trace_state = TraceState::GetDefault()) noexcept
4545
: trace_id_(trace_id),
4646
span_id_(span_id),
4747
trace_flags_(trace_flags),
@@ -64,7 +64,7 @@ class SpanContext final
6464
const trace::SpanId &span_id() const noexcept { return span_id_; }
6565

6666
// @returns the trace_state associated with this span_context
67-
const nostd::shared_ptr<trace::TraceState> trace_state() const noexcept { return trace_state_; }
67+
const nostd::shared_ptr<trace::TraceState>& trace_state() const noexcept { return trace_state_; }
6868

6969
/*
7070
* @param that SpanContext for comparing.

0 commit comments

Comments
 (0)