Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False prometheusNotBoostrapped error with multiplex handler #86

Open
Tyler-Keith-Thompson opened this issue Jul 28, 2023 · 1 comment
Open

Comments

@Tyler-Keith-Thompson
Copy link

Steps to reproduce

Prometheus makes a few too many assumptions about my metrics system factory. I use the multiplex factory that comes from Apple and bootstrap prometheus with it, but then this code tries to cast the multiplexed factory and fails:

guard let prom = self.factory as? PrometheusWrappedMetricsFactory else {
    throw PrometheusError.prometheusFactoryNotBootstrapped(bootstrappedWith: "\(self.factory)")
}
return prom.client

Expected behavior

No error is thrown...cause it was in fact bootstrapped

Actual behavior

It throws the error

Environment

  • OS version:
  • Swift version:
  • Serverside Swift Framework:
  • Framework version:
@Tyler-Keith-Thompson
Copy link
Author

My temporary workaround:

struct PrometheusClientKey: StorageKey {
    typealias Value = PrometheusClient
}

extension Application {
    var prometheusClient: PrometheusClient? {
        get { storage[PrometheusClientKey.self] }
        set { storage[PrometheusClientKey.self] = newValue }
    }
}

I can just attach the client to the application. It's probably suboptimal, but fits my use-case for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant