siimon / prom-client

Prometheus client for node.js
Apache License 2.0
3.14k stars 376 forks source link

Cannot enable Exemplars on collectDefaultMetrics() #605

Closed vmignot closed 10 months ago

vmignot commented 10 months ago

I'm trying to enable exemplars on collectDefaultMetrics, but without much success.

Here is a snippet of code (v15.1.0) :

  import { register, collectDefaultMetrics } from 'prom-client';
  register.setContentType('application/openmetrics-text; version=1.0.0; charset=utf-8');
  collectDefaultMetrics();

Then when requesting my /metrics, no exemplars are set on my counters or histo

~# curl localhost/metrics
# HELP process_cpu_user_seconds Total user CPU time spent in seconds.
# TYPE process_cpu_user_seconds counter
process_cpu_user_seconds_total{} 7.950018
# HELP process_cpu_system_seconds Total system CPU time spent in seconds.
# TYPE process_cpu_system_seconds counter
process_cpu_system_seconds_total{} 1.1639300000000001
[....]
# EOF

Do I have to inject the traceId and spanId myself at some point? Am I missing something, or do I have to use a custom registry for that purpose?

Thanks!

SimenB commented 10 months ago

Default metrics don't really have exemplars as they're never e.g. request bound - so there are no trace or span IDs to use. I think this is expected?

vmignot commented 10 months ago

Default metrics don't really have exemplars as they're never e.g. request bound - so there are no trace or span IDs to use. I think this is expected?

Ho, I see, my bad in that case!

Thanks for the clarification!