Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert null to empty string for tracer name #712

Merged
merged 3 commits into from
Apr 29, 2021

Conversation

ThomsonTan
Copy link
Contributor

Changes

Below spec change required tracer name to be converted to empty string if it is null. As we are using nostd::string_view to represent null, this change converts it to empty string in TracerProvider::GetTracer(name, version).

open-telemetry/opentelemetry-specification#1654

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@ThomsonTan ThomsonTan requested a review from a team April 29, 2021 00:58
@codecov
Copy link

codecov bot commented Apr 29, 2021

Codecov Report

Merging #712 (dd4e043) into main (a987f0a) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #712      +/-   ##
==========================================
+ Coverage   94.72%   94.73%   +0.01%     
==========================================
  Files         216      216              
  Lines        9895     9900       +5     
==========================================
+ Hits         9373     9379       +6     
+ Misses        522      521       -1     
Impacted Files Coverage Δ
sdk/src/trace/tracer_provider.cc 72.22% <100.00%> (+1.63%) ⬆️
sdk/test/trace/tracer_provider_test.cc 100.00% <100.00%> (ø)
sdk/src/logs/batch_log_processor.cc 95.00% <0.00%> (+1.25%) ⬆️

@@ -23,6 +23,9 @@ nostd::shared_ptr<opentelemetry::trace::Tracer> TracerProvider::GetTracer(
nostd::string_view library_name,
nostd::string_view library_version) noexcept
{
if (library_name.data() == nullptr) {
library_name = "";
}
// if (library_name == "") {
Copy link
Contributor

@maxgolov maxgolov Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still intend keeping the previous TODO, since now the code intentionally forces that condition?

( I assume you have to until we sort out some internal macro for logging internal SDK trace messages ? )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO is still needed I think, as the spec requires message reporting. Yes, I assume it is internal SDK logging.

message reporting that the specified value is invalid SHOULD be logged

@@ -23,6 +23,9 @@ nostd::shared_ptr<opentelemetry::trace::Tracer> TracerProvider::GetTracer(
nostd::string_view library_name,
nostd::string_view library_version) noexcept
{
if (library_name.data() == nullptr) {
Copy link
Member

@lalitb lalitb Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing a nullptr to GetTrace() is the application/intrumentation code issue, and the right behavior should be to let it crash so that the application developer can fix this. Probably I need to understand the spec change more clearly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest spec mentioned this in explicit that null name should not crash and should be treat like empty name.

In case an invalid name (null or empty string) is specified, a working Tracer implementation MUST be returned as a fallback rather than returning null or throwing an exception, its name property SHOULD be set to an empty string,

@lalitb
Copy link
Member

lalitb commented Apr 29, 2021

@ThomsonTan - Can you look into CI failures so that we can merge this ?

@ThomsonTan
Copy link
Contributor Author

@ThomsonTan - Can you look into CI failures so that we can merge this ?

Thanks for the reminder, fixed the format.

@lalitb lalitb merged commit fc7a325 into open-telemetry:main Apr 29, 2021
@ThomsonTan ThomsonTan deleted the ConvertNullToEmptyTracerName branch November 9, 2022 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants