@nestjs/observe 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +135 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/agent/detached-observe-worker.d.ts +1 -0
  5. package/dist/agent/detached-observe-worker.js +104 -0
  6. package/dist/agent/observe-agent.shared-buffer.d.ts +42 -0
  7. package/dist/agent/observe-agent.shared-buffer.js +211 -0
  8. package/dist/agent/observe-agent.worker.d.ts +25 -0
  9. package/dist/agent/observe-agent.worker.js +213 -0
  10. package/dist/custom-metrics/counter.d.ts +39 -0
  11. package/dist/custom-metrics/counter.js +128 -0
  12. package/dist/custom-metrics/gauge.d.ts +40 -0
  13. package/dist/custom-metrics/gauge.js +134 -0
  14. package/dist/custom-metrics/index.d.ts +3 -0
  15. package/dist/custom-metrics/index.js +3 -0
  16. package/dist/custom-metrics/summary.d.ts +38 -0
  17. package/dist/custom-metrics/summary.js +106 -0
  18. package/dist/encoders/custom-metrics.encoder.d.ts +25 -0
  19. package/dist/encoders/custom-metrics.encoder.js +50 -0
  20. package/dist/encoders/job-snapshot.encoder.d.ts +28 -0
  21. package/dist/encoders/job-snapshot.encoder.js +28 -0
  22. package/dist/encoders/remap-keys.util.d.ts +1 -0
  23. package/dist/encoders/remap-keys.util.js +10 -0
  24. package/dist/encoders/request-snapshot.encoder.d.ts +33 -0
  25. package/dist/encoders/request-snapshot.encoder.js +32 -0
  26. package/dist/encoders/runtime-metrics.encoder.d.ts +63 -0
  27. package/dist/encoders/runtime-metrics.encoder.js +55 -0
  28. package/dist/encoders/trace.encoder.d.ts +19 -0
  29. package/dist/encoders/trace.encoder.js +20 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +10 -0
  32. package/dist/instrument/create-instance-decorator.instrument.d.ts +7 -0
  33. package/dist/instrument/create-instance-decorator.instrument.js +165 -0
  34. package/dist/interfaces/custom-metric.interface.d.ts +18 -0
  35. package/dist/interfaces/custom-metric.interface.js +1 -0
  36. package/dist/interfaces/graphql.interfaces.d.ts +12 -0
  37. package/dist/interfaces/graphql.interfaces.js +1 -0
  38. package/dist/interfaces/index.d.ts +7 -0
  39. package/dist/interfaces/index.js +7 -0
  40. package/dist/interfaces/job-snapshot.interface.d.ts +23 -0
  41. package/dist/interfaces/job-snapshot.interface.js +1 -0
  42. package/dist/interfaces/node-runtime-metrics.interface.d.ts +37 -0
  43. package/dist/interfaces/node-runtime-metrics.interface.js +1 -0
  44. package/dist/interfaces/observe-options.interface.d.ts +93 -0
  45. package/dist/interfaces/observe-options.interface.js +1 -0
  46. package/dist/interfaces/request-snapshot.interface.d.ts +23 -0
  47. package/dist/interfaces/request-snapshot.interface.js +1 -0
  48. package/dist/interfaces/trace-events.interfaces.d.ts +17 -0
  49. package/dist/interfaces/trace-events.interfaces.js +1 -0
  50. package/dist/interfaces/trace-span.interface.d.ts +12 -0
  51. package/dist/interfaces/trace-span.interface.js +1 -0
  52. package/dist/observe.constants.d.ts +2 -0
  53. package/dist/observe.constants.js +2 -0
  54. package/dist/observe.module.d.ts +20 -0
  55. package/dist/observe.module.js +181 -0
  56. package/dist/profiling/cpu-profiler.service.d.ts +45 -0
  57. package/dist/profiling/cpu-profiler.service.js +146 -0
  58. package/dist/profiling/fold-profile.util.d.ts +28 -0
  59. package/dist/profiling/fold-profile.util.js +0 -0
  60. package/dist/profiling/profile-uploader.d.ts +19 -0
  61. package/dist/profiling/profile-uploader.js +88 -0
  62. package/dist/profiling/span-slice-recorder.d.ts +18 -0
  63. package/dist/profiling/span-slice-recorder.js +78 -0
  64. package/dist/protocols/graphql-observe-agent.service.d.ts +58 -0
  65. package/dist/protocols/graphql-observe-agent.service.js +261 -0
  66. package/dist/protocols/graphql-operation-parser.d.ts +10 -0
  67. package/dist/protocols/graphql-operation-parser.js +174 -0
  68. package/dist/protocols/http-observe-agent.service.d.ts +31 -0
  69. package/dist/protocols/http-observe-agent.service.js +186 -0
  70. package/dist/protocols/queue-observe-agent.service.d.ts +15 -0
  71. package/dist/protocols/queue-observe-agent.service.js +132 -0
  72. package/dist/protocols/rpc-observe-agent.service.d.ts +33 -0
  73. package/dist/protocols/rpc-observe-agent.service.js +183 -0
  74. package/dist/services/index.d.ts +1 -0
  75. package/dist/services/index.js +1 -0
  76. package/dist/services/logger-patcher.service.d.ts +12 -0
  77. package/dist/services/logger-patcher.service.js +76 -0
  78. package/dist/services/node-runtime-metrics.service.d.ts +23 -0
  79. package/dist/services/node-runtime-metrics.service.js +156 -0
  80. package/dist/services/operation-trace.registry.d.ts +49 -0
  81. package/dist/services/operation-trace.registry.js +364 -0
  82. package/dist/services/stdout-forwarder.service.d.ts +21 -0
  83. package/dist/services/stdout-forwarder.service.js +128 -0
  84. package/dist/services/trace-sampler.service.d.ts +19 -0
  85. package/dist/services/trace-sampler.service.js +38 -0
  86. package/dist/services/tracer.service.d.ts +48 -0
  87. package/dist/services/tracer.service.js +186 -0
  88. package/dist/trace-span.delegate.d.ts +10 -0
  89. package/dist/trace-span.delegate.js +24 -0
  90. package/dist/types/key-of.type.d.ts +1 -0
  91. package/dist/types/key-of.type.js +1 -0
  92. package/dist/types/path-value.type.d.ts +6 -0
  93. package/dist/types/path-value.type.js +1 -0
  94. package/dist/utils/assert-module-options.util.d.ts +2 -0
  95. package/dist/utils/assert-module-options.util.js +8 -0
  96. package/dist/utils/default-trace-id-generator.util.d.ts +1 -0
  97. package/dist/utils/default-trace-id-generator.util.js +11 -0
  98. package/dist/utils/log-line.parser.d.ts +9 -0
  99. package/dist/utils/log-line.parser.js +59 -0
  100. package/dist/utils/log-redactor.d.ts +11 -0
  101. package/dist/utils/log-redactor.js +150 -0
  102. package/dist/utils/redact-url-query.d.ts +2 -0
  103. package/dist/utils/redact-url-query.js +51 -0
  104. package/dist/utils/source-context.util.d.ts +11 -0
  105. package/dist/utils/source-context.util.js +130 -0
  106. package/dist/utils/source-map-resolver.util.d.ts +7 -0
  107. package/dist/utils/source-map-resolver.util.js +107 -0
  108. package/package.json +129 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2017-2024
4
+ Kamil Mysliwiec <https://kamilmysliwiec.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ 'Software'), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ <p align="center">
2
+ <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
3
+ </p>
4
+
5
+ <p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
6
+ <p align="center">
7
+ <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/common.svg" alt="NPM Version" /></a>
8
+ <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/common.svg" alt="Package License" /></a>
9
+ <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
10
+ <a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
11
+ <a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
12
+ <a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
13
+ <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
14
+ <a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
15
+ <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
16
+ <a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
17
+
18
+ ## Description
19
+
20
+ `@nestjs/observe` is an observability module for [NestJS](https://nestjs.com) applications. It instruments HTTP, GraphQL, microservice (RPC), and BullMQ queue handlers, collects traces, runtime metrics, custom metrics, and CPU profiles, and ships them to a collector from a detached worker thread so the request path stays untouched.
21
+
22
+ ```bash
23
+ $ npm install @nestjs/observe
24
+ ```
25
+
26
+ ## Quick start
27
+
28
+ `createObserveModule()` returns both the dynamic module and the instrumentation
29
+ hook Nest needs at bootstrap:
30
+
31
+ ```ts
32
+ // observe.ts
33
+ import { createObserveModule } from "@nestjs/observe";
34
+
35
+ export const { ObserveModule, ObserveInstrument } = createObserveModule();
36
+ ```
37
+
38
+ ```ts
39
+ // app.module.ts
40
+ import { Module } from "@nestjs/common";
41
+ import { ObserveModule } from "./observe";
42
+
43
+ @Module({
44
+ imports: [
45
+ ObserveModule.forRoot({
46
+ appKey: process.env.OBSERVE_APP_KEY,
47
+ appSecret: process.env.OBSERVE_APP_SECRET,
48
+ serviceId: "my-service",
49
+ }),
50
+ ],
51
+ })
52
+ export class AppModule {}
53
+ ```
54
+
55
+ ```ts
56
+ // main.ts
57
+ import { NestFactory } from "@nestjs/core";
58
+ import { AppModule } from "./app.module";
59
+ import { ObserveInstrument } from "./observe";
60
+
61
+ async function bootstrap() {
62
+ const app = await NestFactory.create(AppModule, {
63
+ instrument: ObserveInstrument,
64
+ });
65
+ await app.listen(3000);
66
+ }
67
+ bootstrap();
68
+ ```
69
+
70
+ ### Async configuration
71
+
72
+ `ObserveModule.forRootAsync()` resolves the options from the DI container, via
73
+ `useFactory`, `useClass`, or `useExisting`:
74
+
75
+ ```ts
76
+ ObserveModule.forRootAsync({
77
+ imports: [ConfigModule],
78
+ inject: [ConfigService],
79
+ useFactory: (config: ConfigService) => ({
80
+ appKey: config.getOrThrow("OBSERVE_APP_KEY"),
81
+ appSecret: config.getOrThrow("OBSERVE_APP_SECRET"),
82
+ serviceId: config.getOrThrow("OBSERVE_SERVICE_ID"),
83
+ }),
84
+ });
85
+ ```
86
+
87
+ `useClass` and `useExisting` take a class implementing `ObserveOptionsFactory`:
88
+
89
+ ```ts
90
+ @Injectable()
91
+ export class ObserveConfig implements ObserveOptionsFactory {
92
+ createObserveOptions(): ObserveOptions {
93
+ return { appKey: "...", appSecret: "...", serviceId: "..." };
94
+ }
95
+ }
96
+ ```
97
+
98
+ ## Optional peer dependencies
99
+
100
+ Protocol integrations are only loaded when you use them, and their packages are optional peers:
101
+
102
+ - `@nestjs/microservices` - RPC/microservice instrumentation
103
+ - `@nestjs/graphql` - GraphQL operation instrumentation
104
+ - `@nestjs/bullmq` and `bullmq` - queue/job instrumentation
105
+
106
+ ## Test
107
+
108
+ ```bash
109
+ # unit tests
110
+ $ npm test
111
+
112
+ # integration tests (boot real Nest apps on real ports)
113
+ $ npm run test:int
114
+ ```
115
+
116
+ ## Module format
117
+
118
+ The package ships as ESM only. CommonJS consumers can still `require()` it
119
+ through Node's `require(esm)` support, which is why the engine floor is
120
+ **Node 20.19** (or 22.12) rather than 20.0 - and why nothing in the module graph
121
+ uses top-level await, which `require(esm)` cannot load.
122
+
123
+ ```js
124
+ // works from CommonJS on Node >= 20.19
125
+ const { createObserveModule } = require("@nestjs/observe");
126
+ ```
127
+
128
+ ## Stay in touch
129
+
130
+ - Website - [https://nestjs.com](https://nestjs.com/)
131
+ - Twitter - [@nestframework](https://twitter.com/nestframework)
132
+
133
+ ## License
134
+
135
+ Nest is [MIT licensed](LICENSE).