@watchtowerobservability/node 0.0.0-stage → 0.3.0
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/LICENSE +202 -0
- package/README.md +304 -2
- package/dist/cjs/appsec.d.ts +95 -0
- package/dist/cjs/appsec.js +206 -0
- package/dist/cjs/buffer.d.ts +49 -0
- package/dist/cjs/buffer.js +134 -0
- package/dist/cjs/errors.d.ts +17 -0
- package/dist/cjs/errors.js +55 -0
- package/dist/cjs/index.d.ts +123 -0
- package/dist/cjs/index.js +315 -0
- package/dist/cjs/integrations/amqp.d.ts +13 -0
- package/dist/cjs/integrations/amqp.js +96 -0
- package/dist/cjs/integrations/azure-functions.d.ts +18 -0
- package/dist/cjs/integrations/azure-functions.js +97 -0
- package/dist/cjs/integrations/bullmq.d.ts +19 -0
- package/dist/cjs/integrations/bullmq.js +83 -0
- package/dist/cjs/integrations/cache.d.ts +13 -0
- package/dist/cjs/integrations/cache.js +51 -0
- package/dist/cjs/integrations/db.d.ts +62 -0
- package/dist/cjs/integrations/db.js +288 -0
- package/dist/cjs/integrations/duckdb.d.ts +22 -0
- package/dist/cjs/integrations/duckdb.js +66 -0
- package/dist/cjs/integrations/express.d.ts +25 -0
- package/dist/cjs/integrations/express.js +58 -0
- package/dist/cjs/integrations/fastify.d.ts +6 -0
- package/dist/cjs/integrations/fastify.js +44 -0
- package/dist/cjs/integrations/genai-agents.d.ts +36 -0
- package/dist/cjs/integrations/genai-agents.js +124 -0
- package/dist/cjs/integrations/genai-stream.d.ts +19 -0
- package/dist/cjs/integrations/genai-stream.js +135 -0
- package/dist/cjs/integrations/genai.d.ts +18 -0
- package/dist/cjs/integrations/genai.js +150 -0
- package/dist/cjs/integrations/graphile-worker.d.ts +22 -0
- package/dist/cjs/integrations/graphile-worker.js +50 -0
- package/dist/cjs/integrations/koa.d.ts +19 -0
- package/dist/cjs/integrations/koa.js +34 -0
- package/dist/cjs/integrations/lambda.d.ts +11 -0
- package/dist/cjs/integrations/lambda.js +68 -0
- package/dist/cjs/integrations/level.d.ts +18 -0
- package/dist/cjs/integrations/level.js +71 -0
- package/dist/cjs/integrations/lmdb.d.ts +26 -0
- package/dist/cjs/integrations/lmdb.js +78 -0
- package/dist/cjs/integrations/logs.d.ts +10 -0
- package/dist/cjs/integrations/logs.js +77 -0
- package/dist/cjs/integrations/messaging.d.ts +17 -0
- package/dist/cjs/integrations/messaging.js +73 -0
- package/dist/cjs/integrations/mqtt.d.ts +7 -0
- package/dist/cjs/integrations/mqtt.js +41 -0
- package/dist/cjs/integrations/nats.d.ts +17 -0
- package/dist/cjs/integrations/nats.js +73 -0
- package/dist/cjs/integrations/nestjs.d.ts +16 -0
- package/dist/cjs/integrations/nestjs.js +30 -0
- package/dist/cjs/integrations/next.d.ts +11 -0
- package/dist/cjs/integrations/next.js +59 -0
- package/dist/cjs/integrations/orm.d.ts +47 -0
- package/dist/cjs/integrations/orm.js +93 -0
- package/dist/cjs/integrations/pg-boss.d.ts +8 -0
- package/dist/cjs/integrations/pg-boss.js +63 -0
- package/dist/cjs/integrations/pools.d.ts +41 -0
- package/dist/cjs/integrations/pools.js +94 -0
- package/dist/cjs/integrations/postgres.d.ts +12 -0
- package/dist/cjs/integrations/postgres.js +92 -0
- package/dist/cjs/integrations/prisma.d.ts +3 -0
- package/dist/cjs/integrations/prisma.js +33 -0
- package/dist/cjs/integrations/sqlite.d.ts +36 -0
- package/dist/cjs/integrations/sqlite.js +125 -0
- package/dist/cjs/integrations/util.d.ts +9 -0
- package/dist/cjs/integrations/util.js +37 -0
- package/dist/cjs/jest.d.ts +21 -0
- package/dist/cjs/jest.js +45 -0
- package/dist/cjs/load.d.ts +1 -0
- package/dist/cjs/load.js +11 -0
- package/dist/cjs/metrics.d.ts +10 -0
- package/dist/cjs/metrics.js +81 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/payload.d.ts +42 -0
- package/dist/cjs/payload.js +145 -0
- package/dist/cjs/pprof.d.ts +6 -0
- package/dist/cjs/pprof.js +88 -0
- package/dist/cjs/probes.d.ts +97 -0
- package/dist/cjs/probes.js +422 -0
- package/dist/cjs/profiling.d.ts +84 -0
- package/dist/cjs/profiling.js +263 -0
- package/dist/cjs/reporter-core.d.ts +32 -0
- package/dist/cjs/reporter-core.js +102 -0
- package/dist/cjs/sql.d.ts +19 -0
- package/dist/cjs/sql.js +332 -0
- package/dist/cjs/test-plan.d.ts +102 -0
- package/dist/cjs/test-plan.js +352 -0
- package/dist/cjs/vitest.d.ts +27 -0
- package/dist/cjs/vitest.js +52 -0
- package/dist/esm/appsec.d.ts +95 -0
- package/dist/esm/appsec.js +193 -0
- package/dist/esm/buffer.d.ts +49 -0
- package/dist/esm/buffer.js +92 -0
- package/dist/esm/errors.d.ts +17 -0
- package/dist/esm/errors.js +50 -0
- package/dist/esm/index.d.ts +123 -0
- package/dist/esm/index.js +264 -0
- package/dist/esm/integrations/amqp.d.ts +13 -0
- package/dist/esm/integrations/amqp.js +92 -0
- package/dist/esm/integrations/azure-functions.d.ts +18 -0
- package/dist/esm/integrations/azure-functions.js +60 -0
- package/dist/esm/integrations/bullmq.d.ts +19 -0
- package/dist/esm/integrations/bullmq.js +79 -0
- package/dist/esm/integrations/cache.d.ts +13 -0
- package/dist/esm/integrations/cache.js +46 -0
- package/dist/esm/integrations/db.d.ts +62 -0
- package/dist/esm/integrations/db.js +239 -0
- package/dist/esm/integrations/duckdb.d.ts +22 -0
- package/dist/esm/integrations/duckdb.js +29 -0
- package/dist/esm/integrations/express.d.ts +25 -0
- package/dist/esm/integrations/express.js +54 -0
- package/dist/esm/integrations/fastify.d.ts +6 -0
- package/dist/esm/integrations/fastify.js +41 -0
- package/dist/esm/integrations/genai-agents.d.ts +36 -0
- package/dist/esm/integrations/genai-agents.js +118 -0
- package/dist/esm/integrations/genai-stream.d.ts +19 -0
- package/dist/esm/integrations/genai-stream.js +130 -0
- package/dist/esm/integrations/genai.d.ts +18 -0
- package/dist/esm/integrations/genai.js +138 -0
- package/dist/esm/integrations/graphile-worker.d.ts +22 -0
- package/dist/esm/integrations/graphile-worker.js +46 -0
- package/dist/esm/integrations/koa.d.ts +19 -0
- package/dist/esm/integrations/koa.js +31 -0
- package/dist/esm/integrations/lambda.d.ts +11 -0
- package/dist/esm/integrations/lambda.js +32 -0
- package/dist/esm/integrations/level.d.ts +18 -0
- package/dist/esm/integrations/level.js +35 -0
- package/dist/esm/integrations/lmdb.d.ts +26 -0
- package/dist/esm/integrations/lmdb.js +42 -0
- package/dist/esm/integrations/logs.d.ts +10 -0
- package/dist/esm/integrations/logs.js +40 -0
- package/dist/esm/integrations/messaging.d.ts +17 -0
- package/dist/esm/integrations/messaging.js +64 -0
- package/dist/esm/integrations/mqtt.d.ts +7 -0
- package/dist/esm/integrations/mqtt.js +38 -0
- package/dist/esm/integrations/nats.d.ts +17 -0
- package/dist/esm/integrations/nats.js +70 -0
- package/dist/esm/integrations/nestjs.d.ts +16 -0
- package/dist/esm/integrations/nestjs.js +26 -0
- package/dist/esm/integrations/next.d.ts +11 -0
- package/dist/esm/integrations/next.js +22 -0
- package/dist/esm/integrations/orm.d.ts +47 -0
- package/dist/esm/integrations/orm.js +86 -0
- package/dist/esm/integrations/pg-boss.d.ts +8 -0
- package/dist/esm/integrations/pg-boss.js +60 -0
- package/dist/esm/integrations/pools.d.ts +41 -0
- package/dist/esm/integrations/pools.js +89 -0
- package/dist/esm/integrations/postgres.d.ts +12 -0
- package/dist/esm/integrations/postgres.js +55 -0
- package/dist/esm/integrations/prisma.d.ts +3 -0
- package/dist/esm/integrations/prisma.js +30 -0
- package/dist/esm/integrations/sqlite.d.ts +36 -0
- package/dist/esm/integrations/sqlite.js +84 -0
- package/dist/esm/integrations/util.d.ts +9 -0
- package/dist/esm/integrations/util.js +32 -0
- package/dist/esm/jest.d.ts +21 -0
- package/dist/esm/jest.js +41 -0
- package/dist/esm/load.d.ts +1 -0
- package/dist/esm/load.js +5 -0
- package/dist/esm/metrics.d.ts +10 -0
- package/dist/esm/metrics.js +44 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/payload.d.ts +42 -0
- package/dist/esm/payload.js +131 -0
- package/dist/esm/pprof.d.ts +6 -0
- package/dist/esm/pprof.js +85 -0
- package/dist/esm/probes.d.ts +97 -0
- package/dist/esm/probes.js +412 -0
- package/dist/esm/profiling.d.ts +84 -0
- package/dist/esm/profiling.js +251 -0
- package/dist/esm/reporter-core.d.ts +32 -0
- package/dist/esm/reporter-core.js +63 -0
- package/dist/esm/sql.d.ts +19 -0
- package/dist/esm/sql.js +324 -0
- package/dist/esm/test-plan.d.ts +102 -0
- package/dist/esm/test-plan.js +336 -0
- package/dist/esm/vitest.d.ts +27 -0
- package/dist/esm/vitest.js +48 -0
- package/package.json +379 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,305 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @watchtowerobservability/node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/watchtowerobservability/watchtower-node/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
GitHub Packages needs a token with `read:packages` even for public packages:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @watchtowerobservability/node
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install the attested tarball from a release without a token:
|
|
14
|
+
`npm install https://github.com/watchtowerobservability/watchtower-node/releases/download/v0.2.0/watchtowerobservability-node-0.2.0.tgz`.
|
|
15
|
+
|
|
16
|
+
Written in TypeScript and shipped as both ESM and CommonJS (`import` and `require` both work); the `.d.ts`
|
|
17
|
+
typings are generated from the source. A thin layer over the OpenTelemetry Node SDK (ruling L1): `Authorization: Bearer` header, endpoint default (`WT_OTLP_ENDPOINT`), disk offline buffer,
|
|
18
|
+
`wt.*`-safe resource attributes, redaction hook, `getPrompt`, `score`, `evaluate`, `observe`.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import * as wt from '@watchtowerobservability/node'; // or: const wt = require('@watchtowerobservability/node');
|
|
22
|
+
wt.init({ apiKey: process.env.WT_INGEST_KEY, project: process.env.WT_PROJECT_ID, bufferDir: '.wt-buffer' });
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import * as wt from '@watchtowerobservability/node'; // or: const wt = require('@watchtowerobservability/node');
|
|
29
|
+
wt.init({}); // WT_INGEST_KEY, WT_SERVICE, WT_ENVIRONMENT, WT_RELEASE from env
|
|
30
|
+
const traceId = wt.captureException(new Error('oops')); // also: uncaught errors and unhandled rejections
|
|
31
|
+
wt.log('info', 'started', { port: 3000 }); // OTLP log, linked to the active trace
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`init` hooks `uncaughtException` and `unhandledRejection` (pass `captureProcessErrors: false` to opt out). It
|
|
35
|
+
flushes and exits with code 1 like Node does, only when no other handler is registered.
|
|
36
|
+
Request bodies, headers, query strings and query arguments are never recorded.
|
|
37
|
+
|
|
38
|
+
## Integrations
|
|
39
|
+
|
|
40
|
+
Each lives at its own subpath, so nothing is loaded that you do not import.
|
|
41
|
+
|
|
42
|
+
| Integration | Import | Use |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| Express | `@watchtowerobservability/node/express` | `app.use(requestHandler())` first, `app.use(errorHandler())` last |
|
|
45
|
+
| Fastify | `.../fastify` | `await app.register(plugin)` |
|
|
46
|
+
| Koa | `.../koa` | `app.use(middleware())` first |
|
|
47
|
+
| NestJS | `.../nestjs` | `app.useGlobalInterceptors(new WatchtowerInterceptor())` (add express or fastify integration for spans) |
|
|
48
|
+
| Next.js server | `.../next` | `instrumentation.js`: `module.exports = require('@watchtowerobservability/node/next')` (exports `register`, `onRequestError`) |
|
|
49
|
+
| Prisma | `.../prisma` | `prisma.$extends(watchtowerExtension())` |
|
|
50
|
+
| BullMQ | `.../bullmq` | `import * as bullmq from 'bullmq'; instrumentBullMQ(bullmq)` before creating queues and workers |
|
|
51
|
+
| postgres.js (>= 4) | `.../postgres` | `instrumentPostgres()` once at startup |
|
|
52
|
+
| SQLite (`node:sqlite`) | `.../sqlite` | `import * as sqlite from 'node:sqlite'; instrumentNodeSqlite(sqlite)` |
|
|
53
|
+
| better-sqlite3 | `.../sqlite` | `instrumentBetterSqlite3(Database)` (the default export) |
|
|
54
|
+
| sqlite3 | `.../sqlite` | `instrumentSqlite3(sqlite3)` |
|
|
55
|
+
| libSQL / Turso | `.../sqlite` | `const db = instrumentLibsql(createClient({ url }))` |
|
|
56
|
+
| DuckDB | `.../duckdb` | `import * as duckdb from '@duckdb/node-api'; instrumentDuckDB(duckdb)` (classic `duckdb` too) |
|
|
57
|
+
| LMDB (lmdb-js) | `.../lmdb` | `instrumentLmdb(open({ path }))` after `init` |
|
|
58
|
+
| LevelDB / RocksDB | `.../level` | `instrumentLevel(new ClassicLevel(dir))`, `instrumentLevel(rocksdb(dir), { system: 'rocksdb' })` |
|
|
59
|
+
| node-cache, lru-cache, Keyv | `.../cache` | `instrumentNodeCache(cache, 'sessions')`, `instrumentLruCache(lru)`, `instrumentKeyv(keyv)` after `init` |
|
|
60
|
+
| MongoDB pool | `.../pools` | `instrumentMongoPool(client)` after `init` (pool gauges, wait/use time, timeouts from CMAP events) |
|
|
61
|
+
| mysql2 pool | `.../pools` | `instrumentMysql2Pool(pool)` (callback or `.promise()` pool) |
|
|
62
|
+
| Any pool (e.g. node-postgres) | `.../pools` | `observePool('postgresql', 'main', () => ({ used: p.totalCount - p.idleCount, idle: p.idleCount, pending: p.waitingCount, max: 10 }))` |
|
|
63
|
+
| Drizzle | `.../orm` | `instrumentDrizzle(db, 'postgresql')` once per `drizzle(...)` instance |
|
|
64
|
+
| Kysely | `.../orm` | `new Kysely({ dialect, log: kyselyLog('postgresql') })` |
|
|
65
|
+
| TypeORM | `.../orm` | `instrumentTypeORM(dataSource)` |
|
|
66
|
+
| Sequelize | `.../orm` | `new Sequelize(url, { benchmark: true, logging: sequelizeLogging('postgresql') })` |
|
|
67
|
+
| MikroORM | `.../orm` | `MikroORM.init({ loggerFactory: mikroOrmLoggerFactory(DefaultLogger, 'postgresql') })` |
|
|
68
|
+
| amqplib (RabbitMQ) | `.../amqp` | `instrumentAmqplib(await conn.createChannel())` once (patches the channel class) |
|
|
69
|
+
| rabbitmq-client | `.../amqp` | `instrumentRabbitmqClient(rabbit)` before `createPublisher`/`createConsumer` |
|
|
70
|
+
| NATS (nats.js) | `.../nats` | `import * as nats from 'nats'; instrumentNats(nc, nats)` |
|
|
71
|
+
| MQTT (mqtt.js) | `.../mqtt` | `instrumentMqtt(client)` (context propagates on MQTT 5 clients) |
|
|
72
|
+
| pg-boss | `.../pg-boss` | `instrumentPgBoss(boss)` before `send`/`work` |
|
|
73
|
+
| Graphile Worker | `.../graphile-worker` | `run({ taskList: wrapTaskList(tasks) })`; `instrumentAddJob(utils)` |
|
|
74
|
+
| kafkajs | upstream | use `@opentelemetry/instrumentation-kafkajs` |
|
|
75
|
+
| SQL normalizer | `.../sql` | `normalizeAndHash(sql)` -> `[literal-free text, db.query.hash]` |
|
|
76
|
+
| AWS Lambda | `.../lambda` | `exports.handler = wrapHandler(async (event, ctx) => ...)` (async handlers; flushes before freeze) |
|
|
77
|
+
| Azure Functions | `.../azure-functions` | `app.http('fn', { handler: wrapFunction(async (req, ctx) => ...) })` (cold start, trigger, invocation id; flushes) |
|
|
78
|
+
| pino | `.../logs` | `pino(opts, pinoStream())` |
|
|
79
|
+
| winston | `.../logs` | `logger.add(watchtowerTransport())` |
|
|
80
|
+
| openai | `.../genai` | `instrumentOpenAI(new OpenAI())` |
|
|
81
|
+
| anthropic | `.../genai` | `instrumentAnthropic(new Anthropic())` |
|
|
82
|
+
| Mistral, Ollama | `.../genai` | `instrumentMistral(new Mistral())`, `instrumentOllama(ollama)` |
|
|
83
|
+
| LlamaIndex.TS | `.../genai` | `instrumentLlamaIndex(Settings)` |
|
|
84
|
+
| OpenAI Agents SDK | `.../genai` | `instrumentOpenAIAgents(addTraceProcessor)` |
|
|
85
|
+
| Vercel AI SDK | `.../genai` | `generateText({ experimental_telemetry: vercelAiTelemetry() })` |
|
|
86
|
+
|
|
87
|
+
GenAI spans follow the OTel GenAI semantic conventions (model, token usage, finish reasons); prompt and
|
|
88
|
+
completion text is not recorded. Streaming calls end their span at creation, without token usage.
|
|
89
|
+
|
|
90
|
+
### BullMQ
|
|
91
|
+
|
|
92
|
+
`instrumentBullMQ(bullmq)` patches the module you pass, so it works the same under ESM and CommonJS.
|
|
93
|
+
`Queue.add` and `addBulk` get PRODUCER spans (`send <queue>`); each job a `Worker` runs gets a
|
|
94
|
+
CONSUMER span (`process <queue>`) whose parent is the producer span, so one trace runs from the
|
|
95
|
+
request that queued the job to the job itself. The context travels in the job data under `_wt`
|
|
96
|
+
(object data only) and is removed before your processor sees `job.data`. Attributes follow the OTel
|
|
97
|
+
messaging conventions: `messaging.system=bullmq`, `messaging.destination.name`,
|
|
98
|
+
`messaging.operation.type` (`send`/`process`), `messaging.operation.name`, `messaging.message.id`,
|
|
99
|
+
`messaging.batch.message_count`, `messaging.bullmq.job.attempt` and `messaging.bullmq.job.delay_ms`.
|
|
100
|
+
Sandboxed processors (a file path instead of a function) run in a child process and get no consumer
|
|
101
|
+
span.
|
|
102
|
+
|
|
103
|
+
### postgres.js
|
|
104
|
+
|
|
105
|
+
postgres.js has no OTel instrumentation; from 4.0 it publishes every query on the `postgres:query`
|
|
106
|
+
diagnostics tracing channel. `instrumentPostgres()` subscribes to it and records a CLIENT span per
|
|
107
|
+
query, child of the active span: `db.system=postgresql`, `db.operation.name`, `db.namespace`,
|
|
108
|
+
`server.address`/`server.port`, `db.query.summary` (operation and first table, e.g.
|
|
109
|
+
`SELECT users`) and `db.query.hash` (see below; the statement text and parameters are never recorded).
|
|
110
|
+
A failed query sets the span
|
|
111
|
+
to error with its SQLSTATE in `db.response.status_code` (the error message is not recorded: it can
|
|
112
|
+
quote values). It returns an unsubscribe function.
|
|
113
|
+
|
|
114
|
+
### Datastore spans: summary, hash, N+1
|
|
115
|
+
|
|
116
|
+
Every datastore integration below (and postgres.js) records a CLIENT span per call, child of the
|
|
117
|
+
active span, following the OTel database conventions: `db.system.name`, `db.operation.name`,
|
|
118
|
+
`db.collection.name`, `db.namespace` and, for SQL, `db.query.summary` (also the span name, e.g.
|
|
119
|
+
`SELECT users`) and `db.query.hash`. The hash comes from the shared SQL normalizer (literals become
|
|
120
|
+
`?`, comments go, `IN (1, 2, 3)` becomes `IN (?+)`), so it is the same hash Watchtower computes on the
|
|
121
|
+
server and spans join the Datastores views. The algorithm is specified in
|
|
122
|
+
`docs/product/instrumentation/sql-normalization.md` and exported at `.../sql`.
|
|
123
|
+
|
|
124
|
+
Statement text and parameters are never recorded by default. Pass `{ queryText: true }` (or set
|
|
125
|
+
`WATCHTOWER_DB_QUERY_TEXT=1`) to add `db.query.text`, which is then the literal-free text. A
|
|
126
|
+
statement that runs more than 5 times under one parent span gets `db.n_plus_one=true` and
|
|
127
|
+
`db.query.repeat_count` from the sixth run on; change the limit with `{ nPlusOne: n }` or
|
|
128
|
+
`WATCHTOWER_DB_N_PLUS_ONE` (0 turns it off). Failed calls set the span to error with the driver's
|
|
129
|
+
code in `db.response.status_code` and `error.type`; the error message is not recorded (it can quote
|
|
130
|
+
values). All integrations take the module, class or instance you pass, so they work under ESM and
|
|
131
|
+
CommonJS. Metric helpers use the global meter: call them after `init`.
|
|
132
|
+
|
|
133
|
+
### Embedded stores and caches
|
|
134
|
+
|
|
135
|
+
- **SQLite.** `instrumentNodeSqlite`, `instrumentBetterSqlite3` and `instrumentSqlite3` trace `exec`
|
|
136
|
+
and prepared `run`/`get`/`all` (sqlite3: `run`/`get`/`all`/`exec`/`each` on `Database`; the span
|
|
137
|
+
ends in your callback, which keeps the caller's context). `instrumentLibsql(client)` traces
|
|
138
|
+
`execute`, `executeMultiple`, `batch` and the same calls on transactions. `observeSqliteFile(path)`
|
|
139
|
+
reports `wt.embedded.file.size` and `wt.embedded.wal.size`. Not traced: `iterate()`, sqlite3
|
|
140
|
+
`Statement` objects.
|
|
141
|
+
- **DuckDB.** `instrumentDuckDB(duckdb)` traces `DuckDBConnection.run*`/`stream*` (Neo API) or the
|
|
142
|
+
classic `Database`/`Connection` callbacks; `observeDuckDBFile(path)` reports file and WAL size.
|
|
143
|
+
Prepared statements are not traced.
|
|
144
|
+
- **LMDB.** `instrumentLmdb(db)` traces async writes (`put`, `remove`, `ifVersion`, `ifNoExists`,
|
|
145
|
+
`clearAsync`, `drop`), `getMany` and `transaction` (calls inside it are child spans), on the root
|
|
146
|
+
and on `openDB` sub-databases. Synchronous `get` is memory-mapped and gets no span. It reports
|
|
147
|
+
`wt.embedded.map.size`, `.map.used`, `.entries`, `.readers` and `.file.size`.
|
|
148
|
+
- **LevelDB / RocksDB.** `instrumentLevel(db, { system })` traces `get`, `getMany`, `put`, `del`,
|
|
149
|
+
`batch` and `clear` (promise or callback form) on the db and its sublevels, and reports the store
|
|
150
|
+
directory size as `wt.embedded.file.size`. Iterators and the chained `batch()` builder are not
|
|
151
|
+
traced.
|
|
152
|
+
- **Caches.** `instrumentNodeCache`, `instrumentLruCache` and `instrumentKeyv` count
|
|
153
|
+
`wt.embedded.cache.hits` and `.misses` (a `get` returning `undefined` is a miss; multi-key gets count
|
|
154
|
+
per key) and, where the cache knows it, `wt.embedded.cache.entries`. Caches get metrics, not
|
|
155
|
+
spans.
|
|
156
|
+
|
|
157
|
+
### Connection pools
|
|
158
|
+
|
|
159
|
+
Pool metrics follow the OTel database conventions and carry `db.system.name` and
|
|
160
|
+
`db.client.connection.pool.name`: `db.client.connection.count{db.client.connection.state=used|idle}`,
|
|
161
|
+
`db.client.connection.max`, `db.client.connection.pending_requests`, the histograms
|
|
162
|
+
`db.client.connection.wait_time` and `db.client.connection.use_time` (seconds) and the counter
|
|
163
|
+
`db.client.connection.timeouts`. Call these after `init`; the gauges are read at each export.
|
|
164
|
+
`instrumentMongoPool(client)` builds them per server address from the driver's connection-pool
|
|
165
|
+
events (wait time needs driver 6.9 or newer). `instrumentMysql2Pool(pool)` reads the pool's own
|
|
166
|
+
counts and measures use time from acquire to release. It is named `host:port/database` unless you
|
|
167
|
+
pass a name. mysql2 reports no queue wait and has no acquire timeout, so those two stay empty.
|
|
168
|
+
For any other pool, `observePool(system, name, read)` takes your own `read()` function. It returns
|
|
169
|
+
`wait(s)`, `use(s)`, `timeout()` and `stop()`.
|
|
170
|
+
|
|
171
|
+
### ORMs
|
|
172
|
+
|
|
173
|
+
Each ORM query becomes a CLIENT span with the summary, hash and N+1 hint described above.
|
|
174
|
+
- **Drizzle and TypeORM:** the query runs inside the span. Drizzle transactions run on their own
|
|
175
|
+
session and get no spans.
|
|
176
|
+
- **Kysely, Sequelize and MikroORM:** the span is built from the query time the ORM reports and
|
|
177
|
+
ends when the query does. Sequelize needs `benchmark: true` and does not report failed queries
|
|
178
|
+
with a timing.
|
|
179
|
+
- **TypeORM:** maps `options.type` to the OTel names (postgres to postgresql, mssql to
|
|
180
|
+
microsoft.sql_server, the sqlite drivers to sqlite).
|
|
181
|
+
|
|
182
|
+
If you also instrument the driver underneath, each query gets one ORM span and one driver span.
|
|
183
|
+
|
|
184
|
+
### Queues and brokers
|
|
185
|
+
|
|
186
|
+
Every broker and job-queue integration records a PRODUCER span when a message or job is sent and a
|
|
187
|
+
CONSUMER span when it is processed. The consumer span is a child of the producer span and also links
|
|
188
|
+
to it, so one trace runs from the request to the handler and Watchtower can compute queue lag
|
|
189
|
+
(`wt.messaging.lag_ms`). Attributes follow the OTel messaging conventions: `messaging.system`,
|
|
190
|
+
`messaging.destination.name`, `messaging.operation.type` (`send`/`process`), `messaging.operation.name`,
|
|
191
|
+
`messaging.message.id`, `messaging.message.body.size`, `messaging.batch.message_count` and
|
|
192
|
+
`messaging.consumer.group.name` where the library has one. A failed handler marks its span as an error
|
|
193
|
+
with `error.type`; the error message is not recorded.
|
|
194
|
+
|
|
195
|
+
- **amqplib**: `publish` and `sendToQueue` put `traceparent`/`tracestate` into `options.headers`
|
|
196
|
+
(your headers are kept); `consume` callbacks run in the consumer span. Also recorded:
|
|
197
|
+
`messaging.rabbitmq.destination.routing_key`, `messaging.rabbitmq.message.delivery_tag` and
|
|
198
|
+
`.redelivered`. A ConfirmChannel is a separate class, so instrument one of those too if you use it.
|
|
199
|
+
- **rabbitmq-client**: `publisher.send(envelope | queue, body)` adds the context to the envelope
|
|
200
|
+
headers; `createConsumer` handlers run in the consumer span.
|
|
201
|
+
- **nats**: `publish` and `request` add the context as NATS headers. A `callback` subscription runs
|
|
202
|
+
each callback in the consumer span. With `for await (const m of sub)`, each message's span runs from
|
|
203
|
+
receipt until the next iteration and is not active inside the loop body: spans you start there are
|
|
204
|
+
not its children, but the producer link still gives lag.
|
|
205
|
+
- **mqtt**: `publish`/`publishAsync` carry the context in MQTT 5 user properties, so only
|
|
206
|
+
`protocolVersion: 5` clients propagate it; older clients get spans that are not linked. `message`
|
|
207
|
+
listeners run in the consumer span. `publish` spans end when the call returns; use `publishAsync`
|
|
208
|
+
to include the QoS 1/2 ack time.
|
|
209
|
+
- **pg-boss**: `send` and `insert` (v9 and v10 forms) carry the context in job data under `_wt`
|
|
210
|
+
(object data only). It is removed before your `work` handler runs. A batch gets one consumer span
|
|
211
|
+
linked to every job's producer. `messaging.system` is `pg-boss`, since OTel defines no value for it.
|
|
212
|
+
`sendAfter`, `sendThrottled`, `sendDebounced` and `sendSingleton` bypass `send`, so their jobs carry
|
|
213
|
+
no context.
|
|
214
|
+
- **Graphile Worker**: `instrumentAddJob(utils)` (or the runner from `run`) adds `_wt` to the payload.
|
|
215
|
+
`wrapTaskList` runs each task in a consumer span, strips `_wt`, and instruments `helpers.addJob` so
|
|
216
|
+
follow-up jobs stay in the trace. `quickAddJob` cannot be patched under ESM; use `utils.addJob`.
|
|
217
|
+
- **kafkajs**: upstream `@opentelemetry/instrumentation-kafkajs` already covers it.
|
|
218
|
+
|
|
219
|
+
## Profiling
|
|
220
|
+
|
|
221
|
+
Set `WT_PROFILING=1` and `init()` starts the profiler with the same key, endpoint, service and
|
|
222
|
+
release as traces. Or start it yourself:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import { startProfiling } from '@watchtowerobservability/node/profiling';
|
|
226
|
+
await startProfiling({ service: 'api' }); // key and endpoint from WT_INGEST_KEY / WT_OTLP_ENDPOINT
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
V8's own CPU sampler (`node:inspector`, 100 Hz, no native addon) is encoded as pprof (no extra
|
|
230
|
+
dependency) and posted to the gateway's `/v1/profiles?format=pprof&service=<service>&version=<release>`
|
|
231
|
+
every 60 s. Idle time is left out. Samples taken inside `withSpan` carry `span_id` and `trace_id`
|
|
232
|
+
labels. `shutdown()` uploads the last partial period. `withSpan(() => work())`
|
|
233
|
+
labels samples with the active OpenTelemetry span, so a trace links to its exact profile. By default
|
|
234
|
+
only its synchronous part counts. `startProfiling({ asyncSpans: true })` (or
|
|
235
|
+
`enableAsyncSpanLabels()`) also labels code after each `await`, through AsyncLocalStorage and V8
|
|
236
|
+
promise hooks. It is opt-in because its overhead is not part of the benchmark below. Plain callbacks it starts
|
|
237
|
+
(timers, events) are labeled only from their own `await`s on. Past 100 000 labeled intervals in one
|
|
238
|
+
upload period, the rest of that period is unlabeled.
|
|
239
|
+
|
|
240
|
+
### Measuring profiler overhead
|
|
241
|
+
|
|
242
|
+
The profiler's CPU cost depends on your machine and workload, so measure it instead of trusting a
|
|
243
|
+
number: `WT_BENCH=1 npx vitest run test/overhead.bench.test.ts` (in `sdks/node`) runs a CPU-bound loop
|
|
244
|
+
with and without the 100 Hz sampler, prints the median overhead in percent and fails above
|
|
245
|
+
`WT_BENCH_MAX_PCT` (default 2). `WT_BENCH_ROUNDS` and `WT_BENCH_WORK_MS` tune the run. We publish no
|
|
246
|
+
measured figure here; run it on your hardware. The benchmark excludes the once-a-minute upload.
|
|
247
|
+
|
|
248
|
+
## App and API Protection
|
|
249
|
+
|
|
250
|
+
An in-app WAF fed by your project's ruleset (key scope `probes:read`). In `monitor` mode it
|
|
251
|
+
records attacks on the server span. In `block` mode, and always for denylisted IPs and users, it
|
|
252
|
+
answers 403 before your handler runs.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
import { startAppsec, appsecMiddleware, trackLogin } from '@watchtowerobservability/node/appsec';
|
|
256
|
+
startAppsec(); // WT_API_URL, WT_INGEST_KEY, WT_SERVICE
|
|
257
|
+
app.use(appsecMiddleware());
|
|
258
|
+
// in the login handler: trackLogin(email, ok);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
See `docs/product/security/app-api-protection.md`.
|
|
262
|
+
|
|
263
|
+
## Configuration
|
|
264
|
+
|
|
265
|
+
| Option | Env var | Default |
|
|
266
|
+
| --- | --- | --- |
|
|
267
|
+
| `apiKey` | `WT_INGEST_KEY` | required, sent as `Authorization: Bearer`, masked in output |
|
|
268
|
+
| `endpoint` | `WT_OTLP_ENDPOINT` | `http://localhost:4318` |
|
|
269
|
+
| `serviceName` | `WT_SERVICE` | `app` |
|
|
270
|
+
| `environment` | `WT_ENVIRONMENT` | unset |
|
|
271
|
+
| `release` | `WT_RELEASE` | unset |
|
|
272
|
+
| `bufferDir` | | no offline buffer (spans, logs and metrics spool to `traces/`, `logs/` and `metrics/`, 500 batches each) |
|
|
273
|
+
| `logs` | `WATCHTOWER_LOGS` (`OTEL_LOGS_EXPORTER=none` also turns it off) | `on`: OTLP logs (`log()`, pino, winston) |
|
|
274
|
+
| `metrics` | `WATCHTOWER_METRICS` (`OTEL_METRICS_EXPORTER=none` also turns it off) | `on`: OTLP metrics, see below |
|
|
275
|
+
| `redact` | | none; called for every span and log attribute |
|
|
276
|
+
|
|
277
|
+
Metrics: `init` sets the global meter provider, so `metrics.getMeter('app')` (re-exported from
|
|
278
|
+
`@opentelemetry/api`) records to Watchtower. A periodic reader exports to `/v1/metrics` every
|
|
279
|
+
`OTEL_METRIC_EXPORT_INTERVAL` ms (default 60000); counters and histograms use delta temporality unless
|
|
280
|
+
`OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` is set. Install the optional peer
|
|
281
|
+
`@opentelemetry/instrumentation-runtime-node` for event loop, GC and heap metrics.
|
|
282
|
+
|
|
283
|
+
Examples: [`examples/basic.ts`](examples/basic.ts), [`examples/express-app`](examples/express-app/server.js).
|
|
284
|
+
|
|
285
|
+
Development: `npm install`, `npm run typecheck`, `npm test` (vitest), `npm run build` (`tsc` to `dist/cjs` and `dist/esm`).
|
|
286
|
+
|
|
287
|
+
## Test reporters and resumable evals
|
|
288
|
+
|
|
289
|
+
Jest: `reporters: ['default', ['@watchtowerobservability/node/jest', {}]]`. Vitest: `reporters: ['default', ['@watchtowerobservability/node/vitest', {}]]`.
|
|
290
|
+
|
|
291
|
+
Test optimization (`WT_TEST_OPTIMIZATION=1`, same contract as the pytest plugin: disabled and unaffected tests are skipped, quarantined failures do not fail the run, new tests are retried `efd_retries` times; `WT_CI_RUN_ID` also uploads the results as JUnit). Add a global setup file `export { default } from '@watchtowerobservability/node/test-plan'`, then for Vitest a setup file `import { beforeAll, afterEach } from 'vitest'; import { vitestSetup } from '@watchtowerobservability/node/test-plan'; vitestSetup({ beforeAll, afterEach });`, for Jest `testEnvironment: './wt-env.js'` with `module.exports = require('@watchtowerobservability/node/test-plan').jestEnvironment(require('jest-environment-node').TestEnvironment)`. Go: `go test -json ./... | wtctl ci gotest --respect-quarantine ...` and `go test -skip "$(wtctl ci plan ... --go-skip)"`.
|
|
292
|
+
Each test becomes a span (`test.outcome`) and, with `WT_PROJECT_ID`, a `test_pass` score. Set `WT_INGEST_KEY`
|
|
293
|
+
(or pass `client`/`apiKey`); without a key the reporters do nothing.
|
|
294
|
+
|
|
295
|
+
`client.evaluateResume(dataset, task, scorers, previousRows)` re-runs only the cases that errored or are missing
|
|
296
|
+
(the Python SDK has `evaluate_resume`).
|
|
297
|
+
|
|
298
|
+
## Provenance
|
|
299
|
+
|
|
300
|
+
Every release artifact carries a GitHub build attestation. Verify one with
|
|
301
|
+
`gh attestation verify <file> --repo watchtowerobservability/watchtower-node`.
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
Apache-2.0. Source of truth is the Watchtower monorepo; this repository is a published mirror.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export type Field = 'path' | 'query' | 'user_agent' | 'body' | 'headers';
|
|
2
|
+
export interface AppsecRule {
|
|
3
|
+
id: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
category: string;
|
|
6
|
+
severity?: string;
|
|
7
|
+
fields: Field[];
|
|
8
|
+
pattern: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DenyEntry {
|
|
11
|
+
value: string;
|
|
12
|
+
/** Unix seconds; null: no expiry. */
|
|
13
|
+
expires_at?: number | null;
|
|
14
|
+
}
|
|
15
|
+
export interface Ruleset {
|
|
16
|
+
mode: 'monitor' | 'block';
|
|
17
|
+
rules: AppsecRule[];
|
|
18
|
+
denylist?: {
|
|
19
|
+
ip?: DenyEntry[];
|
|
20
|
+
user?: DenyEntry[];
|
|
21
|
+
};
|
|
22
|
+
poll_s?: number;
|
|
23
|
+
}
|
|
24
|
+
/** One request as the inspector sees it (decoded). */
|
|
25
|
+
export interface Inspected {
|
|
26
|
+
path: string;
|
|
27
|
+
query?: string;
|
|
28
|
+
user_agent?: string;
|
|
29
|
+
body?: string;
|
|
30
|
+
headers?: string;
|
|
31
|
+
ip?: string;
|
|
32
|
+
user?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface Decision {
|
|
35
|
+
/** `allow`: nothing matched; `monitor`: matched, let through; `block`: answer 403. */
|
|
36
|
+
action: 'allow' | 'monitor' | 'block';
|
|
37
|
+
rule_id?: string;
|
|
38
|
+
category?: string;
|
|
39
|
+
match?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Rule id recorded for denylist blocks (the worker reports them as their own signal). */
|
|
42
|
+
export declare const DENYLIST = "denylist";
|
|
43
|
+
/** Replace the active ruleset (what the poller calls; tests may call it directly). */
|
|
44
|
+
export declare function setRuleset(r: Ruleset | null): void;
|
|
45
|
+
/** Whether `id` is on the user denylist (call after authentication to refuse a listed user). */
|
|
46
|
+
export declare const isUserBlocked: (id: string, now?: number) => boolean;
|
|
47
|
+
/** Judge one request. Denylisted callers are blocked in either mode. */
|
|
48
|
+
export declare function inspect(req: Inspected, now?: number): Decision;
|
|
49
|
+
type Headers = Record<string, string | string[] | undefined>;
|
|
50
|
+
/** The slice of a Node request the inspector reads. */
|
|
51
|
+
export interface NodeRequest {
|
|
52
|
+
url?: string;
|
|
53
|
+
originalUrl?: string;
|
|
54
|
+
headers?: Headers;
|
|
55
|
+
socket?: {
|
|
56
|
+
remoteAddress?: string;
|
|
57
|
+
};
|
|
58
|
+
body?: unknown;
|
|
59
|
+
}
|
|
60
|
+
/** The slice of a Node response used to answer 403. */
|
|
61
|
+
export interface NodeResponse {
|
|
62
|
+
statusCode: number;
|
|
63
|
+
setHeader?(name: string, value: string): unknown;
|
|
64
|
+
end(body?: string): unknown;
|
|
65
|
+
}
|
|
66
|
+
/** Client IP: first `X-Forwarded-For` hop, else `X-Real-IP`, else the socket peer.
|
|
67
|
+
* shortcut: trusts the forwarding headers; run behind a proxy that overwrites them. */
|
|
68
|
+
export declare function clientIp(req: NodeRequest): string | undefined;
|
|
69
|
+
/** Decode a Node request into the inspector's fields. */
|
|
70
|
+
export declare function fromNode(req: NodeRequest, user?: string): Inspected;
|
|
71
|
+
/** Record a decision on the active span. */
|
|
72
|
+
export declare function annotate(d: Decision, ip?: string): void;
|
|
73
|
+
/** Inspect and, when blocked, answer 403. Returns true when the request was answered. */
|
|
74
|
+
export declare function handleRequest(req: NodeRequest, res: NodeResponse, user?: string): boolean;
|
|
75
|
+
/** Connect-style middleware; `user(req)` names the caller when the app already knows it. */
|
|
76
|
+
export declare function appsecMiddleware(o?: {
|
|
77
|
+
user?: (req: NodeRequest) => string | undefined;
|
|
78
|
+
}): (req: NodeRequest, res: NodeResponse, next: (err?: unknown) => void) => void;
|
|
79
|
+
/** Mark the current request as a login attempt; failed ones feed the account-takeover rules. */
|
|
80
|
+
export declare function trackLogin(login: string, success: boolean): void;
|
|
81
|
+
export interface AppsecOptions {
|
|
82
|
+
/** API base; default `WT_API_URL` or https://api.watchtower.dev */
|
|
83
|
+
apiUrl?: string;
|
|
84
|
+
/** Ingestion key with scope `probes:read`; default `WT_INGEST_KEY`. */
|
|
85
|
+
key?: string;
|
|
86
|
+
/** Default `WT_SERVICE` or `OTEL_SERVICE_NAME`. */
|
|
87
|
+
service?: string;
|
|
88
|
+
fetch?: typeof fetch;
|
|
89
|
+
}
|
|
90
|
+
/** Fetch the ruleset now and keep polling; `stop()` ends the polling. */
|
|
91
|
+
export declare function startAppsec(o?: AppsecOptions): {
|
|
92
|
+
ready: Promise<void>;
|
|
93
|
+
stop(): void;
|
|
94
|
+
};
|
|
95
|
+
export {};
|