-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InstrumentationLibrary to Tracer (#693)
- Loading branch information
1 parent
7909008
commit 30434fa
Showing
14 changed files
with
207 additions
and
13 deletions.
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
85 changes: 85 additions & 0 deletions
85
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,85 @@ | ||
// 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 equal(other.name_, other.version_); | ||
} | ||
|
||
/** | ||
* Check whether the instrumentation library has given name and version. | ||
* This could be used to check version equality and avoid heap allocation. | ||
* @param name name of the instrumentation library to compare. | ||
* @param version version of the instrumentatoin library to compare. | ||
* @returns true if name and version in this instrumentation library are equal with the given name | ||
* and version. | ||
*/ | ||
bool equal(const nostd::string_view name, const nostd::string_view version) const | ||
{ | ||
return this->name_ == name && this->version_ == 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