@nestjs/observe 0.3.6 → 0.3.7
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.
|
@@ -44,6 +44,7 @@ export declare class ObserveAgentWorker implements OnModuleInit, OnApplicationSh
|
|
|
44
44
|
*/
|
|
45
45
|
private startContinuousProfiling;
|
|
46
46
|
onApplicationShutdown(): Promise<void>;
|
|
47
|
+
private get hasScaffoldCredentials();
|
|
47
48
|
private get endpoint();
|
|
48
49
|
/**
|
|
49
50
|
* Says out loud when credentials are about to cross the network unencrypted.
|
|
@@ -30,6 +30,17 @@ const DEFAULT_FLUSH_INTERVAL = 5000; // 5 seconds
|
|
|
30
30
|
*/
|
|
31
31
|
const DEFAULT_COLLECTOR_ENDPOINT = process.env.OBSERVE_ENDPOINT ?? "https://observe-api.nestjs.com";
|
|
32
32
|
const MIN_FLUSH_INTERVAL = 1000; // 1 second
|
|
33
|
+
/**
|
|
34
|
+
* The credentials `nest new --observe` writes into `AppModule`.
|
|
35
|
+
*
|
|
36
|
+
* A project fresh from the generator has these until someone signs up, so
|
|
37
|
+
* they mean "not connected yet", not "wrong": sending them only buys a 401
|
|
38
|
+
* and an `Error:` line on the very first `npm run start`.
|
|
39
|
+
*/
|
|
40
|
+
const SCAFFOLD_APP_KEY = "YOUR_APP_KEY";
|
|
41
|
+
const SCAFFOLD_APP_SECRET = "YOUR_APP_SECRET";
|
|
42
|
+
const DEMO_URL = "https://www.observe-demo.nestjs.com/dashboard";
|
|
43
|
+
const SIGN_UP_URL = "https://observe.nestjs.com";
|
|
33
44
|
let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
34
45
|
observeAgentSharedBuffer;
|
|
35
46
|
options;
|
|
@@ -57,7 +68,16 @@ let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
|
57
68
|
this.nodeRuntimeMetricsService = nodeRuntimeMetricsService;
|
|
58
69
|
}
|
|
59
70
|
onModuleInit() {
|
|
60
|
-
this.
|
|
71
|
+
if (this.hasScaffoldCredentials) {
|
|
72
|
+
// Nothing is sent, so there is no worker to start. The flush timer below
|
|
73
|
+
// still runs and empties the buffer, which the instrumentation keeps
|
|
74
|
+
// writing into either way.
|
|
75
|
+
this.logger.log(`Observe is installed but not connected yet: appKey and appSecret are still the placeholders from nest new, so no telemetry is sent. ` +
|
|
76
|
+
`See what this app will look like: ${DEMO_URL} - then create a free account at ${SIGN_UP_URL} for your own key and secret.`);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.initializeWorker();
|
|
80
|
+
}
|
|
61
81
|
let flushIntervalTime = this.options.flushInterval ?? DEFAULT_FLUSH_INTERVAL;
|
|
62
82
|
if (flushIntervalTime < MIN_FLUSH_INTERVAL) {
|
|
63
83
|
this.logger.warn(`Flush interval is too short (${flushIntervalTime}ms). Setting to minimum of ${MIN_FLUSH_INTERVAL}ms.`);
|
|
@@ -68,7 +88,9 @@ let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
|
68
88
|
this.options.flushInterval = MIN_FLUSH_INTERVAL;
|
|
69
89
|
}
|
|
70
90
|
this.flushInterval = setInterval(() => this.flush(), flushIntervalTime);
|
|
71
|
-
this.
|
|
91
|
+
if (!this.hasScaffoldCredentials) {
|
|
92
|
+
this.startRuntimeMetrics();
|
|
93
|
+
}
|
|
72
94
|
// Continuous profiling is shelved: a flame graph asks more of a reader than
|
|
73
95
|
// most services' owners want to give it, and the signal is not worth the
|
|
74
96
|
// sampling cost until there is a UI that makes it legible. The
|
|
@@ -170,6 +192,10 @@ let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
|
170
192
|
}
|
|
171
193
|
this.worker = null;
|
|
172
194
|
}
|
|
195
|
+
get hasScaffoldCredentials() {
|
|
196
|
+
return (this.options.appKey === SCAFFOLD_APP_KEY &&
|
|
197
|
+
this.options.appSecret === SCAFFOLD_APP_SECRET);
|
|
198
|
+
}
|
|
173
199
|
get endpoint() {
|
|
174
200
|
return this.options.endpoint ?? DEFAULT_COLLECTOR_ENDPOINT;
|
|
175
201
|
}
|
|
@@ -286,6 +312,10 @@ let ObserveAgentWorker = ObserveAgentWorker_1 = class ObserveAgentWorker {
|
|
|
286
312
|
// gone quiet, and an empty buffer would otherwise return here and strand
|
|
287
313
|
// them until shutdown.
|
|
288
314
|
this.observeAgentSharedBuffer.drainPendingLogs();
|
|
315
|
+
if (this.hasScaffoldCredentials) {
|
|
316
|
+
this.observeAgentSharedBuffer.resetMainThreadBuffer();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
289
319
|
if (this.observeAgentSharedBuffer.isBufferEmpty()) {
|
|
290
320
|
return;
|
|
291
321
|
}
|
package/package.json
CHANGED