-
Notifications
You must be signed in to change notification settings - Fork 423
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
Add InstrumentationLibrary to Tracer #693
Merged
lalitb
merged 13 commits into
open-telemetry:main
from
ThomsonTan:AddInstrumentationLibrary
Apr 26, 2021
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
77d0e5c
Add InstrumentationLibrary to Tracer in API package
ThomsonTan 4ff42e6
More test case coverage for GetTracer.
ThomsonTan 6313490
Format
ThomsonTan a4c60a7
Move instrumentation library from API to SDK
ThomsonTan c76e3c6
Remove implicit type cast
ThomsonTan 2084cb5
Apply format
ThomsonTan b2dff23
Store SdkTracer in SdkTracerProvider
ThomsonTan 39eda7e
Fix implicit type cast
ThomsonTan 5e0f613
Fix missing bazel dependence
ThomsonTan c792e3e
Update CHANGELOG file
ThomsonTan 44630a4
Merge branch 'main' into AddInstrumentationLibrary
ThomsonTan c2fb193
Delay heap allocation for existing tracer in GetTracer
ThomsonTan 5b55dd1
Merge branch 'main' into AddInstrumentationLibrary
lalitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2021, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/nostd/unique_ptr.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
|
||
namespace sdk | ||
{ | ||
namespace instrumentationlibrary | ||
{ | ||
|
||
class InstrumentationLibrary | ||
{ | ||
public: | ||
InstrumentationLibrary(const InstrumentationLibrary &) = default; | ||
|
||
/** | ||
* Returns a newly created InstrumentationLibrary with the specified library name and version. | ||
* @param name name of the instrumentation library. | ||
* @param version version of the instrumentation library. | ||
* @returns the newly created InstrumentationLibrary. | ||
*/ | ||
static nostd::unique_ptr<InstrumentationLibrary> create(nostd::string_view name, | ||
nostd::string_view version = "") | ||
{ | ||
return nostd::unique_ptr<InstrumentationLibrary>( | ||
new InstrumentationLibrary{std::string{name}, std::string{version}}); | ||
} | ||
|
||
/** | ||
* Compare 2 instrumentation libraries. | ||
* @param other the instrumentation library to compare to. | ||
* @returns true if the 2 instrumentation libraries are equal, false otherwise. | ||
*/ | ||
bool operator==(const InstrumentationLibrary &other) const | ||
{ | ||
return this->name_ == other.name_ && this->version_ == other.version_; | ||
} | ||
|
||
const std::string &GetName() const { return name_; } | ||
const std::string &GetVersion() const { return version_; } | ||
|
||
private: | ||
InstrumentationLibrary(nostd::string_view name, nostd::string_view version) | ||
: name_(name), version_(version) | ||
{} | ||
|
||
private: | ||
std::string name_; | ||
std::string version_; | ||
}; | ||
|
||
} // namespace instrumentationlibrary | ||
} // namespace sdk | ||
|
||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") | ||
|
||
cc_test( | ||
name = "instrumentationlibrary_test", | ||
srcs = [ | ||
"instrumentationlibrary_test.cc", | ||
], | ||
deps = [ | ||
"//api", | ||
"//sdk:headers", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
include(GoogleTest) | ||
|
||
foreach(testname instrumentationlibrary_test) | ||
add_executable(${testname} "${testname}.cc") | ||
target_link_libraries( | ||
${testname} ${GTEST_BOTH_LIBRARIES} ${CORE_RUNTIME_LIBS} | ||
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) | ||
gtest_add_tests( | ||
TARGET ${testname} | ||
TEST_PREFIX instrumentationlibrary. | ||
TEST_LIST ${testname}) | ||
endforeach() |
34 changes: 34 additions & 0 deletions
34
sdk/test/instrumentationlibrary/instrumentationlibrary_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2021, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" | ||
|
||
#include <gtest/gtest.h> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace opentelemetry; | ||
using namespace opentelemetry::sdk::instrumentationlibrary; | ||
|
||
TEST(InstrumentationLibrary, CreateInstrumentationLibrary) | ||
{ | ||
|
||
std::string library_name = "opentelemetry-cpp"; | ||
std::string library_version = "0.1.0"; | ||
auto instrumentation_library = InstrumentationLibrary::create(library_name, library_version); | ||
|
||
EXPECT_EQ(instrumentation_library->GetName(), library_name); | ||
EXPECT_EQ(instrumentation_library->GetVersion(), library_version); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
GetTracer
were to be used in an instrumentation to retrieve a tracer when creating spans, this potentially creates 3 allocations and deallocs on a hot path.Would it make sense to avoid heap allocations here for the usual case when a tracer already exists?
I mean using
GetTracer()
every time could perhaps be considered bad use of the API as opposed to caching a tracer in the instrumentation, but I think it might be too easy too misuse the API and just default toGetTracer()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seemk thanks. I think this is a valid concern. I updated the PR and delayed the heap allocation to the time when creating new
Tracer
is necessary.