Shutting down a MeterProvider with a asynchronous instrument can take a long time

Open
#131 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
matlab

Research direction

Start by running the supplied MATLAB loop and compare shutdown timing for the observable gauge and synchronous counter. Inspect the MeterProvider creation and opentelemetry.sdk.common.Cleanup.shutdown path, then review the asynchronous example in test/texamples.m. Done means asynchronous shutdown no longer intermittently takes about 30 seconds and the example test no longer needs filtering.

Written by the indexing model from the issue text.

Description

Run the following code in a loop. Many iterations take only about 0.01 seconds to run but some can take a long time (~30 seconds).

function out = currentsecond()
% callback function for an observable gauge

dt = datetime("now");
s = second(dt);

out = opentelemetry.metrics.ObservableResult;
out = out.observe(s);
for i=1:10, 
   mp = opentelemetry.sdk.metrics.MeterProvider();  
   opentelemetry.metrics.Provider.setMeterProvider(mp);
   clear
   mp = opentelemetry.metrics.Provider.getMeterProvider();   
   m = getMeter(mp, "foo"); 
   g = createObservableGauge(m, @currentsecond, "bar");
   tic;   
   opentelemetry.sdk.common.Cleanup.shutdown(mp);   
   toc; 
end

In comparison, if the code is changed to create a synchronous instrument (e.g. counter) instead of an asynchronous one, then shutdown never takes a long time, always around 0.01 seconds.

This issue causes an asynchronous example test in test/texamples.m to be filtered out due to the time it takes to run the test.

Dominant language
MATLAB
Stars
19
Forks
4
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mathworks/OpenTelemetry-MATLAB

All issues in mathworks/OpenTelemetry-MATLAB

Similar issues

More MATLAB issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.