Julien-R44/adonisjs-prometheus

Cannot resolve "Adonis/Prometheus" namespace from the IoC Container

Closed this issue · 0 comments

Hey,
Tried to implement this addon to my adonis project.
The middleware import works fine but when i try to import: "import Prometheus from '@IOC:Adonis/Prometheus'".
Adonis responds with the error

E_IOC_LOOKUP_FAILED: Cannot resolve "Adonis/Prometheus" namespace from the IoC Container

This in the following code:

import Prometheus from '@ioc:Adonis/Prometheus'

export const TestMetric = new Prometheus.Histogram({
  name: 'testmetric',
  help: '',
  labelNames: ['foo', 'bar'],
})

I've tried to check it out myself but can't really find why it would not be able to resolve it while it can resolve the middleware.

for installation I followed the normal process of installing the package configuring it with node ace like in the readme and adding the middleware.

Would be awesome if anyone would be able to help out with this.

Edit:
Found out what is causing it, I was playing around with the Adonis Profiler that is like the internal performance profiler. And tried to add that to ready function of the app provider with some logic in it to expose more metrics to prometheus.
Seems like it doesn't like that, think the ioc container is not ready there or something. Which is weird because:

export default class AppProvider {
  constructor(protected app: ApplicationContract) {}

  public register() {
    // Register your own bindings
  }

  public async boot() {
    // IoC container is ready
  }

  public async ready() {
    // App is ready
  }

  public async shutdown() {
    // Cleanup, since app is going down
  }
}

in the default hello-world project it says that the ioc container is ready in the boot cycle.
Closing this because I don't think it is related to this project but more likely to be for the adonis core project.
edit2: Just remembered that you have to do dynamic imports when you do something in those methods 🤦