From 434ba0b65ca45218608ecf2eb9ea37b18f8c768e Mon Sep 17 00:00:00 2001 From: duncanpo Date: Thu, 22 Feb 2024 15:56:06 -0500 Subject: [PATCH 1/2] Release 1.6.0 --- CMakeLists.txt | 8 +-- README.md | 8 +-- .../+opentelemetry/+sdk/+metrics/View.m | 12 ++-- test/tmetrics.m | 26 ++----- test/tmetrics_sdk.m | 69 ++++++++++++++++++- 5 files changed, 85 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7df661..b4bc2a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,7 @@ else() include(ExternalProject) set(OTEL_CPP_PROJECT_NAME opentelemetry-cpp) set(OTEL_CPP_GIT_REPOSITORY "https://github.com/open-telemetry/opentelemetry-cpp.git") - set(OTEL_CPP_GIT_TAG "11d5d9e") + set(OTEL_CPP_GIT_TAG "e1119ed") if(DEFINED OTEL_CPP_PREFIX) string(REPLACE "\\" "/" OTEL_CPP_PREFIX ${OTEL_CPP_PREFIX}) @@ -133,11 +133,7 @@ else() set(OTEL_CPP_PREFIX ${CMAKE_BINARY_DIR}/otel-cpp) endif() - if(WITH_OTLP_GRPC) - set(OTEL_CPP_CXX_STANDARD 14) # Abseil requires at least Cxx14 - else() - set(OTEL_CPP_CXX_STANDARD 11) - endif() + set(OTEL_CPP_CXX_STANDARD 14) if(NOT APPLE OR SKIP_OTEL_CPP_PATCH) set(patch_command "") diff --git a/README.md b/README.md index ae64fc1..32bb588 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ 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 and metrics are supported. Logs will be in the future. -- View class in metrics is only partially supported. The properties **Aggregation** and **AllowedAttributes** are not yet supported. -- This package is supported and has been tested on Windows®, Linux®, and macOS. +- Tracing and metrics are fully supported. Logs will be in the future. +- Supported and tested on Windows®, Linux®, and macOS. +- Attributes in asynchronous metric instruments are currently ignored because of an issue in the opentelemetry-cpp layer. ### MathWorks Products (https://www.mathworks.com) @@ -91,4 +91,4 @@ The license is available in the License file within this repository ## Community Support [MATLAB Central](https://www.mathworks.com/matlabcentral) -Copyright 2023 The MathWorks, Inc. +Copyright 2023-2024 The MathWorks, Inc. diff --git a/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m b/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m index c6998d8..837ce13 100644 --- a/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m +++ b/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m @@ -7,7 +7,7 @@ % * Ignore unwanted instruments % * Ignore unwanted attributes - % Copyright 2023 The MathWorks, Inc. + % Copyright 2023-2024 The MathWorks, Inc. properties (GetAccess={?opentelemetry.sdk.metrics.MeterProvider}) Proxy % Proxy object to interface C++ code @@ -91,15 +91,13 @@ options.MeterName {mustBeTextScalar} = "" options.MeterVersion {mustBeTextScalar} = "" options.MeterSchema {mustBeTextScalar} = "" - %options.AllowedAttributes {mustBeText, mustBeVector} % no default here - %options.Aggregation {mustBeTextScalar} = "default" + options.AllowedAttributes {mustBeText, mustBeVector} % no default here + options.Aggregation {mustBeTextScalar} = "default" options.HistogramBinEdges {mustBeNumeric, mustBeVector} = zeros(1,0) end - - % Aggregation and AllowedAttributes are not yet supported - options.Aggregation = "default"; - instrument_types = ["counter", "histogram", "updowncounter"]; + instrument_types = ["counter", "histogram", "updowncounter", ... + "observablecounter", "observableupdowncounter", "observablegauge"]; instrument_type = validatestring(options.InstrumentType, instrument_types); aggregation_types = ["drop", "histogram", "lastvalue", "sum", "default"]; diff --git a/test/tmetrics.m b/test/tmetrics.m index 7c6ec38..a9affb4 100644 --- a/test/tmetrics.m +++ b/test/tmetrics.m @@ -197,11 +197,7 @@ function testCounterInvalidAdd(testCase) % fetch results clear p; results = readJsonResults(testCase); - results = results{end}; - - % verify that the counter value is still 0 - verifyEqual(testCase, ... - results.resourceMetrics.scopeMetrics.metrics.sum.dataPoints.asDouble, 0); + verifyEmpty(testCase, results); % results should be empty since all adds were invalid end @@ -516,10 +512,6 @@ function testGetSetMeterProvider(testCase) methods (Test, ParameterCombination="sequential") function testAsynchronousInstrumentBasic(testCase, create_async, datapoint_name) % test basic functionalities of an observable counter - - testCase.assumeTrue(isequal(create_async, @createObservableGauge), ... - "Sporadic failures for counters and updowncounters fixed in otel-cpp 1.14.0"); - countername = "bar"; callback = @callbackNoAttributes; @@ -549,10 +541,9 @@ function testAsynchronousInstrumentBasic(testCase, create_async, datapoint_name) function testAsynchronousInstrumentAttributes(testCase, create_async, datapoint_name) % test for attributes when observing metrics for an observable counter - - testCase.assumeTrue(isequal(create_async, @createObservableGauge), ... - "Sporadic failures for counters and updowncounters fixed in otel-cpp 1.14.0"); - + + testCase.assumeTrue(false, "Asynchronous metrics attributes incorrectly ignored due to issue in opentelemetry-cpp 1.14.0"); + countername = "bar"; callback = @callbackWithAttributes; @@ -586,10 +577,6 @@ function testAsynchronousInstrumentAttributes(testCase, create_async, datapoint_ function testAsynchronousInstrumentAnonymousCallback(testCase, create_async, datapoint_name) % use an anonymous function as callback - - testCase.assumeTrue(isequal(create_async, @createObservableGauge), ... - "Sporadic failures for counters and updowncounters fixed in otel-cpp 1.14.0"); - countername = "bar"; addvalue = 20; callback = @(x)callbackOneInput(addvalue); @@ -617,9 +604,8 @@ function testAsynchronousInstrumentAnonymousCallback(testCase, create_async, dat function testAsynchronousInstrumentMultipleCallbacks(testCase, create_async, datapoint_name) % Observable counter with more than one callbacks - testCase.assumeTrue(isequal(create_async, @createObservableGauge), ... - "Sporadic failures for counters and updowncounters fixed in otel-cpp 1.14.0"); - + testCase.assumeTrue(false, "Asynchronous metrics attributes incorrectly ignored due to issue in opentelemetry-cpp 1.14.0"); + countername = "bar"; p = opentelemetry.sdk.metrics.MeterProvider(testCase.ShortIntervalReader); diff --git a/test/tmetrics_sdk.m b/test/tmetrics_sdk.m index 05be2ff..bf0270a 100644 --- a/test/tmetrics_sdk.m +++ b/test/tmetrics_sdk.m @@ -186,7 +186,6 @@ function testViewBasic(testCase) % verify counter value verifyEqual(testCase, dp.asDouble, val); end - function testViewHistogram(testCase) % testViewHistogram: Change histogram bins @@ -240,6 +239,74 @@ function testViewHistogram(testCase) verifyEqual(testCase, dp.bucketCounts, expected_buckets); end + function testViewAggregation(testCase) + % testViewAggregation: change aggregation of metric instruments + metername = "foo"; + countername = "bar"; + view = opentelemetry.sdk.metrics.View(InstrumentType="Counter", ... + InstrumentName=countername, Aggregation="LastValue"); + mp = opentelemetry.sdk.metrics.MeterProvider(... + testCase.ShortIntervalReader, View=view); + + m = getMeter(mp, metername); + c = createCounter(m, countername); + + % add values + maxi = 5; + for i = 1:maxi + c.add(i); + end + + pause(testCase.WaitTime); + + clear mp; + results = readJsonResults(testCase); + results = results{end}; + + % verify counter name + verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.metrics.name), countername); + + % verify counter value is the last value rather than the sum + dp = results.resourceMetrics.scopeMetrics.metrics.gauge.dataPoints; + verifyEqual(testCase, dp.asDouble, maxi); + end + + function testViewAttributes(testCase) + % testViewAttributes: filter out attributes + metername = "foo"; + countername = "bar"; + view = opentelemetry.sdk.metrics.View(InstrumentType="Counter", ... + InstrumentName=countername, AllowedAttributes="Building"); + mp = opentelemetry.sdk.metrics.MeterProvider(... + testCase.ShortIntervalReader, View=view); + + m = getMeter(mp, metername); + c = createCounter(m, countername); + + % add values + values = 10:10:40; + add(c, values(1), "Building", 1, "Room", 1); + add(c, values(2), "Building", 1, "Room", 2); + add(c, values(3), "Building", 1, "Room", 1); + add(c, values(4), "Building", 1, "Room", 2); + + pause(testCase.WaitTime); + + clear mp; + results = readJsonResults(testCase); + results = results{end}; + + % verify counter name + verifyEqual(testCase, string(results.resourceMetrics.scopeMetrics.metrics.name), countername); + + % verify "Room" attribute has been filtered out + dp = results.resourceMetrics.scopeMetrics.metrics.sum.dataPoints; + verifyEqual(testCase, dp.asDouble, sum(values)); + verifyLength(testCase, dp.attributes, 1); + verifyEqual(testCase, string(dp.attributes(1).key), "Building"); + verifyEqual(testCase, dp.attributes(1).value.doubleValue, 1); + end + function testMultipleViews(testCase) % testMultipleView: Applying multiple views to a meter provider From 714376ea2ea4491d18d06a45c4fd906cc9e0064b Mon Sep 17 00:00:00 2001 From: duncanpo Date: Thu, 22 Feb 2024 22:39:57 -0500 Subject: [PATCH 2/2] Update context_propagation example --- examples/context_propagation/cpp/client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/context_propagation/cpp/client.cc b/examples/context_propagation/cpp/client.cc index 879613d..2bcf6b8 100644 --- a/examples/context_propagation/cpp/client.cc +++ b/examples/context_propagation/cpp/client.cc @@ -84,7 +84,7 @@ void sendRequest(const std::string &url) prop->Inject(carrier, current_ctx); // send http request - http_client::Result result = http_client->Post(url, body, carrier.headers_); + http_client::Result result = http_client->PostNoSsl(url, body, carrier.headers_); if (result) { // set span attributes