Skip to content

Commit

Permalink
V3.0.0 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
MetinSeylan authored Oct 15, 2022
1 parent f6da645 commit 0ac195f
Show file tree
Hide file tree
Showing 162 changed files with 10,903 additions and 11,458 deletions.
68 changes: 47 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ It also includes auto trace and metric instrumentations for some popular Nestjs
- [Distributed Logging with Trace ID](#distributed-logging-with-trace-id)
- #### Metrics
- [Setup](#metrics-1)
- [Decorators](#metric-decorators)
- [Metric Providers](#metric-providers)
- [Auto Metric Observers](#auto-metric-observers)
- ~~[Decorators](#metric-decorators)~~
- ~~[Metric Providers](#metric-providers)~~
- ~~[Auto Metric Observers](#auto-metric-observers)~~

OpenTelemetry Metrics currently experimental. So, this library doesn't support metric decorators and Auto Observers until it's stable. but if you want to use it, you can use OpenTelemetry API directly.

Competability table for Nestjs versions.

| Nestjs | Nestjs-OpenTelemetry |
|--------|----------------------|
| 9.x | 3.x.x |
| 8.x | 2.x.x |


### Installation
``` bash
Expand All @@ -42,7 +52,26 @@ import { OpenTelemetryModule } from '@metinseylan/nestjs-opentelemetry';
@Module({
imports: [
OpenTelemetryModule.forRoot({
applicationName: 'nestjs-opentelemetry-example',
serviceName: 'nestjs-opentelemetry-example',
})
]
})
export class AppModule {}
```

Async configuration example
```ts
import { OpenTelemetryModule } from '@metinseylan/nestjs-opentelemetry';
import {ConfigModule, ConfigService} from '@nestjs/config';

@Module({
imports: [
OpenTelemetryModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
serviceName: configService.get('SERVICE_NAME'),
}),
inject: [ConfigService]
})
]
})
Expand All @@ -52,10 +81,9 @@ export class AppModule {}
| key | value | description |
|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| traceAutoInjectors | ControllerInjector, GuardInjector, EventEmitterInjector, ScheduleInjector, PipeInjector, LoggerInjector | default auto trace instrumentations |
| metricAutoObservers | ResourceMetric, ProcessStartTimeMetric, ProcessOpenFdsMetric, ProcessMaxFdsMetric, ActiveHandlesMetric, ActiveHandlesTotalMetric, HttpRequestDurationSeconds, GrpcRequestDurationSeconds, RabbitMqRequestDurationSeconds | default auto metric collectors |
| autoDetectResources | true | inherited from <a href="https://github.com/open-telemetry/opentelemetry-js/blob/745bd5c34d3961dc73873190adc763747e5e026d/experimental/packages/opentelemetry-sdk-node/src/types.ts#:~:text=NodeSDKConfiguration">NodeSDKConfiguration</a> |
| metricAutoObservers | ResourceMetric, ProcessStartTimeMetric, ProcessOpenFdsMetric, ProcessMaxFdsMetric, ActiveHandlesMetric, ActiveHandlesTotalMetric, HttpRequestDurationSeconds, GrpcRequestDurationSeconds, RabbitMqRequestDurationSeconds | default auto metric collectors | | inherited from <a href="https://github.com/open-telemetry/opentelemetry-js/blob/745bd5c34d3961dc73873190adc763747e5e026d/experimental/packages/opentelemetry-sdk-node/src/types.ts#:~:text=NodeSDKConfiguration">NodeSDKConfiguration</a> |
| contextManager | AsyncLocalStorageContextManager | default trace context manager inherited from <a href="https://github.com/open-telemetry/opentelemetry-js/blob/745bd5c34d3961dc73873190adc763747e5e026d/experimental/packages/opentelemetry-sdk-node/src/types.ts#:~:text=NodeSDKConfiguration"> NodeSDKConfiguration </a> |
| instrumentations | HttpInstrumentation | default instrumentations inherited from <a href="https://github.com/open-telemetry/opentelemetry-js/blob/745bd5c34d3961dc73873190adc763747e5e026d/experimental/packages/opentelemetry-sdk-node/src/types.ts#:~:text=NodeSDKConfiguration"> NodeSDKConfiguration </a> |
| instrumentations | AutoInstrumentations | default instrumentations inherited from <a href="https://github.com/open-telemetry/opentelemetry-js/blob/745bd5c34d3961dc73873190adc763747e5e026d/experimental/packages/opentelemetry-sdk-node/src/types.ts#:~:text=NodeSDKConfiguration"> NodeSDKConfiguration </a> |
| spanProcessor | NoopSpanProcessor | default spanProcessor inherited from <a href="https://github.com/open-telemetry/opentelemetry-js/blob/745bd5c34d3961dc73873190adc763747e5e026d/experimental/packages/opentelemetry-sdk-node/src/types.ts#:~:text=NodeSDKConfiguration"> NodeSDKConfiguration </a> |
| textMapPropagator | JaegerPropagator, B3Propagator | default textMapPropagator inherited from <a href="https://github.com/open-telemetry/opentelemetry-js/blob/745bd5c34d3961dc73873190adc763747e5e026d/experimental/packages/opentelemetry-sdk-node/src/types.ts#:~:text=NodeSDKConfiguration"> NodeSDKConfiguration </a> |

Expand Down Expand Up @@ -205,8 +233,8 @@ import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';

@Module({
imports: [OpenTelemetryModule.forRoot({
applicationName: 'nestjs-opentelemetry-example',
metricExporter: new PrometheusExporter({
serviceName: 'nestjs-opentelemetry-example',
metricReader: new PrometheusExporter({
endpoint: 'metrics',
port: 9464,
})
Expand All @@ -217,7 +245,7 @@ export class AppModule {}
Now you can access Prometheus exporter with auto collected metrics [http://localhost:9464/metrics](http://localhost:9464/metrics).
Also, you can find different exporters [here](https://opentelemetry.io/docs/js/exporters/)
***
### Metric Decorators
### Metric Decorators (Deprecated)
If you need to observe simple block of function, you can use some basic decorators like `@Counter` and `@Observer`

#### Counter
Expand All @@ -241,7 +269,7 @@ export class AppService {
```
And of course, you can configure your decorator metric, the first parameter is "name" and the second one is [MetricOptions](https://github.com/open-telemetry/opentelemetry-js/blob/357ec92e95e03b4d2309c65ffb17d06105985628/experimental/packages/opentelemetry-api-metrics/src/types/Metric.ts#L29)

#### Observer
#### Observer (Deprecated)
```ts
import {Injectable} from '@nestjs/common';
import {Observer} from "./Observer";
Expand All @@ -259,7 +287,7 @@ export class AppService {
```
`@Observer` decorator uses OpenTelemetry `ValueRecorder` metric. If you check Prometheus exporter, you will see metric and configuration parameters same as `@Counter`.
***
### Metric Providers
### Metric Providers (Deprecated)
In advanced usage cases, you need to access the native OpenTelemetry Metric provider to access them from the Nestjs application context.

```ts
Expand All @@ -282,7 +310,7 @@ export class AppService {
}
```
***
### Auto Metric Observers
### Auto Metric Observers (Deprecated)
This library has extendable resource and protocol-specific Auto Observers. All of them come with default module configuration, which you can extend and configure.
```ts
import { Module } from '@nestjs/common';
Expand All @@ -296,26 +324,25 @@ import {
@Module({
imports: [
OpenTelemetryModule.forRoot({
applicationName: 'nestjs-opentelemetry-example',
serviceName: 'nestjs-opentelemetry-example',
metricAutoObservers: [
HttpRequestDurationSeconds.build({
boundaries: [20, 30, 100],
}),
ActiveHandlesMetric,
],
metricExporter: new PrometheusExporter({
metricReader: new PrometheusExporter({
endpoint: 'metrics',
port: 9464,
}),
metricInterval: 1000,
}),
],
})
export class AppModule {}
```
`.build` function takes [MetricOptions](https://github.com/open-telemetry/opentelemetry-js/blob/357ec92e95e03b4d2309c65ffb17d06105985628/experimental/packages/opentelemetry-api-metrics/src/types/Metric.ts#L29) as a parameter.

#### List Of Auto Observers
#### List Of Auto Observers (Deprecated)

| Metric Observer Provider | Description | Configurable |
|----------------------------------|---------------------------------------------------------------------------------------------|--------------|
Expand All @@ -340,7 +367,7 @@ export class AppModule {}

***

### Lets Combine All of them
### Let's Combine All of them
```ts
import { Module } from '@nestjs/common';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
Expand All @@ -351,12 +378,11 @@ import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
@Module({
imports: [
OpenTelemetryModule.forRoot({
applicationName: 'nestjs-opentelemetry-example',
metricExporter: new PrometheusExporter({
serviceName: 'nestjs-opentelemetry-example',
metricReader: new PrometheusExporter({
endpoint: 'metrics',
port: 9464,
}),
metricInterval: 1000,
spanProcessor: new SimpleSpanProcessor(
new ZipkinExporter({
url: 'your-zipkin-url',
Expand Down
3 changes: 0 additions & 3 deletions dist/Metric/Decorators/Counter.d.ts

This file was deleted.

13 changes: 0 additions & 13 deletions dist/Metric/Decorators/Counter.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/Metric/Decorators/Counter.js.map

This file was deleted.

4 changes: 0 additions & 4 deletions dist/Metric/Decorators/DecoratorType.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions dist/Metric/Decorators/DecoratorType.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/Metric/Decorators/DecoratorType.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/Metric/Decorators/Observer.d.ts

This file was deleted.

13 changes: 0 additions & 13 deletions dist/Metric/Decorators/Observer.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/Metric/Decorators/Observer.js.map

This file was deleted.

17 changes: 0 additions & 17 deletions dist/Metric/Injectors/BaseMetricInjector.d.ts

This file was deleted.

78 changes: 0 additions & 78 deletions dist/Metric/Injectors/BaseMetricInjector.js

This file was deleted.

Loading

0 comments on commit 0ac195f

Please sign in to comment.