@nestjs/observe 0.0.1 → 0.1.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.
- package/README.md +16 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/agent/detached-observe-worker.js +98 -1
- package/dist/agent/observe-agent.shared-buffer.d.ts +82 -0
- package/dist/agent/observe-agent.shared-buffer.js +94 -3
- package/dist/agent/observe-agent.worker.d.ts +28 -0
- package/dist/agent/observe-agent.worker.js +59 -5
- package/dist/custom-metrics/counter.d.ts +124 -0
- package/dist/custom-metrics/counter.js +93 -0
- package/dist/custom-metrics/gauge.d.ts +116 -0
- package/dist/custom-metrics/gauge.js +55 -0
- package/dist/custom-metrics/summary.d.ts +102 -0
- package/dist/custom-metrics/summary.js +100 -0
- package/dist/encoders/custom-metrics.encoder.js +18 -0
- package/dist/encoders/remap-keys.util.d.ts +11 -0
- package/dist/encoders/remap-keys.util.js +15 -0
- package/dist/encoders/trace.encoder.d.ts +7 -0
- package/dist/encoders/trace.encoder.js +12 -0
- package/dist/instrument/create-instance-decorator.instrument.d.ts +8 -0
- package/dist/instrument/create-instance-decorator.instrument.js +67 -0
- package/dist/interfaces/custom-metric.interface.d.ts +74 -0
- package/dist/interfaces/graphql.interfaces.d.ts +16 -0
- package/dist/interfaces/job-snapshot.interface.d.ts +70 -0
- package/dist/interfaces/node-runtime-metrics.interface.d.ts +5 -0
- package/dist/interfaces/observe-options.interface.d.ts +358 -0
- package/dist/interfaces/request-snapshot.interface.d.ts +62 -0
- package/dist/interfaces/trace-events.interfaces.d.ts +51 -0
- package/dist/interfaces/trace-span.interface.d.ts +29 -0
- package/dist/observe.module.js +29 -0
- package/dist/profiling/cpu-profiler.service.d.ts +65 -0
- package/dist/profiling/cpu-profiler.service.js +80 -0
- package/dist/profiling/fold-profile.util.d.ts +20 -0
- package/dist/profiling/fold-profile.util.js +0 -0
- package/dist/profiling/profile-uploader.d.ts +26 -0
- package/dist/profiling/profile-uploader.js +52 -0
- package/dist/profiling/span-slice-recorder.d.ts +51 -0
- package/dist/profiling/span-slice-recorder.js +77 -0
- package/dist/protocols/graphql-observe-agent.service.d.ts +128 -0
- package/dist/protocols/graphql-observe-agent.service.js +166 -0
- package/dist/protocols/graphql-operation-parser.d.ts +26 -0
- package/dist/protocols/graphql-operation-parser.js +66 -0
- package/dist/protocols/http-observe-agent.service.d.ts +19 -0
- package/dist/protocols/http-observe-agent.service.js +34 -0
- package/dist/protocols/queue-observe-agent.service.d.ts +8 -0
- package/dist/protocols/queue-observe-agent.service.js +32 -0
- package/dist/protocols/rpc-observe-agent.service.d.ts +7 -0
- package/dist/protocols/rpc-observe-agent.service.js +12 -0
- package/dist/services/logger-patcher.service.d.ts +4 -0
- package/dist/services/logger-patcher.service.js +13 -1
- package/dist/services/node-runtime-metrics.service.js +24 -8
- package/dist/services/operation-trace.registry.d.ts +56 -1
- package/dist/services/operation-trace.registry.js +145 -6
- package/dist/services/stdout-forwarder.service.d.ts +19 -0
- package/dist/services/stdout-forwarder.service.js +62 -0
- package/dist/services/trace-sampler.service.d.ts +6 -0
- package/dist/services/trace-sampler.service.js +3 -3
- package/dist/services/tracer.service.d.ts +91 -0
- package/dist/services/tracer.service.js +56 -1
- package/dist/trace-span.delegate.d.ts +11 -0
- package/dist/trace-span.delegate.js +11 -0
- package/dist/types/path-value.type.d.ts +4 -0
- package/dist/utils/default-trace-id-generator.util.js +11 -0
- package/dist/utils/log-line.parser.d.ts +14 -0
- package/dist/utils/log-line.parser.js +37 -0
- package/dist/utils/log-redactor.js +65 -0
- package/dist/utils/redact-url-query.d.ts +17 -0
- package/dist/utils/redact-url-query.js +38 -0
- package/dist/utils/source-context.util.d.ts +22 -0
- package/dist/utils/source-context.util.js +60 -0
- package/dist/utils/source-map-resolver.util.d.ts +13 -0
- package/dist/utils/source-map-resolver.util.js +26 -28
- package/package.json +1 -1
|
@@ -1,18 +1,92 @@
|
|
|
1
1
|
import { GaugeKind } from "../custom-metrics/index.js";
|
|
2
2
|
export interface CustomMetric<TLabel extends string = "default"> {
|
|
3
|
+
/**
|
|
4
|
+
* The name of the custom metric.
|
|
5
|
+
* This should be a descriptive name that identifies the metric.
|
|
6
|
+
* For example, "user_login_count" or "api_response_time".
|
|
7
|
+
*/
|
|
3
8
|
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The value of the custom metric.
|
|
11
|
+
* Starts with 0 and can be incremented or decremented based on the metric type.
|
|
12
|
+
* For example, if the metric is a counter for user logins, this value would
|
|
13
|
+
* represent the total number of user logins counted so far.
|
|
14
|
+
* If the metric is a gauge for memory usage, this value would represent the current memory
|
|
15
|
+
* usage in bytes or megabytes.
|
|
16
|
+
*/
|
|
4
17
|
value: Record<string, number>;
|
|
18
|
+
/**
|
|
19
|
+
* Description for the custom metric.
|
|
20
|
+
* This can be used to provide additional context about what the metric represents.
|
|
21
|
+
* For example, "Number of user logins in the last hour" or "Average response time for API requests".
|
|
22
|
+
*/
|
|
5
23
|
description?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The type of the custom metric.
|
|
26
|
+
* - "counter" is used for metrics that are incremented, such as the number of requests.
|
|
27
|
+
* - "gauge" is used for metrics that can go up and down, such as memory usage.
|
|
28
|
+
* - "summary" is used for distributions, such as request latency. Quantiles are
|
|
29
|
+
* computed in-process over each flush window, so raw observations never leave
|
|
30
|
+
* the agent.
|
|
31
|
+
*/
|
|
6
32
|
type: "counter" | "gauge" | "summary";
|
|
33
|
+
/**
|
|
34
|
+
* Optional labels for the custom metric.
|
|
35
|
+
* Labels are key-value pairs that can be used to add additional context to the metric.
|
|
36
|
+
* For example, you might use labels to indicate the environment (e.g., "production", "development") or the service (e.g., "user-service", "order-service").
|
|
37
|
+
*/
|
|
7
38
|
labels?: TLabel[];
|
|
39
|
+
/**
|
|
40
|
+
* Optional kind for gauge metrics.
|
|
41
|
+
* This can be "additive", "ratio", or "peak".
|
|
42
|
+
* - "additive": A gauge value will be summed up when multiple instances report values.
|
|
43
|
+
* - "ratio": A gauge value represents a ratio and should be averaged across instances.
|
|
44
|
+
* - "peak": A gauge value represents a peak measurement and the highest value should be reported.
|
|
45
|
+
*/
|
|
8
46
|
kind?: GaugeKind;
|
|
47
|
+
/**
|
|
48
|
+
* Optional tags for the custom metric.
|
|
49
|
+
* Tags are key-value pairs that can be used to add additional context to the metric.
|
|
50
|
+
* For example, you might use tags to indicate the environment (e.g., "production", "development") or the service (e.g., "user-service", "order-service").
|
|
51
|
+
*/
|
|
9
52
|
tags?: Record<string, string>;
|
|
53
|
+
/**
|
|
54
|
+
* Represents when the custom metric was recorded/updated.
|
|
55
|
+
* This is a Unix timestamp in milliseconds that indicates the time when the metric was last updated.
|
|
56
|
+
*/
|
|
10
57
|
lastUpdated?: number;
|
|
58
|
+
/**
|
|
59
|
+
* How much a counter rose since the previous flush, per label.
|
|
60
|
+
*
|
|
61
|
+
* `value` is cumulative for the life of the process, so summing it across
|
|
62
|
+
* reports double counts. This is the additive quantity: summing it over a
|
|
63
|
+
* window gives the real total, and it is unaffected by a process restarting
|
|
64
|
+
* and resetting `value` back to zero.
|
|
65
|
+
*
|
|
66
|
+
* Counters only - a gauge reading is absolute and has no meaningful increase.
|
|
67
|
+
*/
|
|
11
68
|
increase?: Record<string, number>;
|
|
69
|
+
/**
|
|
70
|
+
* Quantiles computed in-process over the observations since the last flush,
|
|
71
|
+
* per label. Summaries only.
|
|
72
|
+
*
|
|
73
|
+
* Because these arrive already computed, combining them across instances can
|
|
74
|
+
* only estimate the true percentile - the exactly-mergeable figures below are
|
|
75
|
+
* what to lean on when that matters.
|
|
76
|
+
*/
|
|
12
77
|
p50?: Record<string, number>;
|
|
13
78
|
p95?: Record<string, number>;
|
|
14
79
|
p99?: Record<string, number>;
|
|
80
|
+
/**
|
|
81
|
+
* Observation count and sum behind the quantiles, per label. Summaries only.
|
|
82
|
+
* Both merge exactly, so a mean derived from them holds across any number of
|
|
83
|
+
* reporters.
|
|
84
|
+
*/
|
|
15
85
|
observations?: Record<string, number>;
|
|
16
86
|
total?: Record<string, number>;
|
|
87
|
+
/**
|
|
88
|
+
* Largest single observation per label since the last flush. Summaries only.
|
|
89
|
+
* Merges exactly, so the worst case survives being combined.
|
|
90
|
+
*/
|
|
17
91
|
maximum?: Record<string, number>;
|
|
18
92
|
}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of `graphql`'s `GraphQLResolveInfo` this module reads.
|
|
3
|
+
*
|
|
4
|
+
* Declared structurally rather than imported: `@nestjs/graphql` and `graphql`
|
|
5
|
+
* are optional peers, and importing a type from them here would make every
|
|
6
|
+
* service that never touches GraphQL fail to compile without them installed.
|
|
7
|
+
* Anything the real `GraphQLResolveInfo` provides is assignable to this.
|
|
8
|
+
*
|
|
9
|
+
* The instance handed to the `graphql` options is synthesised from the incoming
|
|
10
|
+
* document rather than taken from a resolver - operations are measured whole,
|
|
11
|
+
* so there is no single field being resolved when they are called - but it
|
|
12
|
+
* carries the values a root field's real info carried.
|
|
13
|
+
*/
|
|
1
14
|
export interface GraphQLResolveInfoLike {
|
|
15
|
+
/** The field being resolved, e.g. `orders`. */
|
|
2
16
|
fieldName: string;
|
|
17
|
+
/** The type the field hangs off - `Query`, `Mutation` or `Subscription`. */
|
|
3
18
|
parentType: {
|
|
4
19
|
name: string;
|
|
5
20
|
};
|
|
21
|
+
/** The document's operation, when the request carried one. */
|
|
6
22
|
operation?: {
|
|
7
23
|
operation?: string;
|
|
8
24
|
name?: {
|
|
@@ -1,19 +1,89 @@
|
|
|
1
1
|
import { CompleteTraceEventNode, OngoingTraceEventNode } from "./trace-events.interfaces.js";
|
|
2
2
|
export interface JobSnapshot {
|
|
3
|
+
/**
|
|
4
|
+
* Unique identifier for the job.
|
|
5
|
+
* This is typically a UUID or a similar unique identifier.
|
|
6
|
+
*/
|
|
3
7
|
id: string;
|
|
8
|
+
/**
|
|
9
|
+
* Unique identifier for the trace associated
|
|
10
|
+
*/
|
|
4
11
|
traceId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Name of the job.
|
|
14
|
+
* This is a human-readable name that describes the job.
|
|
15
|
+
*/
|
|
5
16
|
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Name of the queue to which the job belongs.
|
|
19
|
+
* This is useful for categorizing jobs and understanding their context.
|
|
20
|
+
*/
|
|
6
21
|
queueName: string;
|
|
22
|
+
/**
|
|
23
|
+
* The status of the job.
|
|
24
|
+
*/
|
|
7
25
|
status?: "completed" | "failed";
|
|
26
|
+
/**
|
|
27
|
+
* Represents when the request was executed.
|
|
28
|
+
* This is a human-readable timestamp, typically in ISO 8601 format.
|
|
29
|
+
*/
|
|
8
30
|
calledAt?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Timestamp when the request started.
|
|
33
|
+
* This is a high-resolution timestamp, typically in milliseconds.
|
|
34
|
+
*/
|
|
9
35
|
startTimestamp?: number;
|
|
36
|
+
/**
|
|
37
|
+
* The duration of the job in milliseconds.
|
|
38
|
+
*
|
|
39
|
+
* This is processing time only - it starts when the worker picks the job up,
|
|
40
|
+
* so it says nothing about how long the job sat in the queue first. See
|
|
41
|
+
* `waitDuration` for that.
|
|
42
|
+
*/
|
|
10
43
|
duration?: number;
|
|
44
|
+
/**
|
|
45
|
+
* When the job was added to the queue, ISO 8601.
|
|
46
|
+
*/
|
|
11
47
|
enqueuedAt?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Milliseconds the job spent waiting in the queue before a worker started it,
|
|
50
|
+
* measured from the moment it became runnable rather than from when it was
|
|
51
|
+
* created - any `delay` the caller asked for is excluded.
|
|
52
|
+
*
|
|
53
|
+
* This is the number that reveals a backlog: a job that waited four minutes
|
|
54
|
+
* and then ran in 10ms is indistinguishable from a healthy one on `duration`
|
|
55
|
+
* alone.
|
|
56
|
+
*/
|
|
12
57
|
waitDuration?: number;
|
|
58
|
+
/**
|
|
59
|
+
* How many attempts had already been made when this run started - 0 on the
|
|
60
|
+
* first attempt. A job that only succeeded on its fifth try is otherwise
|
|
61
|
+
* indistinguishable from one that succeeded immediately.
|
|
62
|
+
*/
|
|
13
63
|
attemptsMade?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Maximum attempts configured for the job, so a consumer can tell "retried
|
|
66
|
+
* once of three" from "final attempt failed".
|
|
67
|
+
*/
|
|
14
68
|
maxAttempts?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Array of trace events associated with the job.
|
|
71
|
+
* This array contains both ongoing and complete trace events.
|
|
72
|
+
* Ongoing events are those that have started but not yet ended.
|
|
73
|
+
*/
|
|
15
74
|
traces: Array<OngoingTraceEventNode | CompleteTraceEventNode>;
|
|
75
|
+
/**
|
|
76
|
+
* Tags associated with the jobs.
|
|
77
|
+
* Tags are key-value pairs that provide additional context about the jobs.
|
|
78
|
+
* This field is optional and can be used to capture additional metadata about the job.
|
|
79
|
+
* @example { 'environment': 'production', 'version': '1.0.0' }
|
|
80
|
+
* @default {}
|
|
81
|
+
*/
|
|
16
82
|
tags?: Record<string, string | number | boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Indicates whether an error occurred during the operation represented by the trace span.
|
|
85
|
+
* If undefined, it means no error occurred.
|
|
86
|
+
*/
|
|
17
87
|
error?: {
|
|
18
88
|
cls?: string;
|
|
19
89
|
message: string;
|
|
@@ -15,6 +15,11 @@ export interface NodeRuntimeMetrics {
|
|
|
15
15
|
gc: {
|
|
16
16
|
count: number;
|
|
17
17
|
totalDuration: number;
|
|
18
|
+
/**
|
|
19
|
+
* Per-kind counts for the window. Every member is optional because the
|
|
20
|
+
* section is reported on every sample, and a window in which nothing was
|
|
21
|
+
* collected reports it empty rather than omitting it.
|
|
22
|
+
*/
|
|
18
23
|
breakdown?: {
|
|
19
24
|
minor?: {
|
|
20
25
|
count: number;
|
|
@@ -2,77 +2,425 @@ import { FactoryProvider, ModuleMetadata, Provider, Type } from "@nestjs/common"
|
|
|
2
2
|
import { BaseRpcContext, Transport } from "@nestjs/microservices";
|
|
3
3
|
import { GraphQLResolveInfoLike } from "./graphql.interfaces.js";
|
|
4
4
|
export interface RedactionOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to scrub log lines at all.
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
5
9
|
enabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Extra patterns to mask, for credentials shaped in a way only your codebase
|
|
12
|
+
* knows about - internal token prefixes, customer identifiers, and so on.
|
|
13
|
+
*
|
|
14
|
+
* Patterns are applied with the global flag whether or not you set it, so a
|
|
15
|
+
* pattern cannot silently mask just the first occurrence in a line.
|
|
16
|
+
*/
|
|
6
17
|
patterns?: RegExp[];
|
|
18
|
+
/**
|
|
19
|
+
* Extra attribute keys whose values are masked outright, on top of the
|
|
20
|
+
* built-in list. Compared case-insensitively, ignoring `-` and `_`, so
|
|
21
|
+
* "apiKey", "api_key" and "API-KEY" are one entry.
|
|
22
|
+
*/
|
|
7
23
|
keys?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Text substituted for anything redacted.
|
|
26
|
+
* @default '[REDACTED]'
|
|
27
|
+
*/
|
|
8
28
|
replacement?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to apply the built-in patterns - bearer tokens, JWTs, AWS key ids,
|
|
31
|
+
* PEM private keys, `key=value` secrets and Luhn-valid card numbers.
|
|
32
|
+
*
|
|
33
|
+
* Disable only if you are replacing them wholesale with `patterns`; there is
|
|
34
|
+
* no supported configuration in which forwarding logs unredacted is a good
|
|
35
|
+
* idea, and this switch exists for tuning, not for opting out.
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
9
38
|
useDefaultPatterns?: boolean;
|
|
10
39
|
}
|
|
11
40
|
export interface CreateObserveModuleOptions {
|
|
41
|
+
/**
|
|
42
|
+
* The trace ID key used to identify the trace in the context.
|
|
43
|
+
* This key is used to store the trace ID in the context for later retrieval.
|
|
44
|
+
* If not provided, the default key 'traceId' will be used.
|
|
45
|
+
* @default 'traceId'
|
|
46
|
+
*/
|
|
12
47
|
traceIdKey?: string;
|
|
48
|
+
/**
|
|
49
|
+
* A function to generate a trace ID for each request.
|
|
50
|
+
* This function should return a unique string that will be used as the trace ID.
|
|
51
|
+
* If not provided, a default trace ID generator will be used.
|
|
52
|
+
* For HTTP protocols, the request object is passed to the function.
|
|
53
|
+
* For non-HTTP protocols, the request object will be contextual and may not be available.
|
|
54
|
+
* The default implementation uses the 'x-request-id' header if available,
|
|
55
|
+
* or generates a random UUID if the header is not present.
|
|
56
|
+
* @default (req) => req.headers['x-request-id'] || randomUUID()
|
|
57
|
+
*/
|
|
13
58
|
traceIdGenerator?: (req: unknown) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Whether to augment the ConsoleLogger to include the trace ID in log messages.
|
|
61
|
+
* If true, the trace ID will be included in the log messages by default.
|
|
62
|
+
* This is useful for correlating logs with traces.
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
14
65
|
attachTraceIdToLogs?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Attaches the source around each in-app stack frame to captured errors, so the
|
|
68
|
+
* throw site can be shown with its code rather than just a file and line.
|
|
69
|
+
*
|
|
70
|
+
* Only the machine running the code can read its own files, which is why this is
|
|
71
|
+
* captured here rather than resolved server-side.
|
|
72
|
+
*
|
|
73
|
+
* Note that enabling this ships fragments of your source to the Observe server,
|
|
74
|
+
* where they are stored alongside the error. Frames inside `node_modules` and
|
|
75
|
+
* Node internals are never read, but application source is - turn this off if
|
|
76
|
+
* that is not acceptable for your codebase.
|
|
77
|
+
*
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
15
80
|
sourceContext?: boolean | {
|
|
81
|
+
/**
|
|
82
|
+
* Lines to read either side of the frame's line.
|
|
83
|
+
* @default 5
|
|
84
|
+
*/
|
|
16
85
|
linesOfContext?: number;
|
|
86
|
+
/**
|
|
87
|
+
* How many in-app frames to attach source for, counted from the top of
|
|
88
|
+
* the stack. Bounds the payload on deep stacks.
|
|
89
|
+
* @default 5
|
|
90
|
+
*/
|
|
17
91
|
maxFrames?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Resolves compiled frames back through source maps before reading source.
|
|
94
|
+
*
|
|
95
|
+
* Only needed when the process runs compiled output without Node's own
|
|
96
|
+
* source map support - without it, frames point at `dist/*.js` and the
|
|
97
|
+
* captured source would be compiled JavaScript. With Node started under
|
|
98
|
+
* `--enable-source-maps` (or `process.setSourceMapsEnabled(true)`) stack
|
|
99
|
+
* frames already carry original positions and this is redundant work.
|
|
100
|
+
*
|
|
101
|
+
* Costs a map parse per compiled file on first touch, cached thereafter.
|
|
102
|
+
*
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
18
105
|
sourceMaps?: boolean;
|
|
19
106
|
};
|
|
20
107
|
}
|
|
21
108
|
export interface ObserveOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Application key identifying this service to the collector.
|
|
111
|
+
*
|
|
112
|
+
* Sign up at https://observe.nestjs.com and create a service; the dashboard
|
|
113
|
+
* issues the key and secret together.
|
|
114
|
+
*
|
|
115
|
+
* Sent as `x-api-key` on every ingest request, alongside `appSecret`.
|
|
116
|
+
* Without valid credentials the collector answers 401 and the batch is
|
|
117
|
+
* dropped.
|
|
118
|
+
*/
|
|
22
119
|
appKey: string;
|
|
120
|
+
/**
|
|
121
|
+
* Secret paired with `appKey`, issued with it at https://observe.nestjs.com.
|
|
122
|
+
*
|
|
123
|
+
* Sent as `x-api-secret`. Shown once when the key is issued and not
|
|
124
|
+
* retrievable afterwards, so treat it as you would a password: supply it from
|
|
125
|
+
* the environment rather than committing it alongside the rest of this config.
|
|
126
|
+
* If it is lost, issue a new pair from the dashboard.
|
|
127
|
+
*/
|
|
23
128
|
appSecret: string;
|
|
129
|
+
/**
|
|
130
|
+
* Base URL of the collector, without a trailing path.
|
|
131
|
+
*
|
|
132
|
+
* One setting for telemetry and profiles both, so the two can never point at
|
|
133
|
+
* different places. Defaults to the hosted collector; set `OBSERVE_ENDPOINT`
|
|
134
|
+
* in the environment to override that without touching this config, which is
|
|
135
|
+
* how a self-hosted or local collector is usually pointed at.
|
|
136
|
+
*
|
|
137
|
+
* @default 'https://observe-api.nestjs.com'
|
|
138
|
+
*/
|
|
24
139
|
endpoint?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Unique identifier for the service.
|
|
142
|
+
* If you anticipate running multiple instances of the same service,
|
|
143
|
+
* consider using a unique identifier such as a hostname or container ID.
|
|
144
|
+
* This helps in distinguishing between different instances of the service in the APM.
|
|
145
|
+
*/
|
|
25
146
|
serviceId: string;
|
|
147
|
+
/**
|
|
148
|
+
* Version of the service.
|
|
149
|
+
* This can be used to track changes in the service over time.
|
|
150
|
+
* It is optional and can be used to differentiate between different versions of the service.
|
|
151
|
+
* For example, it could be a semantic version like "1.0.0"
|
|
152
|
+
* or a commit hash like "abc123".
|
|
153
|
+
*/
|
|
26
154
|
serviceVersion?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Interval in milliseconds at which the tracer submits traces to the Agent.
|
|
157
|
+
* The default value is 5000 milliseconds (5 seconds).
|
|
158
|
+
* @default 5000
|
|
159
|
+
*/
|
|
27
160
|
flushInterval?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Whether to collect runtime metrics: memory, CPU load, GC and event loop
|
|
163
|
+
* latency, sampled on an interval and drawn as gauges.
|
|
164
|
+
*
|
|
165
|
+
* Answers *whether* a process was struggling. `profiling` below answers
|
|
166
|
+
* *which code* it was running - a different signal with a different cost.
|
|
167
|
+
* @default true
|
|
168
|
+
*/
|
|
28
169
|
runtimeMetrics?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Interval in milliseconds at which runtime metrics are collected and sent to
|
|
172
|
+
* the Agent. Only applicable when `runtimeMetrics` is enabled.
|
|
173
|
+
* @default 60000
|
|
174
|
+
*/
|
|
29
175
|
runtimeMetricsInterval?: number;
|
|
176
|
+
/**
|
|
177
|
+
* Continuous profiling: a sampling CPU profiler whose stacks are tagged with
|
|
178
|
+
* the span that was executing, so a slow span can be opened as a flame graph.
|
|
179
|
+
*
|
|
180
|
+
* SHELVED - setting this currently does nothing. The agent does not start the
|
|
181
|
+
* sampler and the collector's /profiles endpoints are unregistered. Kept,
|
|
182
|
+
* along with its implementation and tests, for a later return.
|
|
183
|
+
*
|
|
184
|
+
* Off unless a block is supplied, and off by default inside it. Profiling
|
|
185
|
+
* samples on the profiled thread - V8 profiles the isolate the session is
|
|
186
|
+
* attached to, so it cannot be moved onto the agent's worker - and no agent
|
|
187
|
+
* should start doing that to a customer's process because they upgraded.
|
|
188
|
+
*
|
|
189
|
+
* Built on `node:inspector` rather than a native profiler: a native addon
|
|
190
|
+
* would land in the install of every service using this agent, including the
|
|
191
|
+
* overwhelming majority that never switch this on.
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* The sample rate for traces, which determines the percentage of traces that are sent to the Agent.
|
|
195
|
+
* A value of 1.0 means all traces are sent, while a value of 0.1 means 10% of traces are sent.
|
|
196
|
+
* @default 1.0
|
|
197
|
+
*/
|
|
30
198
|
tracesSampleRate?: number | ((protocal: "http" | "rpc" | "grpc" | "graphql", attributes: any) => boolean);
|
|
199
|
+
/**
|
|
200
|
+
* Maximum number of traces per batch that can be sent to the Agent.
|
|
201
|
+
* This is useful for controlling the volume of traces sent, especially in high-traffic applications.
|
|
202
|
+
* @default 1000
|
|
203
|
+
*/
|
|
31
204
|
maxTracesPerBatch?: number;
|
|
205
|
+
/**
|
|
206
|
+
* Whether to forward logs to the Observe APM.
|
|
207
|
+
* If true, logs will be forwarded to the Agent for correlation with traces.
|
|
208
|
+
* @default false
|
|
209
|
+
*/
|
|
32
210
|
forwardLogs?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* How log lines are scrubbed before leaving the process.
|
|
213
|
+
*
|
|
214
|
+
* Redaction is on by default whenever `forwardLogs` is enabled - forwarding
|
|
215
|
+
* logs moves them onto someone else's disk, and secrets reach logs by accident
|
|
216
|
+
* far more often than by design, so the safe behaviour is the one you get
|
|
217
|
+
* without asking. Set `enabled: false` to turn it off deliberately.
|
|
218
|
+
*/
|
|
33
219
|
redaction?: RedactionOptions;
|
|
220
|
+
/**
|
|
221
|
+
* Whether to enable debug mode for the Observe APM.
|
|
222
|
+
* If true, additional debug information will be logged to the console.
|
|
223
|
+
* This is useful for development and troubleshooting purposes.
|
|
224
|
+
* @default false
|
|
225
|
+
*/
|
|
34
226
|
debug?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* HTTP configuration options for the Observe APM.
|
|
229
|
+
*/
|
|
35
230
|
http?: {
|
|
231
|
+
/**
|
|
232
|
+
* A list of HTTP endpoints to ignore for tracing.
|
|
233
|
+
*/
|
|
36
234
|
ignore?: Array<string | {
|
|
37
235
|
method: string;
|
|
38
236
|
path: string | RegExp;
|
|
39
237
|
} | RegExp> | ((req: any) => boolean);
|
|
238
|
+
/**
|
|
239
|
+
* Tags to be added to all HTTP requests.
|
|
240
|
+
* These tags can be used to provide additional context for the requests.
|
|
241
|
+
* @example { 'environment': 'production', 'version': '1.0.0' }
|
|
242
|
+
* @default {}
|
|
243
|
+
*/
|
|
40
244
|
tags?: Record<string, string>;
|
|
245
|
+
/**
|
|
246
|
+
* A function to generate additional attributes for HTTP requests.
|
|
247
|
+
* This function receives the request object and should return an object containing key-value pairs.
|
|
248
|
+
* These attributes can be retrieved later within the trace.
|
|
249
|
+
* @example (req) => ({ 'user-agent': req.headers['user-agent'], 'client-ip': req.ip })
|
|
250
|
+
* @default (req) => ({})
|
|
251
|
+
*/
|
|
41
252
|
setAttributes?: (req: any) => {
|
|
42
253
|
[key: string]: string | number | boolean;
|
|
43
254
|
};
|
|
255
|
+
/**
|
|
256
|
+
* A regular expression to obfuscate query parameters in HTTP requests.
|
|
257
|
+
* This is useful for masking sensitive information in query strings.
|
|
258
|
+
*
|
|
259
|
+
* Applied *in addition to* the built-in redaction, which always masks the
|
|
260
|
+
* values of well-known sensitive parameters (`token`, `password`, `code`,
|
|
261
|
+
* `signature`, ...) whether or not this is set. Use it for the parameters
|
|
262
|
+
* only your application knows are sensitive.
|
|
263
|
+
* @default undefined
|
|
264
|
+
*/
|
|
44
265
|
queryParamsObfuscateRegex?: RegExp;
|
|
266
|
+
/**
|
|
267
|
+
* A function to associate a user identifier with the HTTP request.
|
|
268
|
+
* This function receives the request object and should return a string representing the user ID.
|
|
269
|
+
* If not provided, no user ID will be associated with the request.
|
|
270
|
+
* @example (req) => req.user?.id || 'anonymous'
|
|
271
|
+
* @default undefined
|
|
272
|
+
*/
|
|
45
273
|
getUserId?: (req: any) => string;
|
|
46
274
|
};
|
|
275
|
+
/**
|
|
276
|
+
* RPC configuration options for the Observe APM.
|
|
277
|
+
*/
|
|
47
278
|
rpc?: {
|
|
279
|
+
/**
|
|
280
|
+
* A function that determines whether to ignore a given RPC request.
|
|
281
|
+
* This function receives the request context and should return true if the request should be ignored.
|
|
282
|
+
*/
|
|
48
283
|
ignore?: (transportId: Transport | symbol, ctx: BaseRpcContext) => boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Tags to be added to all RPC requests.
|
|
286
|
+
* These tags can be used to provide additional context for the requests.
|
|
287
|
+
* @example { 'environment': 'production', 'version': '1.0.0' }
|
|
288
|
+
* @default {}
|
|
289
|
+
*/
|
|
49
290
|
tags?: Record<string, string>;
|
|
291
|
+
/**
|
|
292
|
+
* A function to generate additional attributes for RPC requests.
|
|
293
|
+
* This function receives the request context and should return an object containing key-value pairs.
|
|
294
|
+
* These attributes can be retrieved later within the trace.
|
|
295
|
+
* @example (ctx) => ({ 'service': ctx.getService(), 'method': ctx.getMethod() })
|
|
296
|
+
* @default (ctx) => ({})
|
|
297
|
+
*/
|
|
50
298
|
setAttributes?: (transportId: Transport | symbol, ctx: BaseRpcContext) => {
|
|
51
299
|
[key: string]: string | number | boolean;
|
|
52
300
|
};
|
|
301
|
+
/**
|
|
302
|
+
* A function to associate a user identifier with the HTTP request.
|
|
303
|
+
* This function receives the request object and should return a string representing the user ID.
|
|
304
|
+
* If not provided, no user ID will be associated with the request.
|
|
305
|
+
* @example (transportId, ctx) => ctx.getMetadata().userId || 'anonymous'
|
|
306
|
+
* @default undefined
|
|
307
|
+
*/
|
|
53
308
|
getUserId?: (transportId: Transport | symbol, ctx: BaseRpcContext) => string;
|
|
54
309
|
};
|
|
310
|
+
/**
|
|
311
|
+
* GraphQL configuration options for the Observe APM.
|
|
312
|
+
*
|
|
313
|
+
* A GraphQL server is usually an HTTP endpoint, so its requests are already
|
|
314
|
+
* subject to the `http` options above - `http.ignore` drops the request
|
|
315
|
+
* before the GraphQL layer sees it. These options tune what happens *inside*
|
|
316
|
+
* a request that was let through: which operations get a span, and what that
|
|
317
|
+
* span's trace is labelled with.
|
|
318
|
+
*
|
|
319
|
+
* The unit here is one GraphQL operation, not one resolver. Every hook below
|
|
320
|
+
* is called once per operation, with an info object describing it: the
|
|
321
|
+
* operation type as `parentType.name`, and the document's first root field as
|
|
322
|
+
* `fieldName` - the same pair the operation id is built from.
|
|
323
|
+
*/
|
|
55
324
|
graphql?: {
|
|
325
|
+
/**
|
|
326
|
+
* A function that determines whether to skip tracing a given operation.
|
|
327
|
+
* Receives the GraphQL resolve info, so it can match on the operation type
|
|
328
|
+
* ("Query", "Mutation", "Subscription") and the field name.
|
|
329
|
+
*
|
|
330
|
+
* Matching on a field name skips the whole operation the field leads, not
|
|
331
|
+
* just that field: an operation is measured end to end, so it is traced or
|
|
332
|
+
* it is not.
|
|
333
|
+
* @example (info) => info.fieldName === 'healthcheck'
|
|
334
|
+
*/
|
|
56
335
|
ignore?: (info: GraphQLResolveInfoLike) => boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Tags to be added to traces started by, or labelled from, a GraphQL
|
|
338
|
+
* operation.
|
|
339
|
+
* @example { 'environment': 'production', 'version': '1.0.0' }
|
|
340
|
+
* @default {}
|
|
341
|
+
*/
|
|
57
342
|
tags?: Record<string, string>;
|
|
343
|
+
/**
|
|
344
|
+
* A function to generate additional attributes for GraphQL operations.
|
|
345
|
+
* Receives the resolve info and the GraphQL context, and should return an
|
|
346
|
+
* object containing key-value pairs. These attributes can be retrieved
|
|
347
|
+
* later within the trace. Called once, before the operation is processed.
|
|
348
|
+
* @example (info) => ({ 'operation': info.operation?.operation })
|
|
349
|
+
* @default undefined
|
|
350
|
+
*/
|
|
58
351
|
setAttributes?: (info: GraphQLResolveInfoLike, context: any) => {
|
|
59
352
|
[key: string]: string | number | boolean;
|
|
60
353
|
};
|
|
354
|
+
/**
|
|
355
|
+
* A function to associate a user identifier with the operation.
|
|
356
|
+
*
|
|
357
|
+
* Only consulted for operations that are *not* already inside an HTTP
|
|
358
|
+
* trace - a query over HTTP takes its user id from `http.getUserId`, which
|
|
359
|
+
* sees the whole request. This covers the transports that have no such
|
|
360
|
+
* hook, subscriptions over a websocket in particular.
|
|
361
|
+
* @example (context) => context.req?.user?.id
|
|
362
|
+
* @default undefined
|
|
363
|
+
*/
|
|
61
364
|
getUserId?: (context: any) => string;
|
|
62
365
|
};
|
|
366
|
+
/**
|
|
367
|
+
* gRPC configuration options for the Observe APM.
|
|
368
|
+
* This is used to configure the gRPC protocol tracing.
|
|
369
|
+
*/
|
|
63
370
|
grpc?: {
|
|
371
|
+
/**
|
|
372
|
+
* A function that determines whether to ignore a given gRPC request.
|
|
373
|
+
* This function receives the gRPC call object and should return true if the request should be ignored.
|
|
374
|
+
*/
|
|
64
375
|
ignore?: (call: any) => boolean;
|
|
376
|
+
/**
|
|
377
|
+
* Tags to be added to all gRPC requests.
|
|
378
|
+
* These tags can be used to provide additional context for the requests.
|
|
379
|
+
* @example { 'environment': 'production', 'version': '1.0.0' }
|
|
380
|
+
* @default {}
|
|
381
|
+
*/
|
|
65
382
|
tags?: Record<string, string>;
|
|
383
|
+
/**
|
|
384
|
+
* A function to generate additional attributes for gRPC requests.
|
|
385
|
+
* This function receives the gRPC call object and should return an object containing key-value pairs.
|
|
386
|
+
* These attributes can be retrieved later within the trace.
|
|
387
|
+
* @example (call) => ({ 'service': call.service, 'method': call.method })
|
|
388
|
+
* @default (call) => ({})
|
|
389
|
+
* */
|
|
66
390
|
setAttributes?: (call: any) => {
|
|
67
391
|
[key: string]: string | number | boolean;
|
|
68
392
|
};
|
|
393
|
+
/**
|
|
394
|
+
* A function to associate a user identifier with the HTTP request.
|
|
395
|
+
* This function receives the request object and should return a string representing the user ID.
|
|
396
|
+
* If not provided, no user ID will be associated with the request.
|
|
397
|
+
* @example (call) => call.metadata.userId || 'anonymous'
|
|
398
|
+
* @default undefined
|
|
399
|
+
*/
|
|
69
400
|
getUserId?: (call: any) => string;
|
|
70
401
|
};
|
|
402
|
+
/**
|
|
403
|
+
* Jobs configuration options for the Observe APM.
|
|
404
|
+
*/
|
|
71
405
|
jobs?: {
|
|
406
|
+
/**
|
|
407
|
+
* Tags to be added to all job requests.
|
|
408
|
+
* These tags can be used to provide additional context for the requests.
|
|
409
|
+
* @example { 'environment': 'production', 'version': '1.0.0' }
|
|
410
|
+
* @default {}
|
|
411
|
+
*/
|
|
72
412
|
tags?: Record<string, string>;
|
|
413
|
+
/**
|
|
414
|
+
* A function to generate additional attributes for job processing.
|
|
415
|
+
* This function receives the job object and should return an object containing key-value pairs.
|
|
416
|
+
* These attributes can be retrieved later within the trace.
|
|
417
|
+
* @example (job) => ({ 'queueName': job.queueName, 'jobName': job.name })
|
|
418
|
+
* @default (job) => ({})
|
|
419
|
+
*/
|
|
73
420
|
setAttributes?: (job: {
|
|
74
421
|
queueName: string;
|
|
75
422
|
name: string;
|
|
423
|
+
/** Absent until the queue driver has assigned one. */
|
|
76
424
|
id: string | undefined;
|
|
77
425
|
}) => {
|
|
78
426
|
[key: string]: string | number | boolean;
|
|
@@ -80,6 +428,10 @@ export interface ObserveOptions {
|
|
|
80
428
|
};
|
|
81
429
|
}
|
|
82
430
|
export type ObserveModuleOptionsWithDefaults = Required<CreateObserveModuleOptions> & ObserveOptions;
|
|
431
|
+
/**
|
|
432
|
+
* Implemented by the class passed to `ObserveModule.forRootAsync()` as
|
|
433
|
+
* `useClass` or `useExisting`.
|
|
434
|
+
*/
|
|
83
435
|
export interface ObserveOptionsFactory {
|
|
84
436
|
createObserveOptions(): Promise<ObserveOptions> | ObserveOptions;
|
|
85
437
|
}
|
|
@@ -88,6 +440,12 @@ export interface ObserveModuleAsyncOptions extends Pick<ModuleMetadata, "imports
|
|
|
88
440
|
useClass?: Type<ObserveOptionsFactory>;
|
|
89
441
|
useFactory?: (...args: any[]) => Promise<ObserveOptions> | ObserveOptions;
|
|
90
442
|
inject?: FactoryProvider["inject"];
|
|
443
|
+
/**
|
|
444
|
+
* Extra providers to be registered
|
|
445
|
+
*/
|
|
91
446
|
extraProviders?: Provider[];
|
|
447
|
+
/**
|
|
448
|
+
* Set to true to register ObserveModule as a global module
|
|
449
|
+
*/
|
|
92
450
|
global?: boolean;
|
|
93
451
|
}
|