Giter VIP home page Giter VIP logo

Comments (13)

pragmaticivan avatar pragmaticivan commented on May 16, 2024 1

@issackr I just fixed the reuse of metrics. I haven't tested on NestJS 8.x yet. They have changed a lot of things. Might need to test a new example this week.

from nestjs-otel.

issackr avatar issackr commented on May 16, 2024

Hey, I created PrometheusModule for metrics based on the package and I'm trying to test it but get the error:
Nest can't resolve dependencies of the MetricService (?). Please make sure that the argument OpenTelemetryMeterProvider at index [0] is available in the PrometheusModule context.

this is my module:
import { Module } from "@nestjs/common";
import { LoggerModule } from "../../logger/logger.module";
import { PrometheusService } from "./prometheus.service";
import { MetricService } from "nestjs-otel";

@module({
imports: [LoggerModule],
providers: [PrometheusService, MetricService],
exports: [PrometheusService],
})
export class PrometheusModule {}

and my testing module:
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [PrometheusModule],
providers: [
SweetLogger,
ImageResolver,
{
provide: 'METADATA_SERVICE',
useValue: Image,
},
],
}).compile();

resolver = module.get<ImageResolver>(ImageResolver);

});

but I fail to provide OpenTelemetryMeterProvider whatever I do, I'm not sure how to provide injected stuff.
Will be glad for any help!
Tnx

from nestjs-otel.

pragmaticivan avatar pragmaticivan commented on May 16, 2024

MetricService is injected globally when you use that lib. What you are trying to do is to inject the service directly into another module without any other dependency is available.

In your main app you need OpenTelemetryModule.forRoot( to be called in your imports for all the dependencies of this service to be available.

Is there a reason you would be creating a prometheus service? MetricService should cover most of the cases, all you need is a prometheus exporter

from nestjs-otel.

issackr avatar issackr commented on May 16, 2024

basically you are right but I used interceptor to meter all requests and I noticed that the counters are reset each time if not injected one by one, so I wrapped it with a module that is MetricService alike.

Regarding the error, I added OpenTelemetryModule.forRoot() to my PrometheusModule and now I get another error:
Nest can't resolve dependencies of the OpenTelemetryCoreModule

from nestjs-otel.

pragmaticivan avatar pragmaticivan commented on May 16, 2024

Hey @issackr could you share more on that issue? when you mean reset each time if not injected, what you mean by that? It should reuse the existing one.

from nestjs-otel.

issackr avatar issackr commented on May 16, 2024

@pragmaticivan Sure, it means the counters value aggregators remain on 1 after each call, no matter how many calls you make. Regarding the injection I meant like in other libraries which you need to inject each counter your'e using (not generic enough for me), anyway I solved it by wrapping my metric in another map of my own like in MetricService.
I can share the code if you like.
Anyway, do you have any lead how to solve my tests problem about OpenTelemetryCoreModule ModuleRef?
The error:
Nest can't resolve dependencies of the OpenTelemetryCoreModule (OpenTelemetryModuleOptions, ?). Please make sure that the argument ModuleRef at index [1] is available in the OpenTelemetryCoreModule context.

Tnx

from nestjs-otel.

issackr avatar issackr commented on May 16, 2024

@pragmaticivan I also migrated my project to nest 8, maybe this is whats making problems

from nestjs-otel.

pragmaticivan avatar pragmaticivan commented on May 16, 2024

Ohh I haven't tested with nest 8, there might be a problem there indeed.

from nestjs-otel.

pragmaticivan avatar pragmaticivan commented on May 16, 2024

basically you are right but I used interceptor to meter all requests and I noticed that the counters are reset each time if not injected one by one, so I wrapped it with a module that is MetricService alike.

Regarding the error, I added OpenTelemetryModule.forRoot() to my PrometheusModule and now I get another error:
Nest can't resolve dependencies of the OpenTelemetryCoreModule

I think I found the bug you mentioned while adding more tests today.

#52

from nestjs-otel.

pragmaticivan avatar pragmaticivan commented on May 16, 2024

release 1.8.2 should have the fix @issackr

from nestjs-otel.

issackr avatar issackr commented on May 16, 2024

@pragmaticivan Looks awesome, thanks for the great work! still having the testing ModuleRef issue though

from nestjs-otel.

pragmaticivan avatar pragmaticivan commented on May 16, 2024

fyi @issackr a lot of the problems I found when I created that lib are going to be fixed in this PR: #55

It will require a Major version though.

from nestjs-otel.

issackr avatar issackr commented on May 16, 2024

@pragmaticivan Tnx for the update, I'm definitely gonna use it

from nestjs-otel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.