Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

% 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
PreferredAggregationTemporality (1,1) string % Preferred Aggregation Temporality
properties
Endpoint (1,1) string = "http://localhost:4317" % Export destination
UseCredentials (1,1) logical = false % 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 = seconds(10) % Maximum time above which exports will abort
HttpHeaders (1,1) dictionary = dictionary(string.empty, string.empty) % Additional HTTP headers
PreferredAggregationTemporality (1,1) string = "cumulative" % Preferred Aggregation Temporality
end

methods
Expand Down Expand Up @@ -47,100 +47,79 @@
optionvalues
end

obj = obj@opentelemetry.sdk.metrics.MetricExporter(...
"libmexclass.opentelemetry.exporters.OtlpGrpcMetricExporterProxy");

validnames = ["Endpoint", "UseCredentials ", "CertificatePath", ...
"CertificateString", "Timeout", "HttpHeaders", "PreferredAggregationTemporality"];
% set default values to empty or negative
endpoint = "";
usessl = false;
certificatepath = "";
certificatestring = "";
timeout_millis = -1;
headerkeys = string.empty();
headervalues = string.empty();
temporality = "";
for i = 1:length(optionnames)
namei = validatestring(optionnames{i}, validnames);
valuei = optionvalues{i};
if strcmp(namei, "Endpoint")
if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei)))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:EndpointNotScalarText", "Endpoint must be a scalar string.");
end
endpoint = string(valuei);
elseif strcmp(namei, "UseCredentials ")
if ~((islogical(valuei) || isnumeric(valuei)) && isscalar(valuei))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:UseCredentialsNotScalarLogical", "UseCredentials must be a scalar logical.")
end
usessl = logical(valuei);
elseif strcmp(namei, "CertificatePath")
if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei)))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificatePathNotScalarText", "CertificatePath must be a scalar string.");
end
certificatepath = string(valuei);
elseif strcmp(namei, "CertificateString")
if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei)))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificateStringNotScalarText", "CertificateString must be a scalar string.");
end
certificatestring = string(valuei);
elseif strcmp(namei, "Timeout")
if ~(isduration(valuei) && isscalar(valuei))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration.");
end
timeout = valuei;
timeout_millis = milliseconds(timeout);
elseif strcmp(namei, "HttpHeaders") % HttpHeaders
if ~isa(valuei, "dictionary")
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary.");
end
httpheaders = valuei;
headerkeys = keys(valuei);
headervalues = values(valuei);
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
obj.(namei) = valuei;
end

obj = obj@opentelemetry.sdk.metrics.MetricExporter(...
"libmexclass.opentelemetry.exporters.OtlpGrpcMetricExporterProxy", ...
endpoint, usessl, certificatepath, certificatestring, ...
timeout_millis, headerkeys, headervalues, temporality);
end

function obj = set.Endpoint(obj, ep)
if ~(isStringScalar(ep) || (ischar(ep) && isrow(ep)))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:EndpointNotScalarText", "Endpoint must be a scalar string.");
end
ep = string(ep);
obj.Proxy.setEndpoint(ep);
obj.Endpoint = ep;
end

function obj = set.UseCredentials(obj, uc)
if ~((islogical(uc) || isnumeric(uc)) && isscalar(uc))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:UseCredentialsNotScalarLogical", "UseCredentials must be a scalar logical.")
end
uc = logical(uc);
obj.Proxy.setUseCredentials(uc);
obj.UseCredentials = uc;
end

% populate immutable properties
[defaultendpoint, defaultcertpath, defaultcertstring, defaultmillis, defaulttemporality] = ...
getDefaultOptionValues(obj);
if endpoint == "" % not specified, use default value
obj.Endpoint = defaultendpoint;
else
obj.Endpoint = endpoint;
end
obj.UseCredentials = usessl;
if certificatepath == "" % not specified, use default value
obj.CertificatePath = defaultcertpath;
else
obj.CertificatePath = certificatepath;
function obj = set.CertificatePath(obj, certpath)
if ~(isStringScalar(certpath) || (ischar(certpath) && isrow(certpath)))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificatePathNotScalarText", "CertificatePath must be a scalar string.");
end
if certificatestring == "" % not specified, use default value
obj.CertificateString = defaultcertstring;
else
obj.CertificateString = certificatestring;
certpath = string(certpath);
obj.Proxy.setCertificatePath(certpath);
obj.CertificatePath = certpath;
end

function obj = set.CertificateString(obj, certstr)
if ~(isStringScalar(certstr) || (ischar(certstr) && isrow(certstr)))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificateStringNotScalarText", "CertificateString must be a scalar string.");
end
if timeout_millis < 0 % not specified, use default value
obj.Timeout = milliseconds(defaultmillis);
else
obj.Timeout = timeout;
certstr = string(certstr);
obj.Proxy.setCertificateString(certstr);
obj.CertificateString = certstr;
end

function obj = set.Timeout(obj, timeout)
if ~(isduration(timeout) && isscalar(timeout))
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration.");
end
if isempty(headerkeys) % not specified, return empty dictionary
obj.HttpHeaders = dictionary(headerkeys, headervalues);
else
obj.HttpHeaders = httpheaders;
obj.Proxy.setTimeout(milliseconds(timeout));
obj.Timeout = timeout;
end

function obj = set.HttpHeaders(obj, httpheaders)
if ~isa(httpheaders, "dictionary")
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary.");
end
if temporality == ""
obj.PreferredAggregationTemporality = defaulttemporality;
else
obj.PreferredAggregationTemporality = temporality;
headerkeys = keys(httpheaders);
headervalues = values(httpheaders);
if ~isstring(headervalues)
error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.")
end
obj.Proxy.setHttpHeaders(headerkeys, headervalues);
obj.HttpHeaders = httpheaders;
end

function obj = set.PreferredAggregationTemporality(obj, temporality)
temporality = validatestring(temporality, ["cumulative", "delta"]);
obj.Proxy.setTemporality(temporality);
obj.PreferredAggregationTemporality = temporality;
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

% 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
PreferredAggregationTemporality (1,1) string % Preferred Aggregation Temporality
properties
Endpoint (1,1) string = "http://localhost:4318/v1/metrics" % Export destination
Format (1,1) string = "JSON" % Data format, JSON or binary
JsonBytesMapping (1,1) string = "hexId" % What to convert JSON bytes to
UseJsonName (1,1) logical = false % Whether to use JSON name of protobuf field to set the key of JSON
Timeout (1,1) duration = seconds(10) % Maximum time above which exports will abort
HttpHeaders (1,1) dictionary = dictionary(string.empty, string.empty) % Additional HTTP headers
PreferredAggregationTemporality (1,1) string = "cumulative" % Preferred Aggregation Temporality
end

methods
Expand Down Expand Up @@ -47,98 +47,73 @@
optionvalues
end

obj = obj@opentelemetry.sdk.metrics.MetricExporter(...
"libmexclass.opentelemetry.exporters.OtlpHttpMetricExporterProxy");

validnames = ["Endpoint", "Format", "JsonBytesMapping", ...
"UseJsonName", "Timeout", "HttpHeaders", "PreferredAggregationTemporality"];
% set default values to empty or negative
endpoint = "";
dataformat = "";
jsonbytesmapping = "";
usejsonname = false;
timeout_millis = -1;
headerkeys = string.empty();
headervalues = string.empty();
temporality = "";
for i = 1:length(optionnames)
namei = validatestring(optionnames{i}, validnames);
valuei = optionvalues{i};
if strcmp(namei, "Endpoint")
if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei)))
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:EndpointNotScalarText", "Endpoint must be a scalar string.");
end
endpoint = string(valuei);
elseif strcmp(namei, "Format")
dataformat = validatestring(valuei, ["JSON", "binary"]);
elseif strcmp(namei, "JsonBytesMapping")
jsonbytesmapping = validatestring(valuei, ["hex", "hexId", "base64"]);
elseif strcmp(namei, "UseJsonName")
if ~((islogical(valuei) || isnumeric(valuei)) && isscalar(valuei))
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:UseJsonNameNotScalarLogical", "UseJsonName must be a scalar logical.")
end
usejsonname = logical(valuei);
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);
elseif strcmp(namei, "HttpHeaders")
if ~isa(valuei, "dictionary")
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary.");
end
httpheaders = valuei;
headerkeys = keys(valuei);
headervalues = values(valuei);
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

obj.(namei) = valuei;
end

obj = obj@opentelemetry.sdk.metrics.MetricExporter(...
"libmexclass.opentelemetry.exporters.OtlpHttpMetricExporterProxy", ...
endpoint, dataformat, jsonbytesmapping, usejsonname, ...
timeout_millis, headerkeys, headervalues, temporality);
end

% populate immutable properties
if endpoint == "" || dataformat == "" || jsonbytesmapping == "" || ...
timeout_millis < 0
[defaultendpoint, defaultformat, defaultmapping, defaultmillis, defaulttemporality] = ...
getDefaultOptionValues(obj);
end
if endpoint == "" % not specified, use default value
obj.Endpoint = defaultendpoint;
else
obj.Endpoint = endpoint;
function obj = set.Endpoint(obj, ep)
if ~(isStringScalar(ep) || (ischar(ep) && isrow(ep)))
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:EndpointNotScalarText", "Endpoint must be a scalar string.");
end
if dataformat == "" % not specified, use default value
obj.Format = defaultformat;
else
obj.Format = dataformat;
end
if jsonbytesmapping == "" % not specified, use default value
obj.JsonBytesMapping = defaultmapping;
else
obj.JsonBytesMapping = jsonbytesmapping;
ep = string(ep);
obj.Proxy.setEndpoint(ep);
obj.Endpoint = ep;
end

function obj = set.Format(obj, newformat)
newformat = validatestring(newformat, ["JSON", "binary"]);
obj.Proxy.setFormat(newformat);
obj.Format = newformat;
end

function obj = set.JsonBytesMapping(obj, jbm)
jbm = validatestring(jbm, ["hex", "hexId", "base64"]);
obj.Proxy.setJsonBytesMapping(jbm);
obj.JsonBytesMapping = jbm;
end

function obj = set.UseJsonName(obj, ujn)
if ~((islogical(ujn) || isnumeric(ujn)) && isscalar(ujn))
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:UseJsonNameNotScalarLogical", "UseJsonName must be a scalar logical.")
end
obj.UseJsonName = usejsonname;
if timeout_millis < 0 % not specified, use default value
obj.Timeout = milliseconds(defaultmillis);
else
obj.Timeout = timeout;
ujn = logical(ujn);
obj.Proxy.setUseJsonName(ujn);
obj.UseJsonName = ujn;
end

function obj = set.Timeout(obj, timeout)
if ~(isduration(timeout) && isscalar(timeout))
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration.");
end
if isempty(headerkeys) % not specified, return empty dictionary
obj.HttpHeaders = dictionary(headerkeys, headervalues);
else
obj.HttpHeaders = httpheaders;
obj.Proxy.setTimeout(milliseconds(timeout));
obj.Timeout = timeout;
end

function obj = set.HttpHeaders(obj, httpheaders)
if ~isa(httpheaders, "dictionary")
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary.");
end
if temporality == ""
obj.PreferredAggregationTemporality = defaulttemporality;
else
obj.PreferredAggregationTemporality = temporality;
headerkeys = keys(httpheaders);
headervalues = values(httpheaders);
if ~isstring(headervalues)
error("opentelemetry:exporters:otlp:OtlpHttpMetricExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.")
end
obj.Proxy.setHttpHeaders(headerkeys, headervalues);
obj.HttpHeaders = httpheaders;
end

function obj = set.PreferredAggregationTemporality(obj, temporality)
temporality = validatestring(temporality, ["cumulative", "delta"]);
obj.Proxy.setTemporality(temporality);
obj.PreferredAggregationTemporality = temporality;
end
end
end
Loading