xcally-nest-library 0.0.16 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcally-nest-library",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,11 +39,13 @@
39
39
  "class-transformer": "^0.5.1",
40
40
  "class-validator": "^0.14.1",
41
41
  "datadog-winston": "^1.6.0",
42
+ "dotenv": "^16.4.5",
42
43
  "nest-winston": "^1.9.4",
43
44
  "nestjs-grpc-exceptions": "^0.2.2",
44
45
  "nestjs-paginate": "^8.6.2",
45
46
  "nestjs-pino": "^4.1.0",
46
47
  "pino": "^9.4.0",
48
+ "pino-opentelemetry-transport": "^1.0.1",
47
49
  "pino-pretty": "^11.2.2",
48
50
  "reflect-metadata": "^0.2.2",
49
51
  "rxjs": "^7.8.1",
@@ -2,7 +2,40 @@ import { DynamicModule, Global, Module } from '@nestjs/common';
2
2
  import { ConfigModule, ConfigService } from '@nestjs/config';
3
3
  import { LoggerModule as LoggerModulePino } from 'nestjs-pino';
4
4
  import { LoggerService } from './logger.service';
5
-
5
+ import 'dotenv/config';
6
+ import type { Options } from 'pino-opentelemetry-transport';
7
+ const options: Options = {
8
+ resourceAttributes: {
9
+ 'service.name': process.env.npm_package_name || 'unknown',
10
+ // 'service.version': process.env.npm_package_version || '1.0.0',
11
+ },
12
+ logRecordProcessorOptions: [
13
+ {
14
+ recordProcessorType: 'batch',
15
+ exporterOptions: {
16
+ protocol: 'http',
17
+ httpExporterOptions: {
18
+ url: new URL('v1/logs', process.env.OTLP_HTTP_URL || 'http://localhost:4318/').toString(),
19
+ },
20
+ },
21
+ },
22
+ // {
23
+ // recordProcessorType: 'batch',
24
+ // exporterOptions: {
25
+ // protocol: 'grpc',
26
+ // grpcExporterOptions: {
27
+ // headers: { foo: 'some custom header' },
28
+ // },
29
+ // },
30
+ // },
31
+ // {
32
+ // recordProcessorType: 'simple',
33
+ // exporterOptions: { protocol: 'console' },
34
+ // },
35
+ ],
36
+ loggerName: (process.env.npm_package_name || 'unknown') + '-logger',
37
+ serviceVersion: process.env.npm_package_version || 'unknown',
38
+ };
6
39
  @Global()
7
40
  @Module({})
8
41
  export class LoggerModule {
@@ -16,6 +49,7 @@ export class LoggerModule {
16
49
  imports: [ConfigModule],
17
50
  inject: [ConfigService],
18
51
  useFactory: async (config: ConfigService) => {
52
+ const projectName = process.env.npm_package_name || 'default_project';
19
53
  return {
20
54
  pinoHttp: {
21
55
  level: config.get('LOG_LEVEL') || 'info',
@@ -34,6 +68,10 @@ export class LoggerModule {
34
68
  },
35
69
  transport: {
36
70
  targets: [
71
+ {
72
+ target: 'pino-opentelemetry-transport',
73
+ options,
74
+ },
37
75
  {
38
76
  level: 'debug',
39
77
  target: 'pino-pretty',
@@ -52,7 +90,7 @@ export class LoggerModule {
52
90
  level: 'info',
53
91
  target: 'pino/file',
54
92
  options: {
55
- destination: './logs/info.log',
93
+ destination: `./logs/${projectName}-info.log`,
56
94
  mkdir: true,
57
95
  append: process.env.NODE_ENV !== 'production' ? false : true,
58
96
  },