Skip to content

Commit

Permalink
Meter provider sdk (open-telemetry#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
HudsonHumphries authored Jul 20, 2020
1 parent 879c2bf commit a95e2a6
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter.h
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
31 changes: 31 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter_provider.h
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
1 change: 1 addition & 0 deletions sdk/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(common)
add_subdirectory(trace)
add_subdirectory(metrics)
26 changes: 26 additions & 0 deletions sdk/src/metrics/BUILD
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",
],
)
1 change: 1 addition & 0 deletions sdk/src/metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(opentelemetry_metrics meter_provider.cc)
21 changes: 21 additions & 0 deletions sdk/src/metrics/meter_provider.cc
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
1 change: 1 addition & 0 deletions sdk/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(common)
add_subdirectory(trace)
add_subdirectory(metrics)
10 changes: 10 additions & 0 deletions sdk/test/metrics/BUILD
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",
],
)
6 changes: 6 additions & 0 deletions sdk/test/metrics/CMakeLists.txt
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()
22 changes: 22 additions & 0 deletions sdk/test/metrics/meter_provider_sdk_test.cc
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);

}

0 comments on commit a95e2a6

Please sign in to comment.