From 4c6e09f4d959a874c8c8f01d13949ca639fc39c3 Mon Sep 17 00:00:00 2001 From: duncanpo Date: Wed, 25 Oct 2023 10:06:48 -0400 Subject: [PATCH] Revert "Merge branch 'metrics' into changes_after_v_1_3_0" This reverts commit 083ee564ffc9c07ee4e0fbda4131753eaa0aec34, reversing changes made to 99894413e8034fb825f8ea91f60e6ddd46f2cda1. --- CMakeLists.txt | 18 +- OtelMatlabProxyFactory.cpp | 4 - api/metrics/+opentelemetry/+metrics/Counter.m | 59 --- .../+opentelemetry/+metrics/Histogram.m | 55 --- api/metrics/+opentelemetry/+metrics/Meter.m | 89 ----- .../+opentelemetry/+metrics/UpDownCounter.m | 58 --- .../metrics/CounterProxy.h | 33 -- .../metrics/HistogramProxy.h | 36 -- .../opentelemetry-matlab/metrics/MeterProxy.h | 36 -- .../metrics/UpDownCounterProxy.h | 33 -- api/metrics/src/CounterProxy.cpp | 41 -- api/metrics/src/HistogramProxy.cpp | 44 --- api/metrics/src/MeterProxy.cpp | 88 ----- api/metrics/src/UpDownCounterProxy.cpp | 41 -- .../+sdk/+metrics/MeterProvider.m | 56 --- .../sdk/metrics/MeterProviderProxy.h | 48 --- sdk/metrics/src/MeterProviderProxy.cpp | 54 --- test/tmetrics.m | 364 ------------------ 18 files changed, 1 insertion(+), 1156 deletions(-) delete mode 100644 api/metrics/+opentelemetry/+metrics/Counter.m delete mode 100644 api/metrics/+opentelemetry/+metrics/Histogram.m delete mode 100644 api/metrics/+opentelemetry/+metrics/Meter.m delete mode 100644 api/metrics/+opentelemetry/+metrics/UpDownCounter.m delete mode 100644 api/metrics/include/opentelemetry-matlab/metrics/CounterProxy.h delete mode 100644 api/metrics/include/opentelemetry-matlab/metrics/HistogramProxy.h delete mode 100644 api/metrics/include/opentelemetry-matlab/metrics/MeterProxy.h delete mode 100644 api/metrics/include/opentelemetry-matlab/metrics/UpDownCounterProxy.h delete mode 100644 api/metrics/src/CounterProxy.cpp delete mode 100644 api/metrics/src/HistogramProxy.cpp delete mode 100644 api/metrics/src/MeterProxy.cpp delete mode 100644 api/metrics/src/UpDownCounterProxy.cpp delete mode 100644 sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m delete mode 100644 sdk/metrics/include/opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h delete mode 100644 sdk/metrics/src/MeterProviderProxy.cpp delete mode 100644 test/tmetrics.m diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ee427c..1b9f509 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,25 +188,21 @@ if(WITH_OTLP_GRPC) endif() set(TRACE_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/trace/include) -set(METRICS_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/metrics/include) set(CONTEXT_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/context/include) set(BAGGAGE_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/baggage/include) set(COMMON_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/common/include) set(TRACE_SDK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/trace/include) -set(METRICS_SDK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/metrics/include) set(COMMON_SDK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/common/include) set(OTLP_EXPORTER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/include) -set(OPENTELEMETRY_PROXY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ${TRACE_API_INCLUDE_DIR} ${METRICS_API_INCLUDE_DIR} ${CONTEXT_API_INCLUDE_DIR} ${BAGGAGE_API_INCLUDE_DIR} ${COMMON_API_INCLUDE_DIR} ${TRACE_SDK_INCLUDE_DIR} ${METRICS_SDK_INCLUDE_DIR} ${COMMON_SDK_INCLUDE_DIR} ${OTLP_EXPORTER_INCLUDE_DIR} ${OTEL_CPP_PREFIX}/include) +set(OPENTELEMETRY_PROXY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ${TRACE_API_INCLUDE_DIR} ${CONTEXT_API_INCLUDE_DIR} ${BAGGAGE_API_INCLUDE_DIR} ${COMMON_API_INCLUDE_DIR} ${TRACE_SDK_INCLUDE_DIR} ${COMMON_SDK_INCLUDE_DIR} ${OTLP_EXPORTER_INCLUDE_DIR} ${OTEL_CPP_PREFIX}/include) set(OPENTELEMETRY_PROXY_FACTORY_CLASS_NAME OtelMatlabProxyFactory) set(OPENTELEMETRY_PROXY_FACTORY_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(TRACE_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/trace/src) -set(METRICS_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/metrics/src) set(CONTEXT_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/context/src) set(BAGGAGE_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/baggage/src) set(COMMON_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/common/src) set(TRACE_SDK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/trace/src) -set(METRICS_SDK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/metrics/src) set(COMMON_SDK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/common/src) set(OTLP_EXPORTER_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/src) set(OPENTELEMETRY_PROXY_SOURCES @@ -216,10 +212,6 @@ set(OPENTELEMETRY_PROXY_SOURCES ${TRACE_API_SOURCE_DIR}/SpanProxy.cpp ${TRACE_API_SOURCE_DIR}/SpanContextProxy.cpp ${COMMON_API_SOURCE_DIR}/attribute.cpp - ${METRICS_API_SOURCE_DIR}/MeterProxy.cpp - ${METRICS_API_SOURCE_DIR}/CounterProxy.cpp - ${METRICS_API_SOURCE_DIR}/UpDownCounterProxy.cpp - ${METRICS_API_SOURCE_DIR}/HistogramProxy.cpp ${CONTEXT_API_SOURCE_DIR}/TextMapPropagatorProxy.cpp ${CONTEXT_API_SOURCE_DIR}/CompositePropagatorProxy.cpp ${CONTEXT_API_SOURCE_DIR}/TextMapCarrierProxy.cpp @@ -229,7 +221,6 @@ set(OPENTELEMETRY_PROXY_SOURCES ${TRACE_SDK_SOURCE_DIR}/SimpleSpanProcessorProxy.cpp ${TRACE_SDK_SOURCE_DIR}/BatchSpanProcessorProxy.cpp ${TRACE_SDK_SOURCE_DIR}/ParentBasedSamplerProxy.cpp - ${METRICS_SDK_SOURCE_DIR}/MeterProviderProxy.cpp ${COMMON_SDK_SOURCE_DIR}/resource.cpp) if(WITH_OTLP_HTTP) set(OPENTELEMETRY_PROXY_SOURCES ${OPENTELEMETRY_PROXY_SOURCES} @@ -286,19 +277,16 @@ set(OTEL_CPP_LINK_LIBRARIES ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_trace${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_version${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_logs${CMAKE_STATIC_LIBRARY_SUFFIX} - ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_metrics${CMAKE_STATIC_LIBRARY_SUFFIX} ${Protobuf_LIBRARIES}) if(WITH_OTLP_HTTP) set(OTEL_CPP_LINK_LIBRARIES ${OTEL_CPP_LINK_LIBRARIES} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_http${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_http_client${CMAKE_STATIC_LIBRARY_SUFFIX} - ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_http_metric${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_http_client_curl${CMAKE_STATIC_LIBRARY_SUFFIX} ${CURL_LIBRARIES}) endif() if(WITH_OTLP_GRPC) set(OTEL_CPP_LINK_LIBRARIES ${OTEL_CPP_LINK_LIBRARIES} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_client${CMAKE_STATIC_LIBRARY_SUFFIX} - ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_metrics${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto_grpc${OTEL_PROTO_LIBRARY_SUFFIX} gRPC::grpc++ absl::synchronization) @@ -385,12 +373,10 @@ libmexclass_client_install( # Install M files set(TRACE_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/trace/+opentelemetry) -set(METRICS_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/metrics/+opentelemetry) set(CONTEXT_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/context/+opentelemetry) set(BAGGAGE_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/baggage/+opentelemetry) set(COMMON_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/common/+opentelemetry) 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(OTLP_HTTP_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpHttpSpanExporter.m) set(OTLP_GRPC_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpGrpcSpanExporter.m) @@ -398,12 +384,10 @@ set(OTLP_GRPC_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp set(OTLP_EXPORTERS_DIR +opentelemetry/+exporters/+otlp) install(DIRECTORY ${TRACE_API_MATLAB_SOURCES} DESTINATION .) -install(DIRECTORY ${METRICS_API_MATLAB_SOURCES} DESTINATION .) install(DIRECTORY ${CONTEXT_API_MATLAB_SOURCES} DESTINATION .) install(DIRECTORY ${BAGGAGE_API_MATLAB_SOURCES} DESTINATION .) install(DIRECTORY ${COMMON_API_MATLAB_SOURCES} DESTINATION .) install(DIRECTORY ${TRACE_SDK_MATLAB_SOURCES} DESTINATION .) -install(DIRECTORY ${METRICS_SDK_MATLAB_SOURCES} DESTINATION .) install(FILES ${DEFAULT_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR}) if(WITH_OTLP_HTTP) install(FILES ${OTLP_HTTP_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR}) diff --git a/OtelMatlabProxyFactory.cpp b/OtelMatlabProxyFactory.cpp index 925094d..a2f1315 100644 --- a/OtelMatlabProxyFactory.cpp +++ b/OtelMatlabProxyFactory.cpp @@ -22,7 +22,6 @@ #include "opentelemetry-matlab/sdk/trace/AlwaysOffSamplerProxy.h" #include "opentelemetry-matlab/sdk/trace/TraceIdRatioBasedSamplerProxy.h" #include "opentelemetry-matlab/sdk/trace/ParentBasedSamplerProxy.h" -#include "opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h" #ifdef WITH_OTLP_HTTP #include "opentelemetry-matlab/exporters/otlp/OtlpHttpSpanExporterProxy.h" #endif @@ -55,9 +54,6 @@ OtelMatlabProxyFactory::make_proxy(const libmexclass::proxy::ClassName& class_na REGISTER_PROXY(libmexclass.opentelemetry.sdk.AlwaysOffSamplerProxy, libmexclass::opentelemetry::sdk::AlwaysOffSamplerProxy); REGISTER_PROXY(libmexclass.opentelemetry.sdk.TraceIdRatioBasedSamplerProxy, libmexclass::opentelemetry::sdk::TraceIdRatioBasedSamplerProxy); REGISTER_PROXY(libmexclass.opentelemetry.sdk.ParentBasedSamplerProxy, libmexclass::opentelemetry::sdk::ParentBasedSamplerProxy); - - REGISTER_PROXY(libmexclass.opentelemetry.sdk.MeterProviderProxy, libmexclass::opentelemetry::sdk::MeterProviderProxy); - #ifdef WITH_OTLP_HTTP REGISTER_PROXY(libmexclass.opentelemetry.exporters.OtlpHttpSpanExporterProxy, libmexclass::opentelemetry::exporters::OtlpHttpSpanExporterProxy); #endif diff --git a/api/metrics/+opentelemetry/+metrics/Counter.m b/api/metrics/+opentelemetry/+metrics/Counter.m deleted file mode 100644 index f416f41..0000000 --- a/api/metrics/+opentelemetry/+metrics/Counter.m +++ /dev/null @@ -1,59 +0,0 @@ -classdef Counter < handle - % Counter is a value that accumulates over time, - % you can think of this like an odometer on a car; it only ever goes up. - - % Copyright 2023 The MathWorks, Inc. - - properties (SetAccess=immutable) - Name (1,1) string - Description (1,1) string - Unit (1,1) string - end - - properties (Access=private) - Proxy % Proxy object to interface C++ code - end - - methods (Access={?opentelemetry.metrics.Meter}) - - function obj = Counter(proxy, ctname, ctdescription, ctunit) - % Private constructor. Use createCounter method of Meter - % to create Counters. - obj.Proxy = proxy; - obj.Name = ctname; - obj.Description = ctdescription; - obj.Unit = ctunit; - end - - end - - methods - - function add(obj, value, varargin) - % input value must be a numerical scalar - if isnumeric(value) && isscalar(value) - - if nargin == 2 - obj.Proxy.add(value); - - elseif isa(varargin{1}, "dictionary") - attrkeys = keys(varargin{1}); - attrvals = values(varargin{1},"cell"); - if all(cellfun(@iscell, attrvals)) - attrvals = [attrvals{:}]; - end - obj.Proxy.add(value,attrkeys,attrvals); - - else - attrkeys = [varargin{1:2:length(varargin)}]'; - attrvals = [varargin(2:2:length(varargin))]'; - obj.Proxy.add(value,attrkeys,attrvals); - end - end - - end - - end - - -end diff --git a/api/metrics/+opentelemetry/+metrics/Histogram.m b/api/metrics/+opentelemetry/+metrics/Histogram.m deleted file mode 100644 index 8abc9ee..0000000 --- a/api/metrics/+opentelemetry/+metrics/Histogram.m +++ /dev/null @@ -1,55 +0,0 @@ -classdef Histogram < handle - % Histogram is an instrument that adds or reduce values. - - % Copyright 2023 The MathWorks, Inc. - - properties (SetAccess=immutable) - Name (1,1) string - Description (1,1) string - Unit (1,1) string - end - - properties (Access=public) - Proxy % Proxy object to interface C++ code - end - - methods (Access={?opentelemetry.metrics.Meter}) - - function obj = Histogram(proxy, hiname, hidescription, hiunit) - % Private constructor. Use createHistogram method of Meter - % to create Histograms. - obj.Proxy = proxy; - obj.Name = hiname; - obj.Description = hidescription; - obj.Unit = hiunit; - end - - end - - methods - - function record(obj, value, varargin) - % input value must be a numerical scalar - if isnumeric(value) && isscalar(value) - if nargin == 2 - obj.Proxy.record(value); - elseif isa(varargin{1}, "dictionary") - attrkeys = keys(varargin{1}); - attrvals = values(varargin{1},"cell"); - if all(cellfun(@iscell, attrvals)) - attrvals = [attrvals{:}]; - end - obj.Proxy.record(value,attrkeys,attrvals); - else - attrkeys = [varargin{1:2:length(varargin)}]'; - attrvals = [varargin(2:2:length(varargin))]'; - obj.Proxy.record(value,attrkeys,attrvals); - end - end - - end - - end - - -end diff --git a/api/metrics/+opentelemetry/+metrics/Meter.m b/api/metrics/+opentelemetry/+metrics/Meter.m deleted file mode 100644 index 250a5b9..0000000 --- a/api/metrics/+opentelemetry/+metrics/Meter.m +++ /dev/null @@ -1,89 +0,0 @@ -classdef Meter < handle - % A Meter creates metric instruments, capturing measurements about a service at runtime. - % Meters are created from Meter Providers. - - % Copyright 2023 The MathWorks, Inc. - - properties (SetAccess=immutable) - Name (1,1) string % Meter name - Version (1,1) string % Meter version - Schema (1,1) string % URL that documents the schema of the generated spans - end - - properties (Access=private) - Proxy % Proxy object to interface C++ code - end - - methods (Access={?opentelemetry.sdk.metrics.MeterProvider}) - - function obj = Meter(proxy, mtname, mtversion, mtschema) - % Private constructor. Use getMeter method of MeterProvider - % to create Meters. - obj.Proxy = proxy; - obj.Name = mtname; - obj.Version = mtversion; - obj.Schema = mtschema; - end - - end - - methods - - function counter = createCounter(obj, ctname, ctdescription, ctunit) - arguments - obj - ctname - ctdescription = "" - ctunit = "" - end - import opentelemetry.common.mustBeScalarString - ctname = mustBeScalarString(ctname); - ctdescription = mustBeScalarString(ctdescription); - ctunit = mustBeScalarString(ctunit); - id = obj.Proxy.createCounter(ctname, ctdescription, ctunit); - CounterProxy = libmexclass.proxy.Proxy("Name", ... - "libmexclass.opentelemetry.CounterProxy", "ID", id); - counter = opentelemetry.metrics.Counter(CounterProxy, ctname, ctdescription, ctunit); - end - - - function updowncounter = createUpDownCounter(obj, ctname, ctdescription, ctunit) - arguments - obj - ctname - ctdescription = "" - ctunit = "" - end - - import opentelemetry.common.mustBeScalarString - ctname = mustBeScalarString(ctname); - ctdescription = mustBeScalarString(ctdescription); - ctunit = mustBeScalarString(ctunit); - id = obj.Proxy.createUpDownCounter(ctname, ctdescription, ctunit); - UpDownCounterProxy = libmexclass.proxy.Proxy("Name", ... - "libmexclass.opentelemetry.UpDownCounterProxy", "ID", id); - updowncounter = opentelemetry.metrics.UpDownCounter(UpDownCounterProxy, ctname, ctdescription, ctunit); - end - - - function histogram = createHistogram(obj, hiname, hidescription, hiunit) - arguments - obj - hiname - hidescription = "" - hiunit = "" - end - - import opentelemetry.common.mustBeScalarString - hiname = mustBeScalarString(hiname); - hidescription = mustBeScalarString(hidescription); - hiunit = mustBeScalarString(hiunit); - id = obj.Proxy.createHistogram(hiname, hidescription, hiunit); - HistogramProxy = libmexclass.proxy.Proxy("Name", ... - "libmexclass.opentelemetry.HistogramProxy", "ID", id); - histogram = opentelemetry.metrics.Histogram(HistogramProxy, hiname, hidescription, hiunit); - end - - end - -end diff --git a/api/metrics/+opentelemetry/+metrics/UpDownCounter.m b/api/metrics/+opentelemetry/+metrics/UpDownCounter.m deleted file mode 100644 index b008dc5..0000000 --- a/api/metrics/+opentelemetry/+metrics/UpDownCounter.m +++ /dev/null @@ -1,58 +0,0 @@ -classdef UpDownCounter < handle - % UpDownCounter is an instrument that adds or reduce values. - - % Copyright 2023 The MathWorks, Inc. - - properties (SetAccess=immutable) - Name (1,1) string - Description (1,1) string - Unit (1,1) string - end - - properties (Access=public) - Proxy % Proxy object to interface C++ code - end - - methods (Access={?opentelemetry.metrics.Meter}) - - function obj = UpDownCounter(proxy, ctname, ctdescription, ctunit) - % Private constructor. Use createUpDownCounter method of Meter - % to create UpDownCounters. - obj.Proxy = proxy; - obj.Name = ctname; - obj.Description = ctdescription; - obj.Unit = ctunit; - end - - end - - methods - - function add(obj, value, varargin) - % input value must be a numerical scalar - if isnumeric(value) && isscalar(value) - - if nargin == 2 - obj.Proxy.add(value); - - elseif isa(varargin{1}, "dictionary") - attrkeys = keys(varargin{1}); - attrvals = values(varargin{1},"cell"); - if all(cellfun(@iscell, attrvals)) - attrvals = [attrvals{:}]; - end - obj.Proxy.add(value,attrkeys,attrvals); - - else - attrkeys = [varargin{1:2:length(varargin)}]'; - attrvals = [varargin(2:2:length(varargin))]'; - obj.Proxy.add(value,attrkeys,attrvals); - end - end - - end - - end - - -end diff --git a/api/metrics/include/opentelemetry-matlab/metrics/CounterProxy.h b/api/metrics/include/opentelemetry-matlab/metrics/CounterProxy.h deleted file mode 100644 index 6271d60..0000000 --- a/api/metrics/include/opentelemetry-matlab/metrics/CounterProxy.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#pragma once - -#include "libmexclass/proxy/Proxy.h" -#include "libmexclass/proxy/method/Context.h" - -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/metrics/sync_instruments.h" - -#include "opentelemetry-matlab/common/attribute.h" -#include "opentelemetry-matlab/common/ProcessedAttributes.h" - -namespace metrics_api = opentelemetry::metrics; -namespace nostd = opentelemetry::nostd; - -namespace libmexclass::opentelemetry { -class CounterProxy : public libmexclass::proxy::Proxy { - public: - CounterProxy(nostd::shared_ptr > ct) : CppCounter(ct) { - REGISTER_METHOD(CounterProxy, add); - } - - void add(libmexclass::proxy::method::Context& context); - - private: - - nostd::shared_ptr > CppCounter; - -}; -} // namespace libmexclass::opentelemetry - - diff --git a/api/metrics/include/opentelemetry-matlab/metrics/HistogramProxy.h b/api/metrics/include/opentelemetry-matlab/metrics/HistogramProxy.h deleted file mode 100644 index 248c628..0000000 --- a/api/metrics/include/opentelemetry-matlab/metrics/HistogramProxy.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#pragma once - -#include "libmexclass/proxy/Proxy.h" -#include "libmexclass/proxy/method/Context.h" - -#include "opentelemetry/context/context.h" -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/metrics/sync_instruments.h" - -#include "opentelemetry-matlab/common/attribute.h" -#include "opentelemetry-matlab/common/ProcessedAttributes.h" -#include "opentelemetry-matlab/context/ContextProxy.h" - -namespace metrics_api = opentelemetry::metrics; -namespace context = opentelemetry::context; -namespace nostd = opentelemetry::nostd; - -namespace libmexclass::opentelemetry { -class HistogramProxy : public libmexclass::proxy::Proxy { - public: - HistogramProxy(nostd::shared_ptr > hist) : CppHistogram(hist) { - REGISTER_METHOD(HistogramProxy, record); - } - - void record(libmexclass::proxy::method::Context& context); - - private: - - nostd::shared_ptr > CppHistogram; - -}; -} // namespace libmexclass::opentelemetry - - diff --git a/api/metrics/include/opentelemetry-matlab/metrics/MeterProxy.h b/api/metrics/include/opentelemetry-matlab/metrics/MeterProxy.h deleted file mode 100644 index ab45e48..0000000 --- a/api/metrics/include/opentelemetry-matlab/metrics/MeterProxy.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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 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 CppMeter; -}; -} // namespace libmexclass::opentelemetry diff --git a/api/metrics/include/opentelemetry-matlab/metrics/UpDownCounterProxy.h b/api/metrics/include/opentelemetry-matlab/metrics/UpDownCounterProxy.h deleted file mode 100644 index 6a41c75..0000000 --- a/api/metrics/include/opentelemetry-matlab/metrics/UpDownCounterProxy.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#pragma once - -#include "libmexclass/proxy/Proxy.h" -#include "libmexclass/proxy/method/Context.h" - -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/metrics/sync_instruments.h" - -#include "opentelemetry-matlab/common/attribute.h" -#include "opentelemetry-matlab/common/ProcessedAttributes.h" - -namespace metrics_api = opentelemetry::metrics; -namespace nostd = opentelemetry::nostd; - -namespace libmexclass::opentelemetry { -class UpDownCounterProxy : public libmexclass::proxy::Proxy { - public: - UpDownCounterProxy(nostd::shared_ptr > ct) : CppUpDownCounter(ct) { - REGISTER_METHOD(UpDownCounterProxy, add); - } - - void add(libmexclass::proxy::method::Context& context); - - private: - - nostd::shared_ptr > CppUpDownCounter; - -}; -} // namespace libmexclass::opentelemetry - - diff --git a/api/metrics/src/CounterProxy.cpp b/api/metrics/src/CounterProxy.cpp deleted file mode 100644 index 77e498f..0000000 --- a/api/metrics/src/CounterProxy.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#include "opentelemetry-matlab/metrics/CounterProxy.h" - -#include "libmexclass/proxy/ProxyManager.h" - - -#include "MatlabDataArray.hpp" - -#include - -namespace libmexclass::opentelemetry { - - -void CounterProxy::add(libmexclass::proxy::method::Context& context){ - - matlab::data::Array value_mda = context.inputs[0]; - double value = static_cast(value_mda[0]); - size_t nin = context.inputs.getNumberOfElements(); - if (nin == 1){ - CppCounter->Add(value); - } - // add attributes - else { - ProcessedAttributes attrs; - matlab::data::StringArray attrnames_mda = context.inputs[1]; - matlab::data::Array attrvalues_mda = context.inputs[2]; - size_t nattrs = attrnames_mda.getNumberOfElements(); - for (size_t i = 0; i < nattrs; i ++){ - std::string attrname = static_cast(attrnames_mda[i]); - matlab::data::Array attrvalue = attrvalues_mda[i]; - processAttribute(attrname, attrvalue, attrs); - } - CppCounter->Add(value, attrs.Attributes); - } - -} - - - -} // namespace libmexclass::opentelemetry diff --git a/api/metrics/src/HistogramProxy.cpp b/api/metrics/src/HistogramProxy.cpp deleted file mode 100644 index 3d3ea5f..0000000 --- a/api/metrics/src/HistogramProxy.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#include "opentelemetry-matlab/metrics/HistogramProxy.h" - -#include "libmexclass/proxy/ProxyManager.h" - - -#include "MatlabDataArray.hpp" - -#include - -namespace libmexclass::opentelemetry { - - -void HistogramProxy::record(libmexclass::proxy::method::Context& context){ - // Get value - matlab::data::Array value_mda = context.inputs[0]; - double value = static_cast(value_mda[0]); - // Create empty context - auto ctxt = context_api::Context(); - // If no attributes input, record value and context - size_t nin = context.inputs.getNumberOfElements(); - if (nin == 1){ - CppHistogram->Record(value, ctxt); - } - // Otherwise, get attributes, record value, attributes and context - else { - ProcessedAttributes attrs; - matlab::data::StringArray attrnames_mda = context.inputs[1]; - matlab::data::Array attrvalues_mda = context.inputs[2]; - size_t nattrs = attrnames_mda.getNumberOfElements(); - for (size_t i = 0; i < nattrs; i ++){ - std::string attrname = static_cast(attrnames_mda[i]); - matlab::data::Array attrvalue = attrvalues_mda[i]; - processAttribute(attrname, attrvalue, attrs); - } - CppHistogram->Record(value, attrs.Attributes, ctxt); - } - -} - - - -} // namespace libmexclass::opentelemetry diff --git a/api/metrics/src/MeterProxy.cpp b/api/metrics/src/MeterProxy.cpp deleted file mode 100644 index 3d0d399..0000000 --- a/api/metrics/src/MeterProxy.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#include "opentelemetry-matlab/metrics/MeterProxy.h" - -#include "libmexclass/proxy/ProxyManager.h" - -#include "MatlabDataArray.hpp" - -#include - -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(name_mda[0]); - matlab::data::StringArray description_mda = context.inputs[1]; - std::string description= static_cast(description_mda[0]); - matlab::data::StringArray unit_mda = context.inputs[2]; - std::string unit = static_cast(unit_mda[0]); - - nostd::shared_ptr > ct = std::move(CppMeter->CreateDoubleCounter(name, description, unit)); - - // instantiate a CounterProxy instance - CounterProxy* newproxy = new CounterProxy(ct); - auto proxy = std::shared_ptr(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(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(name_mda[0]); - matlab::data::StringArray description_mda = context.inputs[1]; - std::string description= static_cast(description_mda[0]); - matlab::data::StringArray unit_mda = context.inputs[2]; - std::string unit = static_cast(unit_mda[0]); - - nostd::shared_ptr > ct = std::move(CppMeter->CreateDoubleUpDownCounter -(name, description, unit)); - - // instantiate a UpDownCounterProxy instance - UpDownCounterProxy* newproxy = new UpDownCounterProxy(ct); - auto proxy = std::shared_ptr(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(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(name_mda[0]); - matlab::data::StringArray description_mda = context.inputs[1]; - std::string description= static_cast(description_mda[0]); - matlab::data::StringArray unit_mda = context.inputs[2]; - std::string unit = static_cast(unit_mda[0]); - - nostd::shared_ptr > hist = std::move(CppMeter->CreateDoubleHistogram(name, description, unit)); - - // instantiate a HistogramProxy instance - HistogramProxy* newproxy = new HistogramProxy(hist); - auto proxy = std::shared_ptr(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(proxyid); - context.outputs[0] = proxyid_mda; -} - - -} // namespace libmexclass::opentelemetry diff --git a/api/metrics/src/UpDownCounterProxy.cpp b/api/metrics/src/UpDownCounterProxy.cpp deleted file mode 100644 index f4d35ef..0000000 --- a/api/metrics/src/UpDownCounterProxy.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#include "opentelemetry-matlab/metrics/UpDownCounterProxy.h" - -#include "libmexclass/proxy/ProxyManager.h" - - -#include "MatlabDataArray.hpp" - -#include - -namespace libmexclass::opentelemetry { - - -void UpDownCounterProxy::add(libmexclass::proxy::method::Context& context){ - - matlab::data::Array value_mda = context.inputs[0]; - double value = static_cast(value_mda[0]); - size_t nin = context.inputs.getNumberOfElements(); - if (nin == 1){ - CppUpDownCounter->Add(value); - } - // add attributes - else { - ProcessedAttributes attrs; - matlab::data::StringArray attrnames_mda = context.inputs[1]; - matlab::data::Array attrvalues_mda = context.inputs[2]; - size_t nattrs = attrnames_mda.getNumberOfElements(); - for (size_t i = 0; i < nattrs; i ++){ - std::string attrname = static_cast(attrnames_mda[i]); - matlab::data::Array attrvalue = attrvalues_mda[i]; - processAttribute(attrname, attrvalue, attrs); - } - CppUpDownCounter->Add(value, attrs.Attributes); - } - -} - - - -} // namespace libmexclass::opentelemetry diff --git a/sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m b/sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m deleted file mode 100644 index ec019eb..0000000 --- a/sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m +++ /dev/null @@ -1,56 +0,0 @@ -classdef MeterProvider < handle - % An SDK implementation of meter provider, which stores a set of configurations used - % in a metrics system. - - % Copyright 2023 The MathWorks, Inc. - - properties (Access=private) - Proxy - end - - methods - function obj = MeterProvider() - % SDK implementation of tracer provider - % MP = OPENTELEMETRY.SDK.METRICS.METERPROVIDER creates a meter - % provider that uses a periodic exporting metric reader and default configurations. - % - % MP = OPENTELEMETRY.SDK.METRICS.METERPROVIDER(R) uses metric - % reader R. Currently, the only supported metric reader is the periodic - % exporting metric reader. - % - % TP = OPENTELEMETRY.SDK.METRICS.METERPROVIDER(R, PARAM1, VALUE1, - % PARAM2, VALUE2, ...) specifies optional parameter name/value pairs. - % Parameters are: - % "View" - View object used to customize collected metrics. - % "Resource" - Additional resource attributes. - % Specified as a dictionary. - % - % See also OPENTELEMETRY.SDK.METRICS.PERIODICEXPORTINGMETRICREADER - % OPENTELEMETRY.SDK.METRICS.VIEW - - obj.Proxy = libmexclass.proxy.Proxy("Name", ... - "libmexclass.opentelemetry.sdk.MeterProviderProxy", ... - "ConstructorArguments", {}); - end - - function meter = getMeter(obj, mtname, mtversion, mtschema) - arguments - obj - mtname - mtversion = "" - mtschema = "" - end - % name, version, schema accepts any types that can convert to a - % string - import opentelemetry.common.mustBeScalarString - mtname = mustBeScalarString(mtname); - mtversion = mustBeScalarString(mtversion); - mtschema = mustBeScalarString(mtschema); - id = obj.Proxy.getMeter(mtname, mtversion, mtschema); - Meterproxy = libmexclass.proxy.Proxy("Name", ... - "libmexclass.opentelemetry.MeterProxy", "ID", id); - meter = opentelemetry.metrics.Meter(Meterproxy, mtname, mtversion, mtschema); - end - - end -end diff --git a/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h b/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h deleted file mode 100644 index 3526822..0000000 --- a/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#pragma once - -#include "libmexclass/proxy/Proxy.h" -#include "libmexclass/proxy/method/Context.h" - - -#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" -#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" -#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" -#include "opentelemetry/exporters/otlp/otlp_http_exporter.h" - -#include "opentelemetry/metrics/provider.h" -#include "opentelemetry/metrics/meter_provider.h" -#include "opentelemetry/sdk/common/global_log_handler.h" -#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" -#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_provider.h" -#include "opentelemetry/sdk/metrics/meter_provider_factory.h" -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" - -#include "opentelemetry-matlab/metrics/MeterProxy.h" - -namespace metrics_api = opentelemetry::metrics; -namespace nostd = opentelemetry::nostd; -namespace metrics_sdk = opentelemetry::sdk::metrics; -namespace common = opentelemetry::common; -namespace otlpexporter = opentelemetry::exporter::otlp; - - -namespace libmexclass::opentelemetry::sdk { -class MeterProviderProxy : public libmexclass::proxy::Proxy { - public: - MeterProviderProxy(nostd::shared_ptr mp) : CppMeterProvider(mp) { - REGISTER_METHOD(MeterProviderProxy, getMeter); - } - - static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments); - - void getMeter(libmexclass::proxy::method::Context& context); - - protected: - nostd::shared_ptr CppMeterProvider; -}; -} // namespace libmexclass::opentelemetry diff --git a/sdk/metrics/src/MeterProviderProxy.cpp b/sdk/metrics/src/MeterProviderProxy.cpp deleted file mode 100644 index e0eb3c3..0000000 --- a/sdk/metrics/src/MeterProviderProxy.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2023 The MathWorks, Inc. - -#include "opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h" - -#include "libmexclass/proxy/ProxyManager.h" - -#include - -namespace libmexclass::opentelemetry::sdk { -libmexclass::proxy::MakeResult MeterProviderProxy::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { - - libmexclass::proxy::MakeResult out; - - auto exporter = otlpexporter::OtlpHttpMetricExporterFactory::Create(); - // Initialize and set the periodic metrics reader - metrics_sdk::PeriodicExportingMetricReaderOptions options; - auto reader = metrics_sdk::PeriodicExportingMetricReaderFactory::Create(std::move(exporter), options); - - auto p = metrics_sdk::MeterProviderFactory::Create(); - auto *p_sdk = static_cast(p.get()); - p_sdk->AddMetricReader(std::move(reader)); - - auto p_out = nostd::shared_ptr(std::move(p)); - out = std::make_shared(p_out); - - return out; -} - -void MeterProviderProxy::getMeter(libmexclass::proxy::method::Context& context) { - // Always assumes 3 inputs - matlab::data::StringArray name_mda = context.inputs[0]; - std::string name = static_cast(name_mda[0]); - matlab::data::StringArray version_mda = context.inputs[1]; - std::string version = static_cast(version_mda[0]); - matlab::data::StringArray schema_mda = context.inputs[2]; - std::string schema = static_cast(schema_mda[0]); - - auto mt = CppMeterProvider->GetMeter(name, version, schema); - - // instantiate a MeterProxy instance - MeterProxy* newproxy = new MeterProxy(mt); - auto mtproxy = std::shared_ptr(newproxy); - - // obtain a proxy ID - libmexclass::proxy::ID proxyid = libmexclass::proxy::ProxyManager::manageProxy(mtproxy); - - // return the ID - matlab::data::ArrayFactory factory; - auto proxyid_mda = factory.createScalar(proxyid); - context.outputs[0] = proxyid_mda; -} - - -} // namespace libmexclass::opentelemetry diff --git a/test/tmetrics.m b/test/tmetrics.m deleted file mode 100644 index c452504..0000000 --- a/test/tmetrics.m +++ /dev/null @@ -1,364 +0,0 @@ -classdef tmetrics < matlab.unittest.TestCase - % tests for traces and spans - - % Copyright 2023 The MathWorks, Inc. - - properties - OtelConfigFile - OtelRoot - JsonFile - PidFile - OtelcolName - Otelcol - ListPid - ReadPidList - ExtractPid - Sigint - Sigterm - end - - methods (TestClassSetup) - function setupOnce(testCase) - commonSetupOnce(testCase); - end - end - - methods (TestMethodSetup) - function setup(testCase) - commonSetup(testCase); - end - end - - methods (TestMethodTeardown) - function teardown(testCase) - commonTeardown(testCase); - end - end - - methods (Test) - - function testCounterBasic(testCase) - % test names and added value in Counter - - metername = "foo"; - countername = "bar"; - - p = opentelemetry.sdk.metrics.MeterProvider(); - mt = p.getMeter(metername); - ct = mt.createCounter(countername); - - % verify MATLAB object properties - verifyEqual(testCase, mt.Name, metername); - verifyEqual(testCase, mt.Version, ""); - verifyEqual(testCase, mt.Schema, ""); - verifyEqual(testCase, ct.Name, countername); - - % create testing value - val = 10; - - % add value and attributes - ct.add(val); - - % wait for default collector response time (60s) - pause(70); - - % fetch result - results = readJsonResults(testCase); - results = results{1}; - - % verify meter and counter names - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.metrics.name), countername); - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.scope.name), metername); - - % fetch datapoint - dp = results.resourceMetrics.scopeMetrics.metrics.sum.dataPoints; - - % verify counter value - verifyEqual(testCase, dp.asDouble, val); - - end - - - function testCounterAddAttributes(testCase) - % test names, added value and attributes in Counter - - metername = "foo"; - countername = "bar"; - - p = opentelemetry.sdk.metrics.MeterProvider(); - mt = p.getMeter(metername); - ct = mt.createCounter(countername); - - % create testing value and dictionary - dict = dictionary("k1","v1","k2",5); - vals = [1,2.4,3]; - dict_keys = keys(dict); - dict_vals = values(dict); - - % add value and attributes - ct.add(vals(1),dict); - ct.add(vals(2),dict); - ct.add(vals(3),dict_keys(1),dict_vals(1),dict_keys(2),dict_vals(2)); - - % wait for default collector response time (60s) - pause(70); - - % fetch result - results = readJsonResults(testCase); - results = results{1}; - - % verify meter and counter names - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.metrics.name), countername); - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.scope.name), metername); - - % fetch datapoint - dp = results.resourceMetrics.scopeMetrics.metrics.sum.dataPoints; - - % verify counter value - verifyEqual(testCase, dp.asDouble, sum(vals)); - - % verify counter attributes - resourcekeys = string({dp.attributes.key}); - idx1 = find(resourcekeys == dict_keys(1)); - idx2 = find(resourcekeys == dict_keys(2)); - verifyEqual(testCase, string(dp.attributes(idx1).key), dict_keys(1)); - verifyEqual(testCase, string(dp.attributes(idx1).value.stringValue), dict_vals(1)); - verifyEqual(testCase, string(dp.attributes(idx2).key), dict_keys(2)); - verifyEqual(testCase, string(dp.attributes(idx2).value.stringValue), dict_vals(2)); - - end - - - function testCounterAddNegative(testCase) - % test if counter value remain 0 when added negative value - - metername = "foo"; - countername = "bar"; - - p = opentelemetry.sdk.metrics.MeterProvider(); - mt = p.getMeter(metername); - ct = mt.createCounter(countername); - - % add negative value to counter - ct.add(-1); - pause(70); - - % fetch results - results = readJsonResults(testCase); - results = results{1}; - dp = results.resourceMetrics.scopeMetrics.metrics.sum.dataPoints; - - % verify that the counter value is still 0 - verifyEqual(testCase, dp.asDouble, 0); - - end - - - function testUpDownCounterBasic(testCase) - % test names and added value in UpDownCounter - - metername = "foo"; - countername = "bar"; - - p = opentelemetry.sdk.metrics.MeterProvider(); - mt = p.getMeter(metername); - ct = mt.createUpDownCounter(countername); - - % verify MATLAB object properties - verifyEqual(testCase, mt.Name, metername); - verifyEqual(testCase, mt.Version, ""); - verifyEqual(testCase, mt.Schema, ""); - verifyEqual(testCase, ct.Name, countername); - - % create testing value - val = -10; - - % add value and attributes - ct.add(val); - - % wait for default collector response time (60s) - pause(70); - - % fetch result - results = readJsonResults(testCase); - results = results{1}; - - % verify meter and counter names - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.metrics.name), countername); - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.scope.name), metername); - - % fetch datapoint - dp = results.resourceMetrics.scopeMetrics.metrics.sum.dataPoints; - - % verify counter value - verifyEqual(testCase, dp.asDouble, val); - - end - - - function testUpDownCounterAddAttributes(testCase) - % test names, added value and attributes in UpDownCounter - - metername = "foo"; - countername = "bar"; - - p = opentelemetry.sdk.metrics.MeterProvider(); - mt = p.getMeter(metername); - ct = mt.createUpDownCounter(countername); - - % create testing value and dictionary - dict = dictionary("k1","v1","k2",5); - vals = [2,-1.9,3]; - dict_keys = keys(dict); - dict_vals = values(dict); - - % add value and attributes - ct.add(vals(1),dict); - ct.add(vals(2),dict); - ct.add(vals(3),dict_keys(1),dict_vals(1),dict_keys(2),dict_vals(2)); - - % wait for default collector response time (60s) - pause(70); - - % fetch result - results = readJsonResults(testCase); - results = results{1}; - - % verify meter and counter names - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.metrics.name), countername); - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.scope.name), metername); - - % fetch datapoint - dp = results.resourceMetrics.scopeMetrics.metrics.sum.dataPoints; - - % verify counter value - verifyEqual(testCase, dp.asDouble, sum(vals)); - - % verify counter attributes - resourcekeys = string({dp.attributes.key}); - idx1 = find(resourcekeys == dict_keys(1)); - idx2 = find(resourcekeys == dict_keys(2)); - verifyEqual(testCase, string(dp.attributes(idx1).key), dict_keys(1)); - verifyEqual(testCase, string(dp.attributes(idx1).value.stringValue), dict_vals(1)); - verifyEqual(testCase, string(dp.attributes(idx2).key), dict_keys(2)); - verifyEqual(testCase, string(dp.attributes(idx2).value.stringValue), dict_vals(2)); - - end - - - function testHistogramBasic(testCase) - % test recorded values in histogram - - metername = "foo"; - histname = "bar"; - - p = opentelemetry.sdk.metrics.MeterProvider(); - mt = p.getMeter(metername); - hist = mt.createHistogram(histname); - - % verify MATLAB object properties - verifyEqual(testCase, mt.Name, metername); - verifyEqual(testCase, mt.Version, ""); - verifyEqual(testCase, mt.Schema, ""); - verifyEqual(testCase, hist.Name, histname); - - % create value for histogram - val = 1; - - % record value - hist.record(val); - - % wait for collector response - pause(75); - - % fetch results - results = readJsonResults(testCase); - results = results{1}; - dp = results.resourceMetrics.scopeMetrics.metrics.histogram.dataPoints; - bounds = dp.explicitBounds; - counts = dp.bucketCounts; - - % verify meter and histogram names - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.metrics.name), histname); - verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.scope.name), metername); - - % verify statistics - verifyEqual(testCase, dp.min, val); - verifyEqual(testCase, dp.max, val); - verifyEqual(testCase, dp.sum, val); - - % verify count in bucket - len = length(counts); - verifyEqual(testCase, str2double(counts{1}), sum(val<=bounds(1))); - for i = 2:(len-1) - lower = bounds(i-1); - upper = bounds(i); - expect_count = sum(val>lower & val<=upper); - verifyEqual(testCase, str2double(counts{i}), expect_count); - end - verifyEqual(testCase, str2double(counts{len}), sum(val>bounds(len-1))); - - end - - - function testHistogramRecordAttributes(testCase) - % test recorded values and attributes in histogram - - metername = "foo"; - histname = "bar"; - - p = opentelemetry.sdk.metrics.MeterProvider(); - mt = p.getMeter(metername); - hist = mt.createHistogram(histname); - - % create value and attributes for histogram - dict = dictionary("k1","v1","k2","v2"); - vals = [1,5,8.1]; - dict_keys = keys(dict); - dict_vals = values(dict); - - % record value and attributes - hist.record(vals(1),dict); - hist.record(vals(2),dict); - hist.record(vals(3),dict_keys(1),dict_vals(1),dict_keys(2),dict_vals(2)); - - % wait for collector response - pause(75); - - % fetch results - results = readJsonResults(testCase); - results = results{1}; - dp = results.resourceMetrics.scopeMetrics.metrics.histogram.dataPoints; - bounds = dp.explicitBounds; - counts = dp.bucketCounts; - - % verify statistics - verifyEqual(testCase, dp.min, min(vals)); - verifyEqual(testCase, dp.max, max(vals)); - verifyEqual(testCase, dp.sum, sum(vals)); - - % verify attributes - resourcekeys = string({dp.attributes.key}); - idx1 = find(resourcekeys == dict_keys(1)); - idx2 = find(resourcekeys == dict_keys(2)); - verifyEqual(testCase, string(dp.attributes(idx1).key), dict_keys(1)); - verifyEqual(testCase, string(dp.attributes(idx1).value.stringValue), dict_vals(1)); - verifyEqual(testCase, string(dp.attributes(idx2).key), dict_keys(2)); - verifyEqual(testCase, string(dp.attributes(idx2).value.stringValue), dict_vals(2)); - - % verify count in bucket - len = length(counts); - verifyEqual(testCase, str2double(counts{1}), sum(vals<=bounds(1))); - for i = 2:(len-1) - lower = bounds(i-1); - upper = bounds(i); - expect_count = sum(vals>lower & vals<=upper); - verifyEqual(testCase, str2double(counts{i}), expect_count); - end - verifyEqual(testCase, str2double(counts{len}), sum(vals>bounds(len-1))); - - end - - end - -end