Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpo committed Nov 13, 2023
1 parent 613e99e commit dd0d28a
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
36 changes: 36 additions & 0 deletions api/metrics/include/opentelemetry-matlab/metrics/MeterProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2023 The MathWorks, Inc.

#pragma once

#include "libmexclass/proxy/Proxy.h"
#include "libmexclass/proxy/method/Context.h"

#include "opentelemetry-matlab/metrics/CounterProxy.h"
#include "opentelemetry-matlab/metrics/HistogramProxy.h"
#include "opentelemetry-matlab/metrics/UpDownCounterProxy.h"

#include "opentelemetry/metrics/meter.h"

namespace metrics_api = opentelemetry::metrics;
namespace nostd = opentelemetry::nostd;

namespace libmexclass::opentelemetry {
class MeterProxy : public libmexclass::proxy::Proxy {
public:
MeterProxy(nostd::shared_ptr<metrics_api::Meter> mt) : CppMeter(mt) {
REGISTER_METHOD(MeterProxy, createCounter);
REGISTER_METHOD(MeterProxy, createUpDownCounter);
REGISTER_METHOD(MeterProxy, createHistogram);
}

void createCounter(libmexclass::proxy::method::Context& context);

void createUpDownCounter(libmexclass::proxy::method::Context& context);

void createHistogram(libmexclass::proxy::method::Context& context);

private:

nostd::shared_ptr<metrics_api::Meter> CppMeter;
};
} // namespace libmexclass::opentelemetry
88 changes: 88 additions & 0 deletions api/metrics/src/MeterProxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2023 The MathWorks, Inc.

#include "opentelemetry-matlab/metrics/MeterProxy.h"

#include "libmexclass/proxy/ProxyManager.h"

#include "MatlabDataArray.hpp"

#include <chrono>

namespace libmexclass::opentelemetry {
void MeterProxy::createCounter(libmexclass::proxy::method::Context& context) {
// Always assumes 3 inputs
matlab::data::StringArray name_mda = context.inputs[0];
std::string name = static_cast<std::string>(name_mda[0]);
matlab::data::StringArray description_mda = context.inputs[1];
std::string description= static_cast<std::string>(description_mda[0]);
matlab::data::StringArray unit_mda = context.inputs[2];
std::string unit = static_cast<std::string>(unit_mda[0]);

nostd::shared_ptr<metrics_api::Counter<double> > ct = std::move(CppMeter->CreateDoubleCounter(name, description, unit));

// instantiate a CounterProxy instance
CounterProxy* newproxy = new CounterProxy(ct);
auto proxy = std::shared_ptr<libmexclass::proxy::Proxy>(newproxy);

// obtain a proxy ID
libmexclass::proxy::ID proxyid = libmexclass::proxy::ProxyManager::manageProxy(proxy);

// return the ID
matlab::data::ArrayFactory factory;
auto proxyid_mda = factory.createScalar<libmexclass::proxy::ID>(proxyid);
context.outputs[0] = proxyid_mda;
}


void MeterProxy::createUpDownCounter(libmexclass::proxy::method::Context& context) {
// Always assumes 3 inputs
matlab::data::StringArray name_mda = context.inputs[0];
std::string name = static_cast<std::string>(name_mda[0]);
matlab::data::StringArray description_mda = context.inputs[1];
std::string description= static_cast<std::string>(description_mda[0]);
matlab::data::StringArray unit_mda = context.inputs[2];
std::string unit = static_cast<std::string>(unit_mda[0]);

nostd::shared_ptr<metrics_api::UpDownCounter<double> > ct = std::move(CppMeter->CreateDoubleUpDownCounter
(name, description, unit));

// instantiate a UpDownCounterProxy instance
UpDownCounterProxy* newproxy = new UpDownCounterProxy(ct);
auto proxy = std::shared_ptr<libmexclass::proxy::Proxy>(newproxy);

// obtain a proxy ID
libmexclass::proxy::ID proxyid = libmexclass::proxy::ProxyManager::manageProxy(proxy);

// return the ID
matlab::data::ArrayFactory factory;
auto proxyid_mda = factory.createScalar<libmexclass::proxy::ID>(proxyid);
context.outputs[0] = proxyid_mda;
}


void MeterProxy::createHistogram(libmexclass::proxy::method::Context& context) {
// Always assumes 3 inputs
matlab::data::StringArray name_mda = context.inputs[0];
std::string name = static_cast<std::string>(name_mda[0]);
matlab::data::StringArray description_mda = context.inputs[1];
std::string description= static_cast<std::string>(description_mda[0]);
matlab::data::StringArray unit_mda = context.inputs[2];
std::string unit = static_cast<std::string>(unit_mda[0]);

nostd::shared_ptr<metrics_api::Histogram<double> > hist = std::move(CppMeter->CreateDoubleHistogram(name, description, unit));

// instantiate a HistogramProxy instance
HistogramProxy* newproxy = new HistogramProxy(hist);
auto proxy = std::shared_ptr<libmexclass::proxy::Proxy>(newproxy);

// obtain a proxy ID
libmexclass::proxy::ID proxyid = libmexclass::proxy::ProxyManager::manageProxy(proxy);

// return the ID
matlab::data::ArrayFactory factory;
auto proxyid_mda = factory.createScalar<libmexclass::proxy::ID>(proxyid);
context.outputs[0] = proxyid_mda;
}


} // namespace libmexclass::opentelemetry

0 comments on commit dd0d28a

Please sign in to comment.