From 97754c9c9cd3587370dc4a361e423b7333095047 Mon Sep 17 00:00:00 2001 From: duncanpo Date: Tue, 12 Dec 2023 14:05:47 -0500 Subject: [PATCH] Add help texts for metrics --- README.md | 19 ++- api/metrics/+opentelemetry/+metrics/Counter.m | 10 ++ .../+opentelemetry/+metrics/Histogram.m | 10 ++ api/metrics/+opentelemetry/+metrics/Meter.m | 34 ++++- .../+opentelemetry/+metrics/UpDownCounter.m | 10 ++ .../+sdk/+metrics/MeterProvider.m | 46 +++--- .../+sdk/+metrics/MetricExporter.m | 2 +- .../+metrics/PeriodicExportingMetricReader.m | 33 ++++- .../+opentelemetry/+sdk/+metrics/View.m | 139 +++++++++++++----- .../sdk/metrics/ViewProxy.h | 2 - sdk/metrics/src/ViewProxy.cpp | 42 ++++-- test/tmetrics_sdk.m | 2 +- 12 files changed, 263 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index b6c1225..731ef7e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ MATLAB® interface to [OpenTelemetry™](https://opentelemetry.io/), based on the [OpenTelemetry Specification](https://opentelemetry.io/docs/reference/specification/). OpenTelemetry is an observability framework for creating and managing telemetry data, such as traces, metrics, and logs. This data can then be sent to an observability back-end for monitoring, alerts, and analysis. ### Status -- Currently only tracing is supported. Metrics and logs will be in the future. +- Currently only tracing and metrics are supported. Logs will be in the future. - This package is supported and has been tested on Windows®, Linux®, and macOS. ### MathWorks Products (https://www.mathworks.com) @@ -43,6 +43,7 @@ otelcol --config >> addpath ``` ## Examples +### Tracing 1. Create a default tracer provider and save it. ``` >> p = opentelemetry.sdk.trace.TracerProvider(); @@ -58,6 +59,22 @@ otelcol --config >> sp.endSpan(); ``` 4. If your collector is configured to display the data, you should see your span displayed. +### Metrics +1. Create a default meter provider and save it. +``` +>> p = opentelemetry.sdk.metrics.MeterProvider(); +>> setMeterProvider(p); +``` +2. Create a counter +``` +>> m = opentelemetry.metrics.getMeter("First Meter"); +>> c = m.createCounter("FirstCounter"); +``` +3. Increment the counter +``` +>> c.add(10); +``` +4. If your collector is configured to display the data, you should see your counter displayed after 1 minute. For more examples, see the "examples" folder. diff --git a/api/metrics/+opentelemetry/+metrics/Counter.m b/api/metrics/+opentelemetry/+metrics/Counter.m index f189b90..a851740 100644 --- a/api/metrics/+opentelemetry/+metrics/Counter.m +++ b/api/metrics/+opentelemetry/+metrics/Counter.m @@ -14,6 +14,16 @@ methods function add(obj, value, varargin) + % ADD Add to counter value + % ADD(C, VALUE) adds a nonnegative scalar numeric value to + % the counter. + % + % ADD(C, VALUE, ATTRIBUTES) also specifies attributes as a + % dictionary + % + % ADD(C, VALUE, ATTRNAME1, ATTRVALUE1, ATTRNAME2, + % ATTRVALUE2, ...) specifies attributes as trailing + % name-value pairs. obj.processValue(value, varargin{:}); end end diff --git a/api/metrics/+opentelemetry/+metrics/Histogram.m b/api/metrics/+opentelemetry/+metrics/Histogram.m index 439b636..c81cfa6 100644 --- a/api/metrics/+opentelemetry/+metrics/Histogram.m +++ b/api/metrics/+opentelemetry/+metrics/Histogram.m @@ -13,6 +13,16 @@ methods function record(obj, value, varargin) + % RECORD Aggregate a value into a histogram bin + % RECORD(H, VALUE) determine which bin VALUE falls into and + % increment that bin by 1. + % + % RECORD(H, VALUE, ATTRIBUTES) also specifies attributes as a + % dictionary + % + % RECORD(H, VALUE, ATTRNAME1, ATTRVALUE1, ATTRNAME2, + % ATTRVALUE2, ...) specifies attributes as trailing + % name-value pairs. obj.processValue(value, varargin{:}); end end diff --git a/api/metrics/+opentelemetry/+metrics/Meter.m b/api/metrics/+opentelemetry/+metrics/Meter.m index 45c2486..17e2eda 100644 --- a/api/metrics/+opentelemetry/+metrics/Meter.m +++ b/api/metrics/+opentelemetry/+metrics/Meter.m @@ -30,6 +30,15 @@ methods function counter = createCounter(obj, ctname, ctdescription, ctunit) + % CREATECOUNTER Create a counter + % C = CREATECOUNTER(M, NAME) creates a counter with the specified + % name. A counter's value can only increase but not + % decrease. + % + % C = CREATECOUNTER(M, NAME, DESCRIPTION, UNIT) also + % specifies a description and a unit. + % + % See also CREATEUPDOWNCOUNTER, CREATEHISTOGRAM arguments obj ctname @@ -38,8 +47,6 @@ end import opentelemetry.common.mustBeScalarString ctname = mustBeScalarString(ctname); - % cpp-opentelemetry end does not allow string input with spaces, - % replace any spaces with underscores as a temporary fix ctdescription = mustBeScalarString(ctdescription); ctunit = mustBeScalarString(ctunit); id = obj.Proxy.createCounter(ctname, ctdescription, ctunit); @@ -50,6 +57,15 @@ function updowncounter = createUpDownCounter(obj, ctname, ctdescription, ctunit) + % CREATEUPDOWNCOUNTER Create an UpDownCounter + % C = CREATEUPDOWNCOUNTER(M, NAME) creates an UpDownCounter + % with the specified name. An UpDownCounter's value can + % increase or decrease. + % + % C = CREATEUPDOWNCOUNTER(M, NAME, DESCRIPTION, UNIT) also + % specifies a description and a unit. + % + % See also CREATECOUNTER, CREATEHISTOGRAM arguments obj ctname @@ -59,8 +75,6 @@ import opentelemetry.common.mustBeScalarString ctname = mustBeScalarString(ctname); - % cpp-opentelemetry end does not allow string input with spaces, - % replace any spaces with underscores as a temporary fix ctdescription = mustBeScalarString(ctdescription); ctunit = mustBeScalarString(ctunit); id = obj.Proxy.createUpDownCounter(ctname, ctdescription, ctunit); @@ -71,6 +85,16 @@ function histogram = createHistogram(obj, hiname, hidescription, hiunit) + % CREATEHISTOGRAM Create a histogram + % H = CREATEHISTOGRAM(M, NAME) creates a histogram with the specified + % name. A histogram aggregates values into bins. Bins can be + % customized using a View object. + % + % H = CREATEHISTOGRAM(M, NAME, DESCRIPTION, UNIT) also + % specifies a description and a unit. + % + % See also CREATECOUNTER, CREATEUPDOWNCOUNTER, + % OPENTELEMETRY.SDK.METRICS.VIEW arguments obj hiname @@ -80,8 +104,6 @@ import opentelemetry.common.mustBeScalarString hiname = mustBeScalarString(hiname); - % cpp-opentelemetry end does not allow string input with spaces, - % replace any spaces with underscores as a temporary fix hidescription = mustBeScalarString(hidescription); hiunit = mustBeScalarString(hiunit); id = obj.Proxy.createHistogram(hiname, hidescription, hiunit); diff --git a/api/metrics/+opentelemetry/+metrics/UpDownCounter.m b/api/metrics/+opentelemetry/+metrics/UpDownCounter.m index 073c3d7..cf32bde 100644 --- a/api/metrics/+opentelemetry/+metrics/UpDownCounter.m +++ b/api/metrics/+opentelemetry/+metrics/UpDownCounter.m @@ -13,6 +13,16 @@ methods function add(obj, value, varargin) + % ADD Add to UpDownCounter value + % ADD(C, VALUE) adds scalar numeric value to the + % UpDownCounter. VALUE can be positive or negative. + % + % ADD(C, VALUE, ATTRIBUTES) also specifies attributes as a + % dictionary + % + % ADD(C, VALUE, ATTRNAME1, ATTRVALUE1, ATTRNAME2, + % ATTRVALUE2, ...) specifies attributes as trailing + % name-value pairs. obj.processValue(value, varargin{:}); end end diff --git a/sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m b/sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m index 268802d..f5fc5b0 100644 --- a/sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m +++ b/sdk/metrics/+opentelemetry/+sdk/+metrics/MeterProvider.m @@ -8,23 +8,23 @@ isShutdown (1,1) logical = false end - properties (Access=public) - MetricReader - View - Resource + properties (SetAccess=private) + MetricReader % Metric reader controls how often metrics are exported + View % View object used to customize collected metrics + Resource % Attributes attached to all metrics end methods function obj = MeterProvider(reader, optionnames, optionvalues) % SDK implementation of meter provider - % MP = OPENTELEMETRY.SDK.METRICS.METERPROVIDER creates a meter + % 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. + % reader R. Currently, the only supported metric reader is the periodic + % exporting metric reader. % - % TP = OPENTELEMETRY.SDK.METRICS.METERPROVIDER(R, PARAM1, VALUE1, + % 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. @@ -59,7 +59,7 @@ "ConstructorArguments", {mpproxy.ID}); % leave other properties unassigned, they won't be used else - validnames = ["Resource"]; + validnames = "Resource"; resourcekeys = string.empty(); resourcevalues = {}; resource = dictionary(resourcekeys, resourcevalues); @@ -89,21 +89,31 @@ obj.Resource = resource; end end - + function addMetricReader(obj, reader) - arguments - obj - reader (1,1) {mustBeA(reader, "opentelemetry.sdk.metrics.PeriodicExportingMetricReader")} - end + % ADDMETRICREADER Add an additional metric reader + % ADDMETRICREADER(MP, R) adds an additional metric reader + % R to the list of metric readers used by meter provider + % MP. + % + % See also ADDVIEW, OPENTELEMETRY.SDK.METRICS.PERIODICEXPORTINGMETRICREADER + arguments + obj + reader (1,1) {mustBeA(reader, "opentelemetry.sdk.metrics.PeriodicExportingMetricReader")} + end obj.Proxy.addMetricReader(reader.Proxy.ID); obj.MetricReader = [obj.MetricReader, reader]; end function addView(obj, view) - arguments - obj - view (1,1) {mustBeA(view, "opentelemetry.sdk.metrics.View")} - end + % ADDVIEW Add an additional view + % ADDVIEW(MP, V) adds an additional view V. + % + % See also ADDMETRICREADER, OPENTELEMETRY.SDK.METRICS.VIEW + arguments + obj + view (1,1) {mustBeA(view, "opentelemetry.sdk.metrics.View")} + end obj.Proxy.addView(view.Proxy.ID); obj.View = [obj.View, view]; end diff --git a/sdk/metrics/+opentelemetry/+sdk/+metrics/MetricExporter.m b/sdk/metrics/+opentelemetry/+sdk/+metrics/MetricExporter.m index 8b3de57..7a9da5b 100644 --- a/sdk/metrics/+opentelemetry/+sdk/+metrics/MetricExporter.m +++ b/sdk/metrics/+opentelemetry/+sdk/+metrics/MetricExporter.m @@ -24,7 +24,7 @@ methods function obj = set.PreferredAggregationTemporality(obj, temporality) temporality = validatestring(temporality, ["cumulative", "delta"]); - obj.Proxy.setTemporality(temporality); + obj.Proxy.setTemporality(temporality); %#ok obj.PreferredAggregationTemporality = temporality; end diff --git a/sdk/metrics/+opentelemetry/+sdk/+metrics/PeriodicExportingMetricReader.m b/sdk/metrics/+opentelemetry/+sdk/+metrics/PeriodicExportingMetricReader.m index 1b7aefc..545e39f 100644 --- a/sdk/metrics/+opentelemetry/+sdk/+metrics/PeriodicExportingMetricReader.m +++ b/sdk/metrics/+opentelemetry/+sdk/+metrics/PeriodicExportingMetricReader.m @@ -1,5 +1,6 @@ classdef PeriodicExportingMetricReader < matlab.mixin.Heterogeneous -% Base class of metric reader +% Periodic exporting metric reader passes collected metrics to an exporter +% periodically at a fixed time interval. % Copyright 2023 The MathWorks, Inc. @@ -12,13 +13,35 @@ end properties - Interval (1,1) duration = minutes(1) - Timeout (1,1) duration = seconds(30) + Interval (1,1) duration = minutes(1) % Time interval between exports + Timeout (1,1) duration = seconds(30) % Maximum time before export is timed out and gets aborted end - methods %(Access=?opentelemetry.sdk.metrics.MeterProvider) + methods function obj = PeriodicExportingMetricReader(metricexporter, optionnames, optionvalues) - + % Periodic exporting metric reader passes collected metrics to + % an exporter periodically at a fixed time interval. + % R = OPENTELEMETRY.SDK.METRICS.PERIODICEXPORTINGMETRICREADER + % creates a periodic exporting metric reader that exports + % every minute using an OTLP HTTP exporter, which exports in + % OpenTelemetry Protocol (OTLP) format through HTTP. + % + % R = OPENTELEMETRY.SDK.METRICS.PERIODICEXPORTINGMETRICREADER(EXP) + % specifies the metric exporter. Supported metric exporters + % are OTLP HTTP exporter and OTLP gRPC exporter. + % + % R = OPENTELEMETRY.SDK.METRICS.PERIODICEXPORTINGMETRICREADER( + % EXP, PARAM1, VALUE1, PARAM2, VALUE2, ...) specifies + % optional parameter name/value pairs. Parameters are: + % "Interval" - Time interval between exports specified as + % a duration. Default is 1 minute. + % "Timeout" - Maximum time before export is timed out + % and gets aborted, specified as a duration. + % Default is 30 seconds. + % + % See also OPENTELEMETRY.EXPORTERS.OTLP.OTLPHTTPMETRICEXPORTER, + % OPENTELEMETRY.EXPORTERS.OTLP.OTLPGRPCMETRICEXPORTER, + % OPENTELEMETRY.SDK.METRICS.METERPROVIDER arguments metricexporter {mustBeA(metricexporter, "opentelemetry.sdk.metrics.MetricExporter")} = ... opentelemetry.exporters.otlp.defaultMetricExporter() diff --git a/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m b/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m index 61e03b1..c85308c 100644 --- a/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m +++ b/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m @@ -1,65 +1,124 @@ classdef View + % View enables customization of output metrics. Supported customization + % includes: + % * Metric name + % * Aggregation type + % * Histogram bins + % * Ignore unwanted instruments + % * Ignore unwanted attributes -% Copyright 2023 The MathWorks, Inc. + % Copyright 2023 The MathWorks, Inc. properties (GetAccess={?opentelemetry.sdk.metrics.MeterProvider}) Proxy % Proxy object to interface C++ code end properties (SetAccess=immutable) - Name - Description - Unit - InstrumentName - InstrumentType - MeterName - MeterVersion - MeterSchemaURL - AttributeKeys - Aggregation - HistogramBinEdges + Name (1,1) string % View name + Description (1,1) string % Description of view + InstrumentName (1,1) string % Name of the instrument this view applies to + InstrumentType (1,1) string % Type of instrument this view applies to + InstrumentUnit (1,1) string % Unit of instrument this view applies to + MeterName (1,1) string % Name of the meter this view applies to + MeterVersion (1,1) string % Version of the meter this view applies to + MeterSchema (1,1) string % Schema URL of the meter this view applies to + AllowedAttributes (1,:) string % List of attribute keys that are kept. All other attributes are ignored. + Aggregation (1,1) string % Customized aggregation type + HistogramBinEdges (1,:) double % Vector of customized bin edges for histogram end methods function obj = View(options) + % View enables customization of output metrics + % V = OPENTELEMETRY.SDK.METRICS.VIEW(PARAM1, VALUE1, PARAM2, + % VALUE2, ...) creates a view object and specifies its + % behavior using parameter name/value pairs. Parameters are: + % "Name" - Name of view. Any metric this view + % applies to will be renamed to this name. + % "Description" - Description of view. + % "InstrumentName" - Specifies an instrument name. This + % view will be applied to all metrics + % generated from instruments with + % this name. + % "InstrumentType" - Specifies an instrument type. This + % view will be applied to all metrics + % generated from all instruments of + % this type. + % "InstrumentUnit" - Specifies an instrument unit. This + % view will be applied to all metrics + % generated from all instruments with + % this unit. + % "MeterName" - Specifies a meter name. This view + % will be applied to all metrics + % generated from all instruments created + % by meters with this name. + % "MeterVersion" - Specifies a meter version. This view + % will be applied to all metrics + % generated from all instruments created + % by meters with this version. + % "MeterSchema" - Specifies a meter schema URL. This view + % will be applied to all metrics + % generated from all instruments created + % by meters with this schema URL. + % "AllowedAttributes" - Specifies a list of attributes + % that will be kept. All other + % attributes will be dropped. + % "Aggregation" - Change instruments to use a + % different aggregation beahvior. + % "HistogramBinEdges" - Use a different set of bins + % in all histograms this view + % applies to + % + % Examples: + % import opentelemetry.sdk.metrics + % + % % Change bin edges of all histograms created by any + % % meter named "Meter1" + % v = view(InstrumentType="histogram", MeterName="Meter1", ... + % HistogramBinEdges = 0:100:500); + % + % % Ignore all counters created by any meter named "xyz" + % v = view(MeterName="xyz", InstrumentType="counter", ... + % Aggregation="drop"); + % + % See also OPENTELEMETRY.SDK.METRICS.METERPROVIDER arguments - options.Name="" - options.Description="" - options.Unit="" - options.InstrumentName="" - options.InstrumentType="" - options.MeterName="" - options.MeterVersion="" - options.MeterSchemaURL="" - options.AttributeKeys="" - options.Aggregation="" - options.HistogramBinEdges=[] + options.Name {mustBeTextScalar} = "" + options.Description {mustBeTextScalar} = "" + options.InstrumentName {mustBeTextScalar} = "" + options.InstrumentType {mustBeTextScalar} = "" + options.InstrumentUnit {mustBeTextScalar} = "" + options.MeterName {mustBeTextScalar} = "" + options.MeterVersion {mustBeTextScalar} = "" + options.MeterSchema {mustBeTextScalar} = "" + options.AllowedAttributes {mustBeText, mustBeVector} = "" + options.Aggregation {mustBeTextScalar} = "" + options.HistogramBinEdges {mustBeNumeric, mustBeVector} = zeros(1,0) end - instrument_types = ["Counter", "Histogram", "UpDownCounter", "ObservableCounter", "ObservableGauge", "ObservableUpDownCounter"]; + instrument_types = ["Counter", "Histogram", "UpDownCounter"]; instrument_type = validatestring(options.InstrumentType, instrument_types); - instrumentTypeCategory = find(instrument_type==instrument_types)-1; aggregation_types = ["Drop", "Histogram", "LastValue", "Sum", "Default"]; aggregation_type = validatestring(options.Aggregation, aggregation_types); - aggregationCategory = find(aggregation_type==aggregation_types)-1; obj.Proxy = libmexclass.proxy.Proxy("Name", "libmexclass.opentelemetry.sdk.ViewProxy", ... - "ConstructorArguments", {options.Name, options.Description, options.Unit, options.InstrumentName, ... - instrumentTypeCategory, options.MeterName, options.MeterVersion, options.MeterSchemaURL, ... - options.AttributeKeys, aggregationCategory, options.HistogramBinEdges}); + "ConstructorArguments", {options.Name, options.Description, options.InstrumentName, ... + instrument_type, options.InstrumentUnit, options.MeterName, ... + options.MeterVersion, options.MeterSchema, options.AllowedAttributes, ... + aggregation_type, options.HistogramBinEdges}); - obj.Name = options.Name; - obj.Description = options.Description; - obj.Unit = options.Unit; - obj.InstrumentName = options.InstrumentName; - obj.InstrumentType = options.InstrumentType; - obj.MeterName = options.MeterName; - obj.MeterVersion = options.MeterVersion; - obj.MeterSchemaURL = options.MeterSchemaURL; - obj.AttributeKeys = options.AttributeKeys; - obj.Aggregation = options.Aggregation; - obj.HistogramBinEdges = options.HistogramBinEdges; + obj.Name = string(options.Name); + obj.Description = string(options.Description); + obj.InstrumentName = string(options.InstrumentName); + obj.InstrumentType = instrument_type; + obj.InstrumentUnit = string(options.InstrumentUnit); + obj.MeterName = string(options.MeterName); + obj.MeterVersion = string(options.MeterVersion); + obj.MeterSchema = string(options.MeterSchema); + obj.AllowedAttributes = reshape(string(options.AllowedAttributes),1,[]); + obj.Aggregation = aggregation_type; + obj.HistogramBinEdges = reshape(double(options.HistogramBinEdges),1,[]); end end end \ No newline at end of file diff --git a/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h b/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h index 1bf18b6..bebf8fd 100644 --- a/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h +++ b/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h @@ -32,8 +32,6 @@ class ViewProxy : public libmexclass::proxy::Proxy { static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments); - // void processView(libmexclass::proxy::method::Context& context); - std::unique_ptr getView(libmexclass::proxy::method::Context& context); std::unique_ptr getInstrumentSelector(libmexclass::proxy::method::Context& context); diff --git a/sdk/metrics/src/ViewProxy.cpp b/sdk/metrics/src/ViewProxy.cpp index 3450edf..1d35a7c 100644 --- a/sdk/metrics/src/ViewProxy.cpp +++ b/sdk/metrics/src/ViewProxy.cpp @@ -4,13 +4,9 @@ #include "libmexclass/proxy/ProxyManager.h" -#include - namespace libmexclass::opentelemetry::sdk { -ViewProxy::ViewProxy(std::unique_ptr view, std::unique_ptr instrumentSelector, std::unique_ptr meterSelector){ - View = std::move(view); - InstrumentSelector = std::move(instrumentSelector); - MeterSelector = std::move(meterSelector); +ViewProxy::ViewProxy(std::unique_ptr view, std::unique_ptr instrumentSelector, std::unique_ptr meterSelector) + : View(std::move(view)), InstrumentSelector(std::move(instrumentSelector)), MeterSelector(std::move(meterSelector)) { REGISTER_METHOD(ViewProxy, getView); REGISTER_METHOD(ViewProxy, getInstrumentSelector); REGISTER_METHOD(ViewProxy, getMeterSelector); @@ -26,11 +22,24 @@ libmexclass::proxy::MakeResult ViewProxy::make(const libmexclass::proxy::Functio matlab::data::StringArray description_mda = constructor_arguments[1]; auto description = description_mda[0]; - matlab::data::StringArray unit_mda = constructor_arguments[2]; + matlab::data::StringArray unit_mda = constructor_arguments[4]; auto unit = unit_mda[0]; - matlab::data::TypedArray aggregation_type_mda = constructor_arguments[9]; - metrics_sdk::AggregationType aggregation_type = static_cast(static_cast(aggregation_type_mda[0])); + matlab::data::StringArray aggregation_type_mda = constructor_arguments[9]; + std::string aggregation_type_str = static_cast(aggregation_type_mda[0]); + metrics_sdk::AggregationType aggregation_type; + if (aggregation_type_str.compare("Sum") == 0) { + aggregation_type = metrics_sdk::AggregationType::kSum; + } else if (aggregation_type_str.compare("Drop") == 0) { + aggregation_type = metrics_sdk::AggregationType::kDrop; + } else if (aggregation_type_str.compare("LastValue") == 0) { + aggregation_type = metrics_sdk::AggregationType::kLastValue; + } else if (aggregation_type_str.compare("Histogram") == 0) { + aggregation_type = metrics_sdk::AggregationType::kHistogram; + } else { + assert(aggregation_type_str.compare("Default") == 0); + aggregation_type = metrics_sdk::AggregationType::kDefault; + } std::shared_ptr aggregation_config = std::shared_ptr(new metrics_sdk::HistogramAggregationConfig()); if(aggregation_type == metrics_sdk::AggregationType::kHistogram){ @@ -59,10 +68,19 @@ libmexclass::proxy::MakeResult ViewProxy::make(const libmexclass::proxy::Functio // Create Instrument Selector - matlab::data::TypedArray instrument_type_mda = constructor_arguments[4]; - metrics_sdk::InstrumentType instrument_type = static_cast(static_cast(instrument_type_mda[0])); + matlab::data::StringArray instrument_type_mda = constructor_arguments[3]; + std::string instrument_type_str = static_cast(instrument_type_mda[0]); + metrics_sdk::InstrumentType instrument_type; + if (instrument_type_str.compare("Counter") == 0) { + instrument_type = metrics_sdk::InstrumentType::kCounter; + } else if (instrument_type_str.compare("UpDownCounter") == 0) { + instrument_type = metrics_sdk::InstrumentType::kUpDownCounter; + } else { + assert(instrument_type_str.compare("Histogram") == 0); + instrument_type = metrics_sdk::InstrumentType::kHistogram; + } - matlab::data::StringArray instrument_name_mda = constructor_arguments[3]; + matlab::data::StringArray instrument_name_mda = constructor_arguments[2]; auto instrument_name = static_cast(instrument_name_mda[0]); auto unit_str = static_cast(unit); diff --git a/test/tmetrics_sdk.m b/test/tmetrics_sdk.m index fc98925..fe5cc27 100644 --- a/test/tmetrics_sdk.m +++ b/test/tmetrics_sdk.m @@ -151,7 +151,7 @@ function testViewBasic(testCase) view_name = "counter_view"; view_description = "view_description"; - view = opentelemetry.sdk.metrics.View(Name="counter_view", Description="view_description", InstrumentName="mycounter", InstrumentType="Counter", MeterName="mymeter", MeterVersion="1.2.0", MeterSchemaURL="", Aggregation="Sum"); + view = opentelemetry.sdk.metrics.View(Name="counter_view", Description="view_description", InstrumentName="mycounter", InstrumentType="Counter", MeterName="mymeter", MeterVersion="1.2.0", MeterSchema="", Aggregation="Sum"); addView(mp, view);