Currently, many APIs are flagged as noexcept.
For example:
class OPENTELEMETRY_EXPORT TracerProvider
{
public:
virtual nostd::shared_ptr<Tracer> GetTracer(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const common::KeyValueIterable *attributes) noexcept = 0;
When implemented in the SDK:
nostd::shared_ptr<trace_api::Tracer> TracerProvider::GetTracer(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const opentelemetry::common::KeyValueIterable *attributes) noexcept
{
...
auto tracer = std::shared_ptr<Tracer>(new Tracer(context_, std::move(scope)));
tracers_.push_back(tracer);
return nostd::shared_ptr<trace_api::Tracer>{tracer};
}
The call to new Tracer() can fail with bad_alloc, so an exception is still raised, breaking the noexcept contract.
Proposal:
nostd::shared_ptr<trace_api::Tracer> TracerProvider::GetTracerImpl(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const opentelemetry::common::KeyValueIterable *attributes) {
}
nostd::shared_ptr<trace_api::Tracer> TracerProvider::GetTracer(
nostd::string_view name,
nostd::string_view version,
nostd::string_view schema_url,
const opentelemetry::common::KeyValueIterable *attributes) noexcept
{
try {
// invoke GetTracerImpl
}
catch {
return a pre allocated Noop tracer instead.
}
}
Forcing down the noexcept to the entire code base is not realistic, entry points to the SDK surface needs to handle failures explicitly instead, to give room to the SDK implementation to fail internally with exceptions if needed.
Currently, many APIs are flagged as
noexcept.For example:
When implemented in the SDK:
The call to
new Tracer()can fail with bad_alloc, so an exception is still raised, breaking thenoexceptcontract.Proposal:
Forcing down the
noexceptto the entire code base is not realistic, entry points to the SDK surface needs to handle failures explicitly instead, to give room to the SDK implementation to fail internally with exceptions if needed.