Skip to content

Metrics rendering error with version 15.0.0-0 #554

@vothanhbinhlt

Description

@vothanhbinhlt

Hello everyone. First, I would like to thank you for merging PR to support exemplars in this package. I am very excited. I am trying version 15.0 in my current project and fact with an issuer of metrics rendering here is an example:

We are using: typescript version 4.8.4 and nestjs framework

# metrics.ts
import * as promClient from 'prom-client';

export const register = promClient.register;

const fakeRegistry: any = promClient.Registry; // I have to cheat here because It seems type of the library have not supported
register.setContentType(fakeRegistry.OPENMETRICS_CONTENT_TYPE);

// promClient.collectDefaultMetrics({ register });
export const histogram = new promClient.Histogram({
  name: 'http_request_duration_seconds',
  help: 'Duration of HTTP requests in seconds',
  labelNames: ['method', 'path', 'status', 'traceID', 'spanID'],
  buckets: [0.5, 1, 2, 5, 10, 60],
  enableExemplars: true,
});

// Register the histogram
register.registerMetric(histogram);
# httpmiddleware.ts
...
    histogram.observe({
      labels: {
        method,
        path,
        status: statusCode,
      },
      value: time / 1000,
      exemplarLabels: {
        traceID: spanContext.traceId,
        spanID: spanContext.spanId,
      },
    });
...

Results

# HELP http_request_duration_seconds Duration of HTTP requests in seconds
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{le="0.5",method="GET",path="/metrics",status="200"} 1
 # {traceID="659eb21633214be74be9b03afa6f7105",spanID="cbb23fa4a5669144"} 0.04501697799999999 1678595397.754
http_request_duration_seconds_bucket{le="1",method="GET",path="/metrics",status="200"} 1
http_request_duration_seconds_bucket{le="2",method="GET",path="/metrics",status="200"} 1
http_request_duration_seconds_bucket{le="5",method="GET",path="/metrics",status="200"} 1
http_request_duration_seconds_bucket{le="10",method="GET",path="/metrics",status="200"} 1
http_request_duration_seconds_bucket{le="60",method="GET",path="/metrics",status="200"} 1
http_request_duration_seconds_bucket{le="+Inf",method="GET",path="/metrics",status="200"} 1
http_request_duration_seconds_sum{method="GET",path="/metrics",status="200"} 0.04501697799999999
http_request_duration_seconds_count{method="GET",path="/metrics",status="200"} 1
# EOF

you can see the result has some unexpected new-lines with Exemplars. Therefore, Prometheus said "INVALID" " " is not a valid start token

Do I miss anything? please help me, I am very waiting for this feature

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions