Skip to content

chore(metrics): set default attributes type to never to force typings

The following code used to work:

const incrementCounter = metrics.createCounter(
  'my_counter',
  'A description'
);

incrementCounter({
  key: 'my_value'
});

This works because, if you don't provide a type hint to createCounter , the attributes can be anything. This MR adds a = never default value to the attributes type. This will make the previous code not compile because giving attributes will be forbidden (due to the never type). To make the code work, the following syntax should be used instead:

const incrementCounter = metrics.createCounter<{
  key: string;
}>(
  'my_counter',
  'A description'
);

incrementCounter({
  key: 'my_value'
});

It's more verbose, but it guarantees the contract between the logic and OpenTelemetry. Which is good.

Merge request reports

Loading