Skip to content

dimensions are not escaped #38

@AZm87

Description

@AZm87

I developed a API (based on vapor 4) that throws errors with additional information

enum APIError: Error {
    ...
    case invalidParameter(String),
    ...
}

I want to monitor the reasons for a failed response with prometheus so I added the following line:

prometheus.makeCounter(label: "response_error", dimensions: [("error", "\(error)")]).increment(by: 1)

But this results in the following line in the output:

response_error{error="invalidParameter("Invalid value for parameter <code>")"} 28

According to the documentation the "Label values may contain any Unicode characters." but Prometheus can't read this.

Steps to reproduce

import Prometheus

let prometheus = PrometheusClient()
prometheus.makeCounter(label: "response_error", dimensions: [("error", "a\"b\"c")]).increment(by: 1)
let f : (String) -> () = { print($0) }
prometheus.collect(f)

Actual behavior

the result is response_error{error="a"b"c"} 1

Expected behavior

the result should be escaped to response_error{error="a'b'c"} 1. In my first tests response_error{error="a\"b\"c"} 1 also worked but not sure.

Environment

  • OS version: MacOS Big Sur Version 11.0.1
  • Swift version: Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
  • SwiftPrometheus 1.0.0-alpha

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions