You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This only affects the JavaScript OpenTelemetry library
This may affect other libraries, but I would like to get opinions here first
Proposal
The InMemoryMetricExporter currently allows users to retrieve metrics through getMetrics even after the shutdown method has been called. To improve consistency with other in-memory exporters (such as InMemorySpanExporter and InMemoryLogRecordExporter), it may be beneficial to clear the metrics array after shutdown, preventing further retrieval.
If this proposal is accepted, I would be interested in implementing the changes myself :)
Background
Metric Exporter Specification
According to the specification, allowing getMetrics to return values after shutdown is technically compliant.
Shuts down the exporter. Called when SDK is shut down. This is an opportunity for exporter to do any cleanup required.
Shutdown SHOULD be called only once for each MetricExporter instance. After the call to Shutdown subsequent calls to Export are not allowed and should return a Failure result.
Shutdown SHOULD NOT block indefinitely (e.g., if it attempts to flush the data and the destination is unavailable). OpenTelemetry SDK authors MAY decide if they want to make the shutdown timeout configurable.
However, based on the line:
This is an opportunity for exporter to do any cleanup required.
it seems more intuitive that the getMetrics function should return a cleared array after shutdown, in line with expected behavior for cleanup.
Current Implementation of InMemoryMetricExporter
Currently, InMemoryMetricExporter does not clear the array returned by getMetrics at shutdown. As a result, users can still retrieve data with getMetrics even after shutdown.
Proposal
The InMemoryMetricExporter currently allows users to retrieve metrics through getMetrics even after the shutdown method has been called. To improve consistency with other in-memory exporters (such as InMemorySpanExporter and InMemoryLogRecordExporter), it may be beneficial to clear the metrics array after shutdown, preventing further retrieval.
If this proposal is accepted, I would be interested in implementing the changes myself :)
Background
Metric Exporter Specification
According to the specification, allowing
getMetrics
to return values aftershutdown
is technically compliant.However, based on the line:
it seems more intuitive that the
getMetrics
function should return a cleared array after shutdown, in line with expected behavior for cleanup.Current Implementation of
InMemoryMetricExporter
Currently,
InMemoryMetricExporter
does not clear the array returned bygetMetrics
at shutdown. As a result, users can still retrieve data withgetMetrics
even after shutdown.opentelemetry-js/packages/sdk-metrics/src/export/InMemoryMetricExporter.ts
Lines 77 to 80 in 4b5c21c
Implementation in
InMemorySpanExporter
andInMemoryLogRecordExporter
In contrast,
InMemorySpanExporter
does clean up its data after shutdown, clearing the array returned bygetFinishedSpans
.opentelemetry-js/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts
Lines 48 to 52 in 4b5c21c
Similarly,
InMemoryLogRecordExporter
also resets its internal state at shutdown.opentelemetry-js/experimental/packages/sdk-logs/src/export/InMemoryLogRecordExporter.ts
Lines 52 to 56 in 4b5c21c
This inconsistency in behavior among different in-memory exporters could lead to confusion for users (as it did for me).
The text was updated successfully, but these errors were encountered: