Skip to content

Commit b3ad6a0

Browse files
committed
Add a static make method to all proxy classes, in response to change in libmexclass
1 parent e0a8028 commit b3ad6a0

39 files changed

+220
-183
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ set(OPENTELEMETRY_PROXY_SOURCES
7979
${CONTEXT_API_SOURCE_DIR}/ContextProxy.cpp
8080
${BAGGAGE_API_SOURCE_DIR}/BaggageProxy.cpp
8181
${TRACE_SDK_SOURCE_DIR}/TracerProviderProxy.cpp
82+
${TRACE_SDK_SOURCE_DIR}/SimpleSpanProcessorProxy.cpp
8283
${TRACE_SDK_SOURCE_DIR}/BatchSpanProcessorProxy.cpp
8384
${TRACE_SDK_SOURCE_DIR}/ParentBasedSamplerProxy.cpp
8485
${OTLP_EXPORTER_SOURCE_DIR}/OtlpHttpSpanExporterProxy.cpp

OtelMatlabProxyFactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#include "opentelemetry-matlab/exporters/otlp/OtlpHttpSpanExporterProxy.h"
2626
#include "opentelemetry-matlab/exporters/otlp/OtlpGrpcSpanExporterProxy.h"
2727

28-
std::shared_ptr<libmexclass::proxy::Proxy>
28+
libmexclass::proxy::MakeResult
2929
OtelMatlabProxyFactory::make_proxy(const libmexclass::proxy::ClassName& class_name,
3030
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
3131

3232
REGISTER_PROXY(libmexclass.opentelemetry.TracerProviderProxy, libmexclass::opentelemetry::TracerProviderProxy);
33-
REGISTER_PROXY(libmexclass.opentelemetry.TracerProxy, libmexclass::opentelemetry::TracerProxy);
33+
//REGISTER_PROXY(libmexclass.opentelemetry.TracerProxy, libmexclass::opentelemetry::TracerProxy);
3434
REGISTER_PROXY(libmexclass.opentelemetry.SpanProxy, libmexclass::opentelemetry::SpanProxy);
3535
//REGISTER_PROXY(libmexclass.opentelemetry.ScopeProxy, libmexclass::opentelemetry::ScopeProxy);
3636
REGISTER_PROXY(libmexclass.opentelemetry.SpanContextProxy, libmexclass::opentelemetry::SpanContextProxy);

OtelMatlabProxyFactory.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Copyright 2023 The MathWorks, Inc.
2-
3-
#pragma once
4-
5-
#include "libmexclass/proxy/Factory.h"
6-
7-
class OtelMatlabProxyFactory : public libmexclass::proxy::Factory {
8-
public:
9-
OtelMatlabProxyFactory() {}
10-
virtual std::shared_ptr<libmexclass::proxy::Proxy>
11-
make_proxy(const libmexclass::proxy::ClassName& class_name,
12-
const libmexclass::proxy::FunctionArguments& constructor_arguments);
13-
};
1+
// Copyright 2023 The MathWorks, Inc.
2+
3+
#pragma once
4+
5+
#include "libmexclass/proxy/Factory.h"
6+
7+
class OtelMatlabProxyFactory : public libmexclass::proxy::Factory {
8+
public:
9+
OtelMatlabProxyFactory() {}
10+
virtual libmexclass::proxy::MakeResult
11+
make_proxy(const libmexclass::proxy::ClassName& class_name,
12+
const libmexclass::proxy::FunctionArguments& constructor_arguments);
13+
};

api/baggage/include/opentelemetry-matlab/baggage/BaggagePropagatorProxy.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ namespace context_propagation = opentelemetry::context::propagation;
1515
namespace libmexclass::opentelemetry {
1616
class BaggagePropagatorProxy : public TextMapPropagatorProxy {
1717
public:
18-
BaggagePropagatorProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments)
19-
{
20-
CppPropagator = nostd::shared_ptr<context_propagation::TextMapPropagator>(new baggage_propagation::BaggagePropagator());
18+
BaggagePropagatorProxy() : TextMapPropagatorProxy(nostd::shared_ptr<context_propagation::TextMapPropagator>(
19+
new baggage_propagation::BaggagePropagator())) {}
20+
21+
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
22+
return std::make_shared<BaggagePropagatorProxy>();
2123
}
2224

2325
// getUniquePtrCopy is used by CompositePropagator, which needs a unique_ptr instance

api/baggage/include/opentelemetry-matlab/baggage/BaggageProxy.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ namespace nostd = opentelemetry::nostd;
1212
namespace libmexclass::opentelemetry {
1313
class BaggageProxy : public libmexclass::proxy::Proxy {
1414
public:
15-
BaggageProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments);
15+
BaggageProxy(nostd::shared_ptr<baggage_api::Baggage> bag) : CppBaggage(bag) {
16+
REGISTER_METHOD(BaggageProxy, getAllEntries);
17+
REGISTER_METHOD(BaggageProxy, setEntries);
18+
REGISTER_METHOD(BaggageProxy, deleteEntries);
19+
REGISTER_METHOD(BaggageProxy, insertBaggage);
20+
}
21+
22+
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments);
1623

1724
void getAllEntries(libmexclass::proxy::method::Context& context);
1825
void setEntries(libmexclass::proxy::method::Context& context);

api/baggage/src/BaggageProxy.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
namespace libmexclass::opentelemetry {
1414

15-
BaggageProxy::BaggageProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments)
16-
{
15+
libmexclass::proxy::MakeResult BaggageProxy::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
1716
size_t nin = constructor_arguments.getNumberOfElements();
17+
nostd::shared_ptr<baggage_api::Baggage> baggage;
1818
if (nin == 1) {
1919
matlab::data::TypedArray<uint64_t> contextid_mda = constructor_arguments[0];
2020
libmexclass::proxy::ID contextid = contextid_mda[0];
2121

2222
context_api::Context ctxt = std::static_pointer_cast<ContextProxy>(
2323
libmexclass::proxy::ProxyManager::getProxy(contextid))->getInstance();
24-
CppBaggage = baggage_api::GetBaggage(ctxt);
24+
baggage = baggage_api::GetBaggage(ctxt);
2525
} else { // 2 inputs
2626
matlab::data::StringArray keys_mda = constructor_arguments[0];
2727
matlab::data::StringArray values_mda = constructor_arguments[1];
@@ -34,13 +34,9 @@ BaggageProxy::BaggageProxy(const libmexclass::proxy::FunctionArguments& construc
3434
static_cast<std::string>(values_mda[i])));
3535
}
3636

37-
CppBaggage = nostd::shared_ptr<baggage_api::Baggage>(new baggage_api::Baggage(attrs));
37+
baggage = nostd::shared_ptr<baggage_api::Baggage>(new baggage_api::Baggage(attrs));
3838
}
39-
40-
REGISTER_METHOD(BaggageProxy, getAllEntries);
41-
REGISTER_METHOD(BaggageProxy, setEntries);
42-
REGISTER_METHOD(BaggageProxy, deleteEntries);
43-
REGISTER_METHOD(BaggageProxy, insertBaggage);
39+
return std::make_shared<BaggageProxy>(baggage);
4440
}
4541

4642
void BaggageProxy::getAllEntries(libmexclass::proxy::method::Context& context) {

api/context/include/opentelemetry-matlab/context/ContextProxy.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ namespace context_api = opentelemetry::context;
1616
namespace libmexclass::opentelemetry {
1717
class ContextProxy : public libmexclass::proxy::Proxy {
1818
public:
19-
// zero input supports the code path for empty context creation
20-
// one input supports the code path for getCurrentContext
21-
ContextProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments)
22-
: CppContext(constructor_arguments.isEmpty()? context_api::Context() : context_api::RuntimeContext::GetCurrent())
23-
{
24-
registerMethods();
19+
ContextProxy(context_api::Context ctxt) : CppContext{ctxt} {
20+
REGISTER_METHOD(ContextProxy, setCurrentContext);
2521
}
2622

27-
ContextProxy(context_api::Context ctxt) : CppContext{ctxt} {
28-
registerMethods();
23+
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
24+
// zero input supports the code path for empty context creation
25+
// one input supports the code path for getCurrentContext
26+
return std::make_shared<ContextProxy>(constructor_arguments.isEmpty()?
27+
context_api::Context() : context_api::RuntimeContext::GetCurrent());
2928
}
3029

3130
context_api::Context getInstance() {
@@ -35,9 +34,6 @@ class ContextProxy : public libmexclass::proxy::Proxy {
3534
void setCurrentContext(libmexclass::proxy::method::Context& context);
3635

3736
private:
38-
void registerMethods() {
39-
REGISTER_METHOD(ContextProxy, setCurrentContext);
40-
}
4137

4238
context_api::Context CppContext;
4339
};

api/context/include/opentelemetry-matlab/context/TokenProxy.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ namespace nostd = opentelemetry::nostd;
1515
namespace libmexclass::opentelemetry {
1616
class TokenProxy : public libmexclass::proxy::Proxy {
1717
public:
18-
TokenProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments) {}
18+
TokenProxy() {}
19+
20+
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
21+
return std::make_shared<TokenProxy>();
22+
}
1923

2024
void setInstance(nostd::unique_ptr<context_api::Token>& instance) {
2125
CppToken.swap(instance);

api/context/include/opentelemetry-matlab/context/propagation/CompositePropagatorProxy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
namespace libmexclass::opentelemetry {
1111
class CompositePropagatorProxy : public TextMapPropagatorProxy {
1212
public:
13-
CompositePropagatorProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments);
13+
CompositePropagatorProxy(nostd::shared_ptr<context_propagation::TextMapPropagator> prop) : TextMapPropagatorProxy(prop) {}
14+
15+
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments);
1416
};
1517
} // namespace libmexclass::opentelemetry

api/context/include/opentelemetry-matlab/context/propagation/TextMapCarrierProxy.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,19 @@
1010
namespace libmexclass::opentelemetry {
1111
class TextMapCarrierProxy : public libmexclass::proxy::Proxy {
1212
public:
13-
TextMapCarrierProxy(const libmexclass::proxy::FunctionArguments& constructor_arguments);
14-
1513
TextMapCarrierProxy(const HttpTextMapCarrier& carrier) : CppCarrier(carrier) {
16-
registerMethods();
14+
REGISTER_METHOD(TextMapCarrierProxy, getHeaders);
1715
}
1816

17+
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments);
18+
1919
HttpTextMapCarrier getInstance() {
2020
return CppCarrier;
2121
}
2222

2323
void getHeaders(libmexclass::proxy::method::Context& context);
2424

2525
private:
26-
void registerMethods() {
27-
REGISTER_METHOD(TextMapCarrierProxy, getHeaders);
28-
}
29-
3026
HttpTextMapCarrier CppCarrier;
3127
};
3228
} // namespace libmexclass::opentelemetry

0 commit comments

Comments
 (0)