opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

feat(prometheus-exporter): add unref function check to improve compat…

Open acamposruiz opened this issue 3 months ago • 2 comments

Which problem is this PR solving?

This PR introduces a conditional unref feature to the Prometheus Exporter within the OpenTelemetry JavaScript project. Previously, the unref method was called unconditionally, which could lead to potential issues in environments where unref is not available or not needed, thus keeping the process open unnecessarily. This change enhances compatibility and reliability, especially in diverse runtime environments.

Fixes # https://github.com/open-telemetry/opentelemetry-js/issues/4488

Short description of the changes

  • Added a check to ensure unref is only called if it is a function, preventing potential runtime errors in environments where unref might not be available.
  • This ensures the HTTP server created by the Prometheus exporter does not keep the process open when not required, allowing for cleaner shutdowns and resource management.

Type of change

  • [x] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

The changes were tested by:

  • [x] Existing tests pass

Checklist:

  • [x] Followed the style guidelines of this project

acamposruiz avatar Apr 08 '24 10:04 acamposruiz

@acamposruiz thanks for opening this PR. I don't have a bun testing setup at the moment, but I've seen a PR (https://github.com/oven-sh/bun/pull/8675) that added unref support to the server.

Would you mind testing with a more recent version? Maybe this change is not needed anymore?

pichlermarc avatar Apr 09 '24 12:04 pichlermarc