|
5 | 5 |
|
6 | 6 | % Copyright 2023 The MathWorks, Inc.
|
7 | 7 |
|
8 |
| - properties (SetAccess=immutable) |
9 |
| - Endpoint (1,1) string % Export destination |
10 |
| - UseCredentials (1,1) logical % Whether to use SSL credentials |
11 |
| - CertificatePath (1,1) string % Path to .pem file for SSL encryption |
12 |
| - CertificateString (1,1) string % In-memory string representation of .pem file for SSL encryption |
13 |
| - Timeout (1,1) duration % Maximum time above which exports will abort |
14 |
| - HttpHeaders (1,1) dictionary % Additional HTTP headers |
| 8 | + properties |
| 9 | + Endpoint (1,1) string = "http://localhost:4317" % Export destination |
| 10 | + UseCredentials (1,1) logical = false % Whether to use SSL credentials |
| 11 | + CertificatePath (1,1) string = "" % Path to .pem file for SSL encryption |
| 12 | + CertificateString (1,1) string = "" % In-memory string representation of .pem file for SSL encryption |
| 13 | + Timeout (1,1) duration = seconds(10) % Maximum time above which exports will abort |
| 14 | + HttpHeaders (1,1) dictionary = dictionary(string.empty, string.empty) % Additional HTTP headers |
15 | 15 | end
|
16 | 16 |
|
17 | 17 | methods
|
|
43 | 43 | optionvalues
|
44 | 44 | end
|
45 | 45 |
|
| 46 | + |
| 47 | + "libmexclass.opentelemetry.exporters.OtlpGrpcSpanExporterProxy"); |
| 48 | + |
46 | 49 | validnames = ["Endpoint", "UseCredentials ", "CertificatePath", ...
|
47 | 50 | "CertificateString", "Timeout", "HttpHeaders"];
|
48 |
| - % set default values to empty or negative |
49 |
| - endpoint = ""; |
50 |
| - usessl = false; |
51 |
| - certificatepath = ""; |
52 |
| - certificatestring = ""; |
53 |
| - timeout_millis = -1; |
54 |
| - headerkeys = string.empty(); |
55 |
| - headervalues = string.empty(); |
56 | 51 | for i = 1:length(optionnames)
|
57 | 52 | namei = validatestring(optionnames{i}, validnames);
|
58 | 53 | valuei = optionvalues{i};
|
59 |
| - if strcmp(namei, "Endpoint") |
60 |
| - if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei))) |
61 |
| - error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:EndpointNotScalarText", "Endpoint must be a scalar string."); |
62 |
| - end |
63 |
| - endpoint = string(valuei); |
64 |
| - elseif strcmp(namei, "UseCredentials ") |
65 |
| - if ~((islogical(valuei) || isnumeric(valuei)) && isscalar(valuei)) |
66 |
| - error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:UseCredentialsNotScalarLogical", "UseCredentials must be a scalar logical.") |
67 |
| - end |
68 |
| - usessl = logical(valuei); |
69 |
| - elseif strcmp(namei, "CertificatePath") |
70 |
| - if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei))) |
71 |
| - error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:CertificatePathNotScalarText", "CertificatePath must be a scalar string."); |
72 |
| - end |
73 |
| - certificatepath = string(valuei); |
74 |
| - elseif strcmp(namei, "CertificateString") |
75 |
| - if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei))) |
76 |
| - error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:CertificateStringNotScalarText", "CertificateString must be a scalar string."); |
77 |
| - end |
78 |
| - certificatestring = string(valuei); |
79 |
| - elseif strcmp(namei, "Timeout") |
80 |
| - if ~(isduration(valuei) && isscalar(valuei)) |
81 |
| - error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration."); |
82 |
| - end |
83 |
| - timeout = valuei; |
84 |
| - timeout_millis = milliseconds(timeout); |
85 |
| - else % HttpHeaders |
86 |
| - if ~isa(valuei, "dictionary") |
87 |
| - error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary."); |
88 |
| - end |
89 |
| - httpheaders = valuei; |
90 |
| - headerkeys = keys(valuei); |
91 |
| - headervalues = values(valuei); |
92 |
| - if ~isstring(headervalues) |
93 |
| - error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.") |
94 |
| - end |
95 |
| - end |
| 54 | + obj.(namei) = valuei; |
96 | 55 | end
|
97 |
| - |
98 |
| - |
99 |
| - "libmexclass.opentelemetry.exporters.OtlpGrpcSpanExporterProxy", ... |
100 |
| - endpoint, usessl, certificatepath, certificatestring, ... |
101 |
| - timeout_millis, headerkeys, headervalues); |
| 56 | + end |
102 | 57 |
|
103 |
| - % populate immutable properties |
104 |
| - [defaultendpoint, defaultcertpath, defaultcertstring, defaultmillis] = ... |
105 |
| - getDefaultOptionValues(obj); |
106 |
| - if endpoint == "" % not specified, use default value |
107 |
| - obj.Endpoint = defaultendpoint; |
108 |
| - else |
109 |
| - obj.Endpoint = endpoint; |
110 |
| - end |
111 |
| - obj.UseCredentials = usessl; |
112 |
| - if certificatepath == "" % not specified, use default value |
113 |
| - obj.CertificatePath = defaultcertpath; |
114 |
| - else |
115 |
| - obj.CertificatePath = certificatepath; |
| 58 | + function obj = set.Endpoint(obj, ep) |
| 59 | + if ~(isStringScalar(ep) || (ischar(ep) && isrow(ep))) |
| 60 | + error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:EndpointNotScalarText", "Endpoint must be a scalar string."); |
116 | 61 | end
|
117 |
| - if certificatestring == "" % not specified, use default value |
118 |
| - obj.CertificateString = defaultcertstring; |
119 |
| - else |
120 |
| - obj.CertificateString = certificatestring; |
| 62 | + ep = string(ep); |
| 63 | + obj.Proxy.setEndpoint(ep); |
| 64 | + obj.Endpoint = ep; |
| 65 | + end |
| 66 | + |
| 67 | + function obj = set.UseCredentials(obj, uc) |
| 68 | + if ~((islogical(uc) || isnumeric(uc)) && isscalar(uc)) |
| 69 | + error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:UseCredentialsNotScalarLogical", "UseCredentials must be a scalar logical.") |
| 70 | + end |
| 71 | + uc = logical(uc); |
| 72 | + obj.Proxy.setUseCredentials(uc); |
| 73 | + obj.UseCredentials = uc; |
| 74 | + end |
| 75 | + |
| 76 | + function obj = set.CertificatePath(obj, certpath) |
| 77 | + if ~(isStringScalar(certpath) || (ischar(certpath) && isrow(certpath))) |
| 78 | + error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:CertificatePathNotScalarText", "CertificatePath must be a scalar string."); |
121 | 79 | end
|
122 |
| - if timeout_millis < 0 % not specified, use default value |
123 |
| - obj.Timeout = milliseconds(defaultmillis); |
124 |
| - else |
125 |
| - obj.Timeout = timeout; |
| 80 | + certpath = string(certpath); |
| 81 | + obj.Proxy.setCertificatePath(certpath); |
| 82 | + obj.CertificatePath = certpath; |
| 83 | + end |
| 84 | + |
| 85 | + function obj = set.CertificateString(obj, certstr) |
| 86 | + if ~(isStringScalar(certstr) || (ischar(certstr) && isrow(certstr))) |
| 87 | + error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:CertificateStringNotScalarText", "CertificateString must be a scalar string."); |
| 88 | + end |
| 89 | + certstr = string(certstr); |
| 90 | + obj.Proxy.setCertificateString(certstr); |
| 91 | + obj.CertificateString = certstr; |
| 92 | + end |
| 93 | + |
| 94 | + function obj = set.Timeout(obj, timeout) |
| 95 | + if ~(isduration(timeout) && isscalar(timeout)) |
| 96 | + error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration."); |
| 97 | + end |
| 98 | + obj.Proxy.setTimeout(milliseconds(timeout)); |
| 99 | + obj.Timeout = timeout; |
| 100 | + end |
| 101 | + |
| 102 | + function obj = set.HttpHeaders(obj, httpheaders) |
| 103 | + if ~isa(httpheaders, "dictionary") |
| 104 | + error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary."); |
126 | 105 | end
|
127 |
| - if isempty(headerkeys) % not specified, return empty dictionary |
128 |
| - obj.HttpHeaders = dictionary(headerkeys, headervalues); |
129 |
| - else |
130 |
| - obj.HttpHeaders = httpheaders; |
| 106 | + headerkeys = keys(httpheaders); |
| 107 | + headervalues = values(httpheaders); |
| 108 | + if ~isstring(headervalues) |
| 109 | + error("opentelemetry:exporters:otlp:OtlpGrpcSpanExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.") |
131 | 110 | end
|
132 |
| - |
| 111 | + obj.Proxy.setHttpHeaders(headerkeys, headervalues); |
| 112 | + obj.HttpHeaders = httpheaders; |
133 | 113 | end
|
134 | 114 | end
|
135 | 115 | end
|
0 commit comments