Skip to content

Commit

Permalink
v3
Browse files Browse the repository at this point in the history
  • Loading branch information
ricktu-mw committed Oct 2, 2023
1 parent 081f16e commit dd8e0e9
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 109 deletions.
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,16 @@ set(OPENTELEMETRY_PROXY_SOURCES
${METRICS_SDK_SOURCE_DIR}/PeriodicExportingMetricReaderProxy.cpp
${COMMON_SDK_SOURCE_DIR}/resource.cpp)
if(WITH_OTLP_HTTP)
set(OPENTELEMETRY_PROXY_SOURCES ${OPENTELEMETRY_PROXY_SOURCES}
${OTLP_EXPORTER_SOURCE_DIR}/OtlpHttpSpanExporterProxy.cpp
set(OPENTELEMETRY_PROXY_SOURCES
${OPENTELEMETRY_PROXY_SOURCES}
${OTLP_EXPORTER_SOURCE_DIR}/OtlpHttpSpanExporterProxy.cpp
${OTLP_EXPORTER_SOURCE_DIR}/OtlpHttpMetricExporterProxy.cpp)
endif()
if(WITH_OTLP_GRPC)
set(OPENTELEMETRY_PROXY_SOURCES ${OPENTELEMETRY_PROXY_SOURCES}
${OTLP_EXPORTER_SOURCE_DIR}/OtlpGrpcSpanExporterProxy.cpp)
set(OPENTELEMETRY_PROXY_SOURCES
${OPENTELEMETRY_PROXY_SOURCES}
${OTLP_EXPORTER_SOURCE_DIR}/OtlpGrpcSpanExporterProxy.cpp
${OTLP_EXPORTER_SOURCE_DIR}/OtlpGrpcMetricExporterProxy.cpp)
endif()

libmexclass_client_add_proxy_library(
Expand Down Expand Up @@ -391,11 +394,12 @@ set(COMMON_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/common/+openteleme
set(TRACE_SDK_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sdk/trace/+opentelemetry)
set(METRICS_SDK_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sdk/metrics/+opentelemetry)
set(DEFAULT_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/defaultSpanExporter.m)
set(DEFAULT_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/defaultMetricExporter.m)
set(OTLP_HTTP_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpHttpSpanExporter.m)
set(OTLP_HTTP_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpHttpMetricExporter.m)
set(OTLP_GRPC_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpGrpcSpanExporter.m)
set(DEFAULT_METRIC_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/defaultMetricExporter.m)
set(OTLP_HTTP_METRIC_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpHttpMetricExporter.m)
set(OTLP_GRPC_METRIC_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpGrpcMetricExporter.m)
set(OTLP_GRPC_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpGrpcMetricExporter.m)


set(OTLP_EXPORTERS_DIR +opentelemetry/+exporters/+otlp)

Expand All @@ -410,11 +414,9 @@ install(FILES ${DEFAULT_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DI
install(FILES ${DEFAULT_METRIC_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
if(WITH_OTLP_HTTP)
install(FILES ${OTLP_HTTP_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
install(FILES ${OTLP_HTTP_METRIC_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
endif()
if(WITH_OTLP_GRPC)
install(FILES ${OTLP_GRPC_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
install(FILES ${OTLP_GRPC_METRIC_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
endif()

# Install dependent runtime libraries
Expand Down
6 changes: 6 additions & 0 deletions OtelMatlabProxyFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
#include "opentelemetry-matlab/sdk/trace/TraceIdRatioBasedSamplerProxy.h"
#include "opentelemetry-matlab/sdk/trace/ParentBasedSamplerProxy.h"
#include "opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h"
#include "opentelemetry-matlab/sdk/metrics/PeriodicExportingMetricReaderProxy.h"
#ifdef WITH_OTLP_HTTP
#include "opentelemetry-matlab/exporters/otlp/OtlpHttpSpanExporterProxy.h"
#include "opentelemetry-matlab/exporters/otlp/OtlpHttpMetricExporterProxy.h"
#endif
#ifdef WITH_OTLP_GRPC
#include "opentelemetry-matlab/exporters/otlp/OtlpGrpcSpanExporterProxy.h"
#include "opentelemetry-matlab/exporters/otlp/OtlpGrpcMetricExporterProxy.h"
#endif

libmexclass::proxy::MakeResult
Expand Down Expand Up @@ -57,12 +60,15 @@ OtelMatlabProxyFactory::make_proxy(const libmexclass::proxy::ClassName& class_na
REGISTER_PROXY(libmexclass.opentelemetry.sdk.ParentBasedSamplerProxy, libmexclass::opentelemetry::sdk::ParentBasedSamplerProxy);

REGISTER_PROXY(libmexclass.opentelemetry.sdk.MeterProviderProxy, libmexclass::opentelemetry::sdk::MeterProviderProxy);
REGISTER_PROXY(libmexclass.opentelemetry.sdk.PeriodicExportingMetricReaderProxy, libmexclass::opentelemetry::sdk::PeriodicExportingMetricReaderProxy);

#ifdef WITH_OTLP_HTTP
REGISTER_PROXY(libmexclass.opentelemetry.exporters.OtlpHttpSpanExporterProxy, libmexclass::opentelemetry::exporters::OtlpHttpSpanExporterProxy);
REGISTER_PROXY(libmexclass.opentelemetry.exporters.OtlpHttpMetricExporterProxy, libmexclass::opentelemetry::exporters::OtlpHttpMetricExporterProxy);
#endif
#ifdef WITH_OTLP_GRPC
REGISTER_PROXY(libmexclass.opentelemetry.exporters.OtlpGrpcSpanExporterProxy, libmexclass::opentelemetry::exporters::OtlpGrpcSpanExporterProxy);
REGISTER_PROXY(libmexclass.opentelemetry.exporters.OtlpGrpcMetricExporterProxy, libmexclass::opentelemetry::exporters::OtlpGrpcMetricExporterProxy);
#endif
return nullptr;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
% Copyright 2023 The MathWorks, Inc.

properties (SetAccess=immutable)
Endpoint (1,1) string % Export destination
UseCredentials (1,1) logical % Whether to use SSL credentials
CertificatePath (1,1) string % Path to .pem file for SSL encryption
CertificateString (1,1) string % In-memory string representation of .pem file for SSL encryption
Timeout (1,1) duration % Maximum time above which exports will abort
HttpHeaders (1,1) dictionary % Additional HTTP headers
Endpoint (1,1) string % Export destination
UseCredentials (1,1) logical % Whether to use SSL credentials
CertificatePath (1,1) string % Path to .pem file for SSL encryption
CertificateString (1,1) string % In-memory string representation of .pem file for SSL encryption
Timeout (1,1) duration % Maximum time above which exports will abort
HttpHeaders (1,1) dictionary % Additional HTTP headers
PreferredAggregationTemporality (1,1) string % Preferred Aggregation Temporality
end

methods
Expand Down Expand Up @@ -44,7 +45,7 @@
end

validnames = ["Endpoint", "UseCredentials ", "CertificatePath", ...
"CertificateString", "Timeout", "HttpHeaders"];
"CertificateString", "Timeout", "HttpHeaders", "PreferredAggregationTemporality"];
% set default values to empty or negative
endpoint = "";
usessl = false;
Expand All @@ -53,6 +54,7 @@
timeout_millis = -1;
headerkeys = string.empty();
headervalues = string.empty();
temporality = "";
for i = 1:length(optionnames)
namei = validatestring(optionnames{i}, validnames);
valuei = optionvalues{i};
Expand Down Expand Up @@ -82,7 +84,7 @@
end
timeout = valuei;
timeout_millis = milliseconds(timeout);
else % HttpHeaders
elseif strcmp(namei, "HttpHeaders") % HttpHeaders
if ~isa(valuei, "dictionary")
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary.");
end
Expand All @@ -92,16 +94,18 @@
if ~isstring(headervalues)
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.")
end
elseif strcmp(namei, "PreferredAggregationTemporality")
temporality = validatestring(valuei, ["Cumulative", "Delta"]);
end
end

obj = [email protected](...
"libmexclass.opentelemetry.exporters.OtlpGrpcMetricExporterProxy", ...
endpoint, usessl, certificatepath, certificatestring, ...
timeout_millis, headerkeys, headervalues);
timeout_millis, headerkeys, headervalues, temporality);

% populate immutable properties
[defaultendpoint, defaultcertpath, defaultcertstring, defaultmillis] = ...
[defaultendpoint, defaultcertpath, defaultcertstring, defaultmillis, defaulttemporality] = ...
getDefaultOptionValues(obj);
if endpoint == "" % not specified, use default value
obj.Endpoint = defaultendpoint;
Expand Down Expand Up @@ -129,7 +133,11 @@
else
obj.HttpHeaders = httpheaders;
end

if temporality == ""
obj.PreferredAggregationTemporality = defaulttemporality;
else
obj.PreferredAggregationTemporality = temporality;
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,25 @@
% Copyright 2023 The MathWorks, Inc.

properties (SetAccess=immutable)
Endpoint (1,1) string % Export destination
Format (1,1) string % Data format, JSON or binary
JsonBytesMapping (1,1) string % What to convert JSON bytes to
UseJsonName (1,1) logical % Whether to use JSON name of protobuf field to set the key of JSON
Timeout (1,1) duration % Maximum time above which exports will abort
HttpHeaders (1,1) dictionary % Additional HTTP headers
Endpoint (1,1) string % Export destination
Format (1,1) string % Data format, JSON or binary
JsonBytesMapping (1,1) string % What to convert JSON bytes to
UseJsonName (1,1) logical % Whether to use JSON name of protobuf field to set the key of JSON
Timeout (1,1) duration % Maximum time above which exports will abort
HttpHeaders (1,1) dictionary % Additional HTTP headers
PreferredAggregationTemporality (1,1) string % Preferred Aggregation Temporality
end

methods
function obj = OtlpHttpMetricExporter(optionnames, optionvalues)
% OtlpHttpMetricExporter exports Metrics in OpenTelemetry Protocol format via HTTP.
% EXP = OPENTELEMETRY.EXPORTERS.OTLP.OTLPHTTPMetricEXPORTER
% creates an exporter that uses default configurations.
%
% EXP =
% OPENTELEMETRY.EXPORTERS.OTLP.OTLPHTTPMetricEXPORTER(PARAM1,
% VALUE1, PARAM2, VALUE2, ...) specifies optional parameter
% name/value pairs. Parameters are:
% "Endpoint" - Endpoint to export to
% "Format" - Data format: "JSON" (default) or "binary"
% "JsonBytesMapping" - What to convert JSON bytes to. Supported
% values are "hex", "hexId" (default), and
% "base64". Default "hexId"
% converts to base 64 except for IDs
% which are converted to hexadecimals.
% "UseJsonName" - Whether to use JSON name of protobuf
% field to set the key of JSON
% "Timeout" - Maximum time above which exports
% will abort
% "HTTPHeaders" - Additional HTTP Headers
%
% See also OPENTELEMETRY.EXPORTERS.OTLP.OTLPGRPCMetricEXPORTER

arguments (Repeating)
optionnames (1,:) {mustBeTextScalar}
optionvalues
end

validnames = ["Endpoint", "Format", "JsonBytesMapping", ...
"UseJsonName", "Timeout", "HttpHeaders"];
"UseJsonName", "Timeout", "HttpHeaders", "PreferredAggregationTemporality"];
% set default values to empty or negative
endpoint = "";
dataformat = "";
Expand All @@ -53,6 +33,7 @@
timeout_millis = -1;
headerkeys = string.empty();
headervalues = string.empty();
temporality = "";
for i = 1:length(optionnames)
namei = validatestring(optionnames{i}, validnames);
valuei = optionvalues{i};
Expand All @@ -70,13 +51,13 @@
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:UseJsonNameNotScalarLogical", "UseJsonName must be a scalar logical.")
end
usejsonname = logical(valuei);
elseif strcmp(namei, "Timeout")
elseif strcmp(namei, "Timeout")
if ~(isduration(valuei) && isscalar(valuei))
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration.");
end
timeout = valuei;
timeout_millis = milliseconds(timeout);
else % HttpHeaders
elseif strcmp(namei, "HttpHeaders")
if ~isa(valuei, "dictionary")
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary.");
end
Expand All @@ -86,18 +67,21 @@
if ~isstring(headervalues)
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.")
end
elseif strcmp(namei, "PreferredAggregationTemporality")
temporality = validatestring(valuei, ["Cumulative", "Delta"]);
end

end

obj = [email protected](...
"libmexclass.opentelemetry.exporters.OtlpHttpMetricExporterProxy", ...
endpoint, dataformat, jsonbytesmapping, usejsonname, ...
timeout_millis, headerkeys, headervalues);
timeout_millis, headerkeys, headervalues, temporality);

% populate immutable properties
if endpoint == "" || dataformat == "" || jsonbytesmapping == "" || ...
timeout_millis < 0
[defaultendpoint, defaultformat, defaultmapping, defaultmillis] = ...
[defaultendpoint, defaultformat, defaultmapping, defaultmillis, defaulttemporality] = ...
getDefaultOptionValues(obj);
end
if endpoint == "" % not specified, use default value
Expand Down Expand Up @@ -126,6 +110,11 @@
else
obj.HttpHeaders = httpheaders;
end
if temporality == ""
obj.PreferredAggregationTemporality = defaulttemporality;
else
obj.PreferredAggregationTemporality = temporality;
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
#include "libmexclass/proxy/method/Context.h"

#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h"

namespace metric_sdk = opentelemetry::sdk::metric;
namespace metric_sdk = opentelemetry::sdk::metrics;
namespace otlp_exporter = opentelemetry::exporter::otlp;

namespace libmexclass::opentelemetry::exporters {
class OtlpGrpcMetricExporterProxy: public libmexclass::opentelemetry::sdk::MetricExporterProxy {
public:
OtlpGrpcMetricExporterProxy(otlp_exporter::OtlpGrpcExporterOptions options) : CppOptions(options) {
OtlpGrpcMetricExporterProxy(otlp_exporter::OtlpGrpcMetricExporterOptions options) : CppOptions(options) {
REGISTER_METHOD(OtlpGrpcMetricExporterProxy, getDefaultOptionValues);
}

static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments);

std::unique_ptr<metric_sdk::MetricExporter> getInstance() override;
std::unique_ptr<metric_sdk::PushMetricExporter> getInstance() override;

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

private:
otlp_exporter::OtlpGrpcExporterOptions CppOptions;
otlp_exporter::OtlpGrpcMetricExporterOptions CppOptions;
};
} // namespace libmexclass::opentelemetry
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class OtlpHttpMetricExporterProxy: public libmexclass::opentelemetry::sdk::Metri
public:
OtlpHttpMetricExporterProxy(otlp_exporter::OtlpHttpMetricExporterOptions options) : CppOptions(options) {
REGISTER_METHOD(OtlpHttpMetricExporterProxy, getDefaultOptionValues);
REGISTER_METHOD(OtlpHttpMetricExporterProxy, test);
}

static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments);
Expand All @@ -27,8 +26,6 @@ class OtlpHttpMetricExporterProxy: public libmexclass::opentelemetry::sdk::Metri

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

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

private:
otlp_exporter::OtlpHttpMetricExporterOptions CppOptions;
};
Expand Down
Loading

0 comments on commit dd8e0e9

Please sign in to comment.