Skip to content

Commit 99a72e1

Browse files
authored
Add noexcept/const qualifier at missing places for Trace API. (#1374)
* fix noxcept * fix etw
1 parent 5458dde commit 99a72e1

File tree

14 files changed

+50
-45
lines changed

14 files changed

+50
-45
lines changed

api/include/opentelemetry/baggage/baggage.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ class Baggage
2525
static constexpr char kMembersSeparator = ',';
2626
static constexpr char kMetadataSeparator = ';';
2727

28-
Baggage() : kv_properties_(new opentelemetry::common::KeyValueProperties()) {}
29-
Baggage(size_t size) : kv_properties_(new opentelemetry::common::KeyValueProperties(size)){};
28+
Baggage() noexcept : kv_properties_(new opentelemetry::common::KeyValueProperties()) {}
29+
Baggage(size_t size) noexcept
30+
: kv_properties_(new opentelemetry::common::KeyValueProperties(size)){};
3031

3132
template <class T>
32-
Baggage(const T &keys_and_values)
33+
Baggage(const T &keys_and_values) noexcept
3334
: kv_properties_(new opentelemetry::common::KeyValueProperties(keys_and_values))
3435
{}
3536

@@ -42,15 +43,16 @@ class Baggage
4243
/* Get value for key in the baggage
4344
@returns true if key is found, false otherwise
4445
*/
45-
bool GetValue(nostd::string_view key, std::string &value) const
46+
bool GetValue(nostd::string_view key, std::string &value) const noexcept
4647
{
4748
return kv_properties_->GetValue(key, value);
4849
}
4950

5051
/* Returns shared_ptr of new baggage object which contains new key-value pair. If key or value is
5152
invalid, copy of current baggage is returned
5253
*/
53-
nostd::shared_ptr<Baggage> Set(const nostd::string_view &key, const nostd::string_view &value)
54+
nostd::shared_ptr<Baggage> Set(const nostd::string_view &key,
55+
const nostd::string_view &value) noexcept
5456
{
5557

5658
nostd::shared_ptr<Baggage> baggage(new Baggage(kv_properties_->Size() + 1));
@@ -89,7 +91,7 @@ class Baggage
8991
// if key does not exist, copy of current baggage is returned.
9092
// Validity of key is not checked as invalid keys should never be populated in baggage in the
9193
// first place.
92-
nostd::shared_ptr<Baggage> Delete(nostd::string_view key)
94+
nostd::shared_ptr<Baggage> Delete(nostd::string_view key) noexcept
9395
{
9496
// keeping size of baggage same as key might not be found in it
9597
nostd::shared_ptr<Baggage> baggage(new Baggage(kv_properties_->Size()));
@@ -103,7 +105,7 @@ class Baggage
103105
}
104106

105107
// Returns shared_ptr of baggage after extracting key-value pairs from header
106-
static nostd::shared_ptr<Baggage> FromHeader(nostd::string_view header)
108+
static nostd::shared_ptr<Baggage> FromHeader(nostd::string_view header) noexcept
107109
{
108110
if (header.size() > kMaxSize)
109111
{
@@ -158,7 +160,7 @@ class Baggage
158160
}
159161

160162
// Creates string from baggage object.
161-
std::string ToHeader() const
163+
std::string ToHeader() const noexcept
162164
{
163165
std::string header_s;
164166
bool first = true;

api/include/opentelemetry/baggage/baggage_context.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace baggage
1616
static const std::string kBaggageHeader = "baggage";
1717

1818
inline nostd::shared_ptr<opentelemetry::baggage::Baggage> GetBaggage(
19-
const opentelemetry::context::Context &context)
19+
const opentelemetry::context::Context &context) noexcept
2020
{
2121
context::ContextValue context_value = context.GetValue(kBaggageHeader);
2222
if (nostd::holds_alternative<nostd::shared_ptr<opentelemetry::baggage::Baggage>>(context_value))
@@ -28,8 +28,9 @@ inline nostd::shared_ptr<opentelemetry::baggage::Baggage> GetBaggage(
2828
return empty_baggage;
2929
}
3030

31-
inline context::Context SetBaggage(opentelemetry::context::Context &context,
32-
nostd::shared_ptr<opentelemetry::baggage::Baggage> baggage)
31+
inline context::Context SetBaggage(
32+
opentelemetry::context::Context &context,
33+
nostd::shared_ptr<opentelemetry::baggage::Baggage> baggage) noexcept
3334
{
3435
return context.SetValue(kBaggageHeader, baggage);
3536
}

api/include/opentelemetry/common/kv_properties.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class KeyValueStringTokenizer
3333
public:
3434
KeyValueStringTokenizer(
3535
nostd::string_view str,
36-
const KeyValueStringTokenizerOptions &opts = KeyValueStringTokenizerOptions())
36+
const KeyValueStringTokenizerOptions &opts = KeyValueStringTokenizerOptions()) noexcept
3737
: str_(str), opts_(opts), index_(0)
3838
{}
3939

@@ -48,7 +48,7 @@ class KeyValueStringTokenizer
4848
// @param key : key in kv pair
4949
// @param key : value in kv pair
5050
// @returns true if next kv pair was found, false otherwise.
51-
bool next(bool &valid_kv, nostd::string_view &key, nostd::string_view &value)
51+
bool next(bool &valid_kv, nostd::string_view &key, nostd::string_view &value) noexcept
5252
{
5353
valid_kv = true;
5454
while (index_ < str_.size())
@@ -170,13 +170,13 @@ class KeyValueProperties
170170
}
171171

172172
// Gets the key associated with this entry.
173-
nostd::string_view GetKey() const { return key_.get(); }
173+
nostd::string_view GetKey() const noexcept { return key_.get(); }
174174

175175
// Gets the value associated with this entry.
176-
nostd::string_view GetValue() const { return value_.get(); }
176+
nostd::string_view GetValue() const noexcept { return value_.get(); }
177177

178178
// Sets the value for this entry. This overrides the previous value.
179-
void SetValue(nostd::string_view value) { value_ = CopyStringToPointer(value); }
179+
void SetValue(nostd::string_view value) noexcept { value_ = CopyStringToPointer(value); }
180180

181181
private:
182182
// Store key and value as raw char pointers to avoid using std::string.
@@ -206,15 +206,15 @@ class KeyValueProperties
206206
public:
207207
// Create Key-value list of given size
208208
// @param size : Size of list.
209-
KeyValueProperties(size_t size)
209+
KeyValueProperties(size_t size) noexcept
210210
: num_entries_(0), max_num_entries_(size), entries_(new Entry[size])
211211
{}
212212

213213
// Create Empty Key-Value list
214-
KeyValueProperties() : num_entries_(0), max_num_entries_(0), entries_(nullptr) {}
214+
KeyValueProperties() noexcept : num_entries_(0), max_num_entries_(0), entries_(nullptr) {}
215215

216216
template <class T, class = typename std::enable_if<detail::is_key_value_iterable<T>::value>::type>
217-
KeyValueProperties(const T &keys_and_values)
217+
KeyValueProperties(const T &keys_and_values) noexcept
218218
: num_entries_(0),
219219
max_num_entries_(keys_and_values.size()),
220220
entries_(new Entry[max_num_entries_])
@@ -227,7 +227,7 @@ class KeyValueProperties
227227
}
228228

229229
// Adds new kv pair into kv properties
230-
void AddEntry(nostd::string_view key, nostd::string_view value)
230+
void AddEntry(nostd::string_view key, nostd::string_view value) noexcept
231231
{
232232
if (num_entries_ < max_num_entries_)
233233
{
@@ -238,7 +238,7 @@ class KeyValueProperties
238238

239239
// Returns all kv pair entries
240240
bool GetAllEntries(
241-
nostd::function_ref<bool(nostd::string_view, nostd::string_view)> callback) const
241+
nostd::function_ref<bool(nostd::string_view, nostd::string_view)> callback) const noexcept
242242
{
243243
for (size_t i = 0; i < num_entries_; i++)
244244
{
@@ -252,7 +252,7 @@ class KeyValueProperties
252252
}
253253

254254
// Return value for key if exists, return false otherwise
255-
bool GetValue(nostd::string_view key, std::string &value) const
255+
bool GetValue(nostd::string_view key, std::string &value) const noexcept
256256
{
257257
for (size_t i = 0; i < num_entries_; i++)
258258
{

api/include/opentelemetry/common/string_util.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace common
2626
class StringUtil
2727
{
2828
public:
29-
static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right)
29+
static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right) noexcept
3030
{
3131
while (str[static_cast<std::size_t>(left)] == ' ' && left <= right)
3232
{
@@ -39,7 +39,7 @@ class StringUtil
3939
return str.substr(left, 1 + right - left);
4040
}
4141

42-
static nostd::string_view Trim(nostd::string_view str)
42+
static nostd::string_view Trim(nostd::string_view str) noexcept
4343
{
4444
if (str.empty())
4545
{

api/include/opentelemetry/context/context.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ class Context
2424
// Creates a context object from a map of keys and identifiers, this will
2525
// hold a shared_ptr to the head of the DataList linked list
2626
template <class T>
27-
Context(const T &keys_and_values)
27+
Context(const T &keys_and_values) noexcept
2828
{
2929
head_ = nostd::shared_ptr<DataList>{new DataList(keys_and_values)};
3030
}
3131

3232
// Creates a context object from a key and value, this will
3333
// hold a shared_ptr to the head of the DataList linked list
34-
Context(nostd::string_view key, ContextValue value)
34+
Context(nostd::string_view key, ContextValue value) noexcept
3535
{
3636
head_ = nostd::shared_ptr<DataList>{new DataList(key, value)};
3737
}

api/include/opentelemetry/context/runtime_context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class RuntimeContext
173173
}
174174
};
175175

176-
inline Token::~Token()
176+
inline Token::~Token() noexcept
177177
{
178178
context::RuntimeContext::Detach(*this);
179179
}

api/include/opentelemetry/trace/context.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace trace
1212
{
1313

1414
// Get Span from explicit context
15-
inline nostd::shared_ptr<Span> GetSpan(const opentelemetry::context::Context &context)
15+
inline nostd::shared_ptr<Span> GetSpan(const opentelemetry::context::Context &context) noexcept
1616
{
1717
context::ContextValue span = context.GetValue(kSpanKey);
1818
if (nostd::holds_alternative<nostd::shared_ptr<Span>>(span))
@@ -24,7 +24,7 @@ inline nostd::shared_ptr<Span> GetSpan(const opentelemetry::context::Context &co
2424

2525
// Set Span into explicit context
2626
inline context::Context SetSpan(opentelemetry::context::Context &context,
27-
nostd::shared_ptr<Span> span)
27+
nostd::shared_ptr<Span> span) noexcept
2828
{
2929
return context.SetValue(kSpanKey, span);
3030
}

api/include/opentelemetry/trace/default_span.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ class DefaultSpan : public Span
5050

5151
void End(const EndSpanOptions & /* options */ = {}) noexcept {}
5252

53-
nostd::string_view ToString() { return "DefaultSpan"; }
53+
nostd::string_view ToString() const noexcept { return "DefaultSpan"; }
5454

55-
DefaultSpan(SpanContext span_context) : span_context_(span_context) {}
55+
DefaultSpan(SpanContext span_context) noexcept : span_context_(span_context) {}
5656

5757
// movable and copiable
58-
DefaultSpan(DefaultSpan &&spn) : span_context_(spn.GetContext()) {}
59-
DefaultSpan(const DefaultSpan &spn) : span_context_(spn.GetContext()) {}
58+
DefaultSpan(DefaultSpan &&spn) noexcept : span_context_(spn.GetContext()) {}
59+
DefaultSpan(const DefaultSpan &spn) noexcept : span_context_(spn.GetContext()) {}
6060

6161
private:
6262
SpanContext span_context_;

api/include/opentelemetry/trace/noop.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ class NoopTracer final : public Tracer, public std::enable_shared_from_this<Noop
100100
class NoopTracerProvider final : public opentelemetry::trace::TracerProvider
101101
{
102102
public:
103-
NoopTracerProvider()
103+
NoopTracerProvider() noexcept
104104
: tracer_{nostd::shared_ptr<opentelemetry::trace::NoopTracer>(
105105
new opentelemetry::trace::NoopTracer)}
106106
{}
107107

108-
nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer(nostd::string_view library_name,
109-
nostd::string_view library_version,
110-
nostd::string_view schema_url) override
108+
nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer(
109+
nostd::string_view library_name,
110+
nostd::string_view library_version,
111+
nostd::string_view schema_url) noexcept override
111112
{
112113
return tracer_;
113114
}

api/include/opentelemetry/trace/span_context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SpanContext final
2626
* sampled
2727
* @param is_remote true if this context was propagated from a remote parent.
2828
*/
29-
SpanContext(bool sampled_flag, bool is_remote)
29+
SpanContext(bool sampled_flag, bool is_remote) noexcept
3030
: trace_id_(),
3131
span_id_(),
3232
trace_flags_(opentelemetry::trace::TraceFlags((uint8_t)sampled_flag)),

api/include/opentelemetry/trace/trace_state.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TraceState
5353
* the W3C Trace Context specification https://www.w3.org/TR/trace-context/
5454
* @return TraceState A new TraceState instance or DEFAULT
5555
*/
56-
static nostd::shared_ptr<TraceState> FromHeader(nostd::string_view header)
56+
static nostd::shared_ptr<TraceState> FromHeader(nostd::string_view header) noexcept
5757
{
5858

5959
common::KeyValueStringTokenizer kv_str_tokenizer(header);
@@ -89,7 +89,7 @@ class TraceState
8989
/**
9090
* Creates a w3c tracestate header from TraceState object
9191
*/
92-
std::string ToHeader()
92+
std::string ToHeader() const noexcept
9393
{
9494
std::string header_s;
9595
bool first = true;
@@ -135,7 +135,8 @@ class TraceState
135135
*
136136
* If the existing object has maximum list members, it's copy is returned.
137137
*/
138-
nostd::shared_ptr<TraceState> Set(const nostd::string_view &key, const nostd::string_view &value)
138+
nostd::shared_ptr<TraceState> Set(const nostd::string_view &key,
139+
const nostd::string_view &value) noexcept
139140
{
140141
auto curr_size = kv_properties_->Size();
141142
if (!IsValidKey(key) || !IsValidValue(value))
@@ -168,7 +169,7 @@ class TraceState
168169
* @returns empty TraceState object if key is invalid
169170
* @returns copy of original TraceState object if key is not present (??)
170171
*/
171-
nostd::shared_ptr<TraceState> Delete(const nostd::string_view &key)
172+
nostd::shared_ptr<TraceState> Delete(const nostd::string_view &key) noexcept
172173
{
173174
if (!IsValidKey(key))
174175
{

api/include/opentelemetry/trace/tracer_provider.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TracerProvider
2525
*/
2626
virtual nostd::shared_ptr<Tracer> GetTracer(nostd::string_view library_name,
2727
nostd::string_view library_version = "",
28-
nostd::string_view schema_url = "") = 0;
28+
nostd::string_view schema_url = "") noexcept = 0;
2929
};
3030
} // namespace trace
3131
OPENTELEMETRY_END_NAMESPACE

api/test/trace/provider_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestProvider : public TracerProvider
1616
{
1717
nostd::shared_ptr<Tracer> GetTracer(nostd::string_view library_name,
1818
nostd::string_view library_version,
19-
nostd::string_view schema_url) override
19+
nostd::string_view schema_url) noexcept override
2020
{
2121
return nostd::shared_ptr<Tracer>(nullptr);
2222
}

exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ class TracerProvider : public opentelemetry::trace::TracerProvider
980980
nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer(
981981
nostd::string_view name,
982982
nostd::string_view args = "",
983-
nostd::string_view schema_url = "") override
983+
nostd::string_view schema_url = "") noexcept override
984984
{
985985
UNREFERENCED_PARAMETER(args);
986986
UNREFERENCED_PARAMETER(schema_url);

0 commit comments

Comments
 (0)