forked from open-telemetry/opentelemetry-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Meter provider sdk (open-telemetry#182)
- Loading branch information
1 parent
879c2bf
commit a95e2a6
Showing
10 changed files
with
139 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/metrics/meter.h" | ||
#include "opentelemetry/version.h" | ||
|
||
#include <memory> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
class Meter final : public opentelemetry::metrics::Meter, public std::enable_shared_from_this<Meter> | ||
{ | ||
public: | ||
|
||
}; | ||
} // namespace trace | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/nostd/shared_ptr.h" | ||
#include "opentelemetry/sdk/metrics/meter.h" | ||
#include "opentelemetry/metrics/meter_provider.h" | ||
|
||
#include <memory> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
class MeterProvider final : public opentelemetry::metrics::MeterProvider | ||
{ | ||
public: | ||
/** | ||
* Initialize a new meter provider | ||
*/ | ||
explicit MeterProvider() noexcept; | ||
|
||
opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Meter> GetMeter( | ||
nostd::string_view library_name, | ||
nostd::string_view library_version = "") noexcept override; | ||
|
||
private: | ||
std::shared_ptr<opentelemetry::metrics::Meter> meter_; | ||
}; | ||
} // namespace metrics | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(common) | ||
add_subdirectory(trace) | ||
add_subdirectory(metrics) |
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,26 @@ | ||
# Copyright 2020, 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. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "metrics", | ||
srcs = glob(["**/*.cc"]), | ||
hdrs = glob(["**/*.h"]), | ||
include_prefix = "src/metrics", | ||
deps = [ | ||
"//api", | ||
"//sdk:headers", | ||
], | ||
) |
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 @@ | ||
add_library(opentelemetry_metrics meter_provider.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,21 @@ | ||
#include "opentelemetry/sdk/metrics/meter_provider.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
MeterProvider::MeterProvider() noexcept | ||
: meter_(new Meter) | ||
{} | ||
|
||
opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Meter> MeterProvider::GetMeter( | ||
nostd::string_view library_name, | ||
nostd::string_view library_version) noexcept | ||
{ | ||
return opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Meter>(meter_); | ||
} | ||
|
||
} // namespace metrics | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(common) | ||
add_subdirectory(trace) | ||
add_subdirectory(metrics) |
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,10 @@ | ||
cc_test( | ||
name = "meter_provider_sdk_test", | ||
srcs = [ | ||
"meter_provider_sdk_test.cc", | ||
], | ||
deps = [ | ||
"//sdk/src/metrics", | ||
"@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,6 @@ | ||
foreach(testname meter_provider_sdk_test) | ||
add_executable(${testname} "${testname}.cc") | ||
target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} | ||
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common opentelemetry_metrics) | ||
gtest_add_tests(TARGET ${testname} TEST_PREFIX metrics. TEST_LIST ${testname}) | ||
endforeach() |
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,22 @@ | ||
#include "opentelemetry/sdk/metrics/meter_provider.h" | ||
#include "opentelemetry/sdk/metrics/meter.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace opentelemetry::sdk::metrics; | ||
|
||
TEST(MeterProvider, GetMeter) | ||
{ | ||
MeterProvider tf; | ||
auto t1 = tf.GetMeter("test"); | ||
auto t2 = tf.GetMeter("test"); | ||
auto t3 = tf.GetMeter("different", "1.0.0"); | ||
ASSERT_NE(nullptr, t1); | ||
ASSERT_NE(nullptr, t2); | ||
ASSERT_NE(nullptr, t3); | ||
|
||
// Should return the same instance each time. | ||
ASSERT_EQ(t1, t2); | ||
ASSERT_EQ(t1, t3); | ||
|
||
} |