@rootcat/node 0.0.0-stage → 0.2.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/CHANGELOG.md +83 -0
- package/LICENSE +202 -0
- package/README.md +294 -2
- package/dist/attach.d.ts +1 -0
- package/dist/attach.js +24 -0
- package/dist/attach.js.map +1 -0
- package/dist/callsite.d.ts +109 -0
- package/dist/callsite.js +565 -0
- package/dist/callsite.js.map +1 -0
- package/dist/coexist.d.ts +183 -0
- package/dist/coexist.js +587 -0
- package/dist/coexist.js.map +1 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +182 -0
- package/dist/config.js.map +1 -0
- package/dist/drizzle.d.ts +21 -0
- package/dist/drizzle.js +127 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/esm.mjs +57 -0
- package/dist/esmhook.d.ts +52 -0
- package/dist/esmhook.js +158 -0
- package/dist/esmhook.js.map +1 -0
- package/dist/iitm-hook.mjs +83 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/intake.d.ts +40 -0
- package/dist/intake.js +164 -0
- package/dist/intake.js.map +1 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.js +33 -0
- package/dist/keys.js.map +1 -0
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +21 -0
- package/dist/notices.js.map +1 -0
- package/dist/otlp.d.ts +75 -0
- package/dist/otlp.js +449 -0
- package/dist/otlp.js.map +1 -0
- package/dist/pg.d.ts +16 -0
- package/dist/pg.js +170 -0
- package/dist/pg.js.map +1 -0
- package/dist/pgpool.d.ts +20 -0
- package/dist/pgpool.js +99 -0
- package/dist/pgpool.js.map +1 -0
- package/dist/postgresjs.d.ts +60 -0
- package/dist/postgresjs.js +400 -0
- package/dist/postgresjs.js.map +1 -0
- package/dist/privacy.d.ts +38 -0
- package/dist/privacy.js +161 -0
- package/dist/privacy.js.map +1 -0
- package/dist/processor.d.ts +197 -0
- package/dist/processor.js +494 -0
- package/dist/processor.js.map +1 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +12 -0
- package/dist/register.js.map +1 -0
- package/dist/sampler.d.ts +30 -0
- package/dist/sampler.js +101 -0
- package/dist/sampler.js.map +1 -0
- package/dist/sdk.d.ts +129 -0
- package/dist/sdk.js +606 -0
- package/dist/sdk.js.map +1 -0
- package/package.json +72 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
**Alongside another tracer.** An application whose tracer owns the
|
|
6
|
+
process's OpenTelemetry setup (Sentry, tested with 8.55, 9.47 and 10.51;
|
|
7
|
+
an application's own `NodeSDK`) starts Rootcat after it with
|
|
8
|
+
`startAlongside()` from `@rootcat/node/attach`, and gives a tracer that
|
|
9
|
+
records spans the processors from `rootcatSpanProcessors()`; see
|
|
10
|
+
"Alongside another tracer" in the README. Modes: `own`, `beside`,
|
|
11
|
+
`inside`.
|
|
12
|
+
|
|
13
|
+
- Sentry for errors only (no `tracesSampleRate`): the package runs its
|
|
14
|
+
own provider beside Sentry's, never registered globally, under Sentry's
|
|
15
|
+
context manager. Its spans are recorded without the sampled flag, so
|
|
16
|
+
the headers Sentry propagates and the error events it sends make the
|
|
17
|
+
same sampling statement as before. Sentry receives no transaction and
|
|
18
|
+
no span it did not receive before; its error events now carry the
|
|
19
|
+
Rootcat trace id, linking an error to its trace. Outgoing requests
|
|
20
|
+
carry Sentry's headers byte for byte as before, made before, during or
|
|
21
|
+
after the response. One client report is no longer sent:
|
|
22
|
+
the one counting an outgoing request's span Sentry skipped for want of
|
|
23
|
+
a parent, which now has one. A Hono route that `@sentry/hono` names
|
|
24
|
+
becomes the server span's `http.route`.
|
|
25
|
+
- Sentry with tracing: `Sentry.init({ openTelemetrySpanProcessors:
|
|
26
|
+
rootcatSpanProcessors() })` puts the package's processor in Sentry's
|
|
27
|
+
provider. It exports a copy of every span Sentry records, with its
|
|
28
|
+
call site and the privacy rules, and leaves Sentry's spans as they
|
|
29
|
+
are. The package adds no span of its own; its Drizzle, pg pool and
|
|
30
|
+
postgres.js entry wrappers carry call sites to Sentry's query spans.
|
|
31
|
+
- Nothing global is registered before `Sentry.init` in an application
|
|
32
|
+
that depends on a Sentry server SDK (listed in `package.json`, or
|
|
33
|
+
installed when there is none): loaded before it (the import line,
|
|
34
|
+
`NODE_OPTIONS`) the package starts nothing; `startAlongside()` above it
|
|
35
|
+
starts beside Sentry at once and settles a tick later: beside, or
|
|
36
|
+
inside a tracing Sentry with nothing of its own left on `node:http`, or
|
|
37
|
+
stopped (handlers removed, loader hook idle, processors inert). One
|
|
38
|
+
line on stderr either way.
|
|
39
|
+
- Whether Sentry traces is read by its own rule per major version (8:
|
|
40
|
+
a `tracesSampleRate` key with no value is tracing on). Beside another
|
|
41
|
+
SDK, no wrapper of it is removed or wrapped over (Sentry 8's
|
|
42
|
+
`node:http`). The package patches `http` and `https` through the
|
|
43
|
+
CommonJS hook itself, so server spans are recorded with Sentry's and
|
|
44
|
+
the package's import-in-the-middle copies apart (pnpm). Its loader
|
|
45
|
+
hook takes over postgres.js's entry and Drizzle's query classes from
|
|
46
|
+
a hook that wraps every module (Sentry 8's).
|
|
47
|
+
- Beside Sentry, outgoing `fetch` and `http` requests carry Sentry's
|
|
48
|
+
headers once, with the baggage they had without the package; the
|
|
49
|
+
package's spans below another SDK's unrecorded span (Next.js under
|
|
50
|
+
`@sentry/nextjs`) are kept.
|
|
51
|
+
- Inside a tracing Sentry, the copies the package exports are cut to
|
|
52
|
+
what its own spans would hold: span names that are paths or URLs
|
|
53
|
+
masked, Redis statements reduced to the command, `cache.key` and
|
|
54
|
+
headers dropped, `url.fragment` emptied. The pg pool wrapper leaves
|
|
55
|
+
`connect` to Sentry, and a wrapper of the package never unwraps another
|
|
56
|
+
SDK's.
|
|
57
|
+
- A registered provider is recognised in the same copy of
|
|
58
|
+
`@opentelemetry/api` as well; before, only one from another copy was.
|
|
59
|
+
|
|
60
|
+
**Other changes.**
|
|
61
|
+
|
|
62
|
+
- postgres.js: the driver's own queries on a new connection (the array
|
|
63
|
+
type lookup, the read-only check) are no longer traced; they showed as
|
|
64
|
+
a second span, with the call site, for the query that opened the
|
|
65
|
+
connection.
|
|
66
|
+
- ioredis and redis: a command is traced only inside a traced operation.
|
|
67
|
+
A queue such as BullMQ polls Redis all the time outside any, which was
|
|
68
|
+
a trace per poll.
|
|
69
|
+
- Request and response header attributes and Sentry's `sentry.*` keys
|
|
70
|
+
are never exported; `http.query` and `db.connection_string` are
|
|
71
|
+
emptied like `url.query`.
|
|
72
|
+
- The ES module loader hook is an import-in-the-middle instance of the
|
|
73
|
+
package's own, never a second registration of the `hook.mjs` another
|
|
74
|
+
SDK registered (with one copy installed for both, that replaced the
|
|
75
|
+
other's list of modules to wrap); it wraps only postgres.js's entry file
|
|
76
|
+
and Drizzle's two query classes of those ES module packages (all of
|
|
77
|
+
their files before), and neither hook warns about the other.
|
|
78
|
+
|
|
79
|
+
## 0.1.0
|
|
80
|
+
|
|
81
|
+
First release: the import line, `--require`/`--import` entries, the
|
|
82
|
+
curated instrumentations, the call-site processor, OTLP/HTTP protobuf
|
|
83
|
+
to the host agent.
|
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 2026 Kelvin Guchu
|
|
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,295 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rootcat/node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tracing for Node services that report to the Rootcat host agent, with the
|
|
4
|
+
line of application code behind every database and HTTP client call.
|
|
5
|
+
Loading the package starts an OpenTelemetry tracer with a curated set of
|
|
6
|
+
instrumentations and posts the spans to the agent's OTLP intake on the
|
|
7
|
+
same host. It talks to the host agent and to nothing else; it needs no
|
|
8
|
+
token.
|
|
9
|
+
|
|
10
|
+
## Enable
|
|
11
|
+
|
|
12
|
+
**Next.js** (the recommended setup): add `instrumentation.ts` beside
|
|
13
|
+
`next.config.js`. Next loads it before the application, in every server
|
|
14
|
+
it starts, including the standalone output:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// instrumentation.ts
|
|
18
|
+
export async function register() {
|
|
19
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') await import('@rootcat/node');
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
With `output: 'standalone'`, keep the package and the drivers out of the
|
|
24
|
+
server bundles (a bundled driver cannot be patched):
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// next.config.js
|
|
28
|
+
module.exports = {
|
|
29
|
+
output: 'standalone',
|
|
30
|
+
serverExternalPackages: ['@rootcat/node', 'postgres', 'drizzle-orm'],
|
|
31
|
+
experimental: { serverSourceMaps: true },
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**CommonJS apps** (Express, Fastify, a worker): one line, first in the
|
|
36
|
+
entry file, before anything else is required:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
require('@rootcat/node');
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**ES module apps** (`"type": "module"`): an entry of two files, so the
|
|
43
|
+
application's imports are resolved after the package is loaded:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
// main.mjs
|
|
47
|
+
import '@rootcat/node';
|
|
48
|
+
await import('./app.mjs');
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
A single file with `import '@rootcat/node'` above `import pg from 'pg'`
|
|
52
|
+
does not work: an ES module's static imports are all resolved and loaded
|
|
53
|
+
before any of them runs, so the drivers are already in memory, unpatched,
|
|
54
|
+
when the package starts. The dynamic `import()` runs after it.
|
|
55
|
+
|
|
56
|
+
**When the code cannot change**, set the variable instead (in Dokploy, the
|
|
57
|
+
application's Environment tab):
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
NODE_OPTIONS="--require @rootcat/node" # CommonJS
|
|
61
|
+
NODE_OPTIONS="--import @rootcat/node/esm" # ES modules
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Using the line and the variable together is harmless: the tracer starts
|
|
65
|
+
once.
|
|
66
|
+
|
|
67
|
+
The intake address is discovered: inside a container on a Docker bridge
|
|
68
|
+
it is the container's default gateway (the bridge address the agent
|
|
69
|
+
listens on); on the host, or in a container on the host's network, it is
|
|
70
|
+
loopback; port 4318 either way. Discovery never picks a public address.
|
|
71
|
+
The host-network check looks for a Docker bridge in `/sys/class/net`: a
|
|
72
|
+
container on the host's network under Podman, or on a Docker host with no
|
|
73
|
+
bridge network, should set `ROOTCAT_OTLP_URL=http://127.0.0.1:4318`.
|
|
74
|
+
`ROOTCAT_OTLP_URL` overrides discovery. The service name is `ROOTCAT_SERVICE`,
|
|
75
|
+
else `OTEL_SERVICE_NAME`, else the `name` of the nearest `package.json`.
|
|
76
|
+
|
|
77
|
+
**Alongside another tracer** (Sentry, tested with 8.55, 9.47 and 10.51;
|
|
78
|
+
an app's own `NodeSDK`), the package starts after it: see Alongside
|
|
79
|
+
another tracer below.
|
|
80
|
+
|
|
81
|
+
## Alongside another tracer
|
|
82
|
+
|
|
83
|
+
The package works alongside a tracer that owns the process's
|
|
84
|
+
OpenTelemetry setup (its tracer provider, the context manager, the
|
|
85
|
+
propagator): it starts after that tracer and takes none of them. Sentry 8
|
|
86
|
+
and later is the worked example. In the file that initialises Sentry:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// src/instrument.ts (node --import ./dist/instrument.js ./dist/index.js)
|
|
90
|
+
import { startAlongside } from '@rootcat/node/attach';
|
|
91
|
+
import { initializeSentry } from './lib/sentry';
|
|
92
|
+
|
|
93
|
+
initializeSentry(); // Sentry.init({ ... })
|
|
94
|
+
startAlongside();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
With Sentry tracing on (`tracesSampleRate` or `tracesSampler`), also give
|
|
98
|
+
`Sentry.init` the package's processor:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { rootcatSpanProcessors } from '@rootcat/node/attach';
|
|
102
|
+
|
|
103
|
+
Sentry.init({ ...options, openTelemetrySpanProcessors: rootcatSpanProcessors() });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- **Sentry for errors only**: the package runs its own provider beside
|
|
107
|
+
Sentry's, unregistered, with the curated instrumentations. Sentry sends
|
|
108
|
+
what it sent before: no transaction, no span, the same error events
|
|
109
|
+
with their request scope and `beforeSend`; each error event now carries
|
|
110
|
+
the Rootcat trace id of its request. Outgoing requests carry
|
|
111
|
+
`sentry-trace` and `baggage` byte for byte as without Rootcat (ids
|
|
112
|
+
aside), whether made before, during or after the response, so
|
|
113
|
+
downstream Sentry quotas and a payment provider's callbacks see what
|
|
114
|
+
they saw. The one item not sent is a client report of a span
|
|
115
|
+
Sentry skipped for want of a parent, which now has one. With
|
|
116
|
+
`@sentry/hono` the server span gets the route (`http.route`).
|
|
117
|
+
- **Sentry with tracing**: Sentry instruments the libraries; the package
|
|
118
|
+
adds no span and exports a copy of each span Sentry records, with its
|
|
119
|
+
call site, without changing what Sentry sends, cut to what the
|
|
120
|
+
package's own spans would hold (no headers, masked paths in span names,
|
|
121
|
+
Redis commands without keys). Sentry's sample rate decides which traces
|
|
122
|
+
exist; a query outside a request (a queue job) has no Sentry span, so
|
|
123
|
+
none here either.
|
|
124
|
+
- Nothing global is registered before `Sentry.init`: that would take the
|
|
125
|
+
context manager from Sentry and break its request isolation. Loaded
|
|
126
|
+
before it (the import line first, or `NODE_OPTIONS`), the package starts
|
|
127
|
+
nothing and says so in one line. `startAlongside()` above `Sentry.init`
|
|
128
|
+
starts beside Sentry at once and settles a tick later (stays beside,
|
|
129
|
+
goes inside a tracing Sentry leaving nothing of its own on `node:http`,
|
|
130
|
+
or stops, leaving nothing running), one line on stderr; the ES
|
|
131
|
+
module drivers may go untraced in that order, so call it after
|
|
132
|
+
`Sentry.init`.
|
|
133
|
+
- Trace context crosses services in Sentry's headers (`sentry-trace`,
|
|
134
|
+
`baggage`); Sentry's propagator does not read a W3C `traceparent`.
|
|
135
|
+
|
|
136
|
+
With an application's own `NodeSDK`, pass `rootcatSpanProcessors()` in
|
|
137
|
+
its `spanProcessors` and call `startAlongside()` after `sdk.start()`.
|
|
138
|
+
Tested with `@sentry/hono` 10.51 (npm, and a pnpm deployment as the
|
|
139
|
+
owner's API ships) and `@sentry/node` 8.55 and 9.47; expected to work
|
|
140
|
+
with the other Sentry server SDKs of those versions and any
|
|
141
|
+
OpenTelemetry SDK whose provider takes span processors; not with one whose provider does not (`dd-trace`), where the
|
|
142
|
+
package does not start and says so. The cost per request beside and
|
|
143
|
+
inside Sentry: see Cost. Details, and why not `skipOpenTelemetrySetup`:
|
|
144
|
+
"Alongside another tracer" in `docs/v4-node-package.md`.
|
|
145
|
+
|
|
146
|
+
## What is traced
|
|
147
|
+
|
|
148
|
+
| Package | Spans | Call site | Tested here |
|
|
149
|
+
|---|---|---|---|
|
|
150
|
+
| `http`, `https` | server and client requests | client requests | through Next.js |
|
|
151
|
+
| `fetch`, `undici` | client requests | yes | no |
|
|
152
|
+
| `pg` | one span per query; cursors and streams (`pg-cursor`, `pg-query-stream`) are not traced | yes, through the pool as well | yes |
|
|
153
|
+
| `postgres` (postgres.js) | one span per query (not the driver's own queries on a new connection) | tagged templates, and queries made through Drizzle | yes |
|
|
154
|
+
| `drizzle-orm` | the driver spans below it | yes, from where the query was built | yes, over `pg` and postgres.js |
|
|
155
|
+
| `mysql2` | queries | yes | no |
|
|
156
|
+
| `mongodb` | commands | yes | no |
|
|
157
|
+
| `ioredis`, `redis` | commands inside a traced operation (a queue's polling outside one is not traced) | yes | with Sentry, through BullMQ |
|
|
158
|
+
| `@prisma/client` | when the app installs `@prisma/instrumentation` | the operation's | no |
|
|
159
|
+
|
|
160
|
+
Every client span carries `code.filepath`, `code.lineno` and
|
|
161
|
+
`code.function` for the first application frame: outside `node_modules`,
|
|
162
|
+
resolved through the file's source map when it has one, and skipped when
|
|
163
|
+
the map sends it into a bundled library. `code.filepath` is relative to
|
|
164
|
+
the working directory (or, outside it, to the parent of the file's
|
|
165
|
+
package), cut from the front to 120 bytes; the server's absolute layout
|
|
166
|
+
is not sent. A query run where no application frame is on the stack (a
|
|
167
|
+
pool handing it to a client on the next tick, an awaited ORM promise)
|
|
168
|
+
takes the site captured where the application made the call; a query
|
|
169
|
+
issued in the continuation of another gets its own.
|
|
170
|
+
|
|
171
|
+
## What never leaves the process
|
|
172
|
+
|
|
173
|
+
Literals in query text: strings, numbers and dollar-quoted bodies become
|
|
174
|
+
`?`, comments are dropped, placeholders (`$1`) and identifiers stay
|
|
175
|
+
(`ROOTCAT_DB_STATEMENT=off` keeps only the first keyword). Parameter
|
|
176
|
+
values (never read). Query strings and fragments on URLs, and every path
|
|
177
|
+
segment that could hold an identifier or a token (`/users/42/orders` is
|
|
178
|
+
sent as `/users/{id}/orders`): a segment is kept only when it is a name of
|
|
179
|
+
letters, hyphens and underscores up to 32 bytes (not a mixed-case run of
|
|
180
|
+
twelve or more) or a version such as `v1`, so a username or slug made of
|
|
181
|
+
letters (`/u/kelvin`) is sent, and numbers, UUIDs, tokens, emails and file
|
|
182
|
+
names are not. Client addresses and user agents. Request
|
|
183
|
+
and response bodies and headers (header attributes another SDK such as
|
|
184
|
+
Sentry records are dropped). Connection strings. Environment variables and command lines.
|
|
185
|
+
A database server's error message (only the error class and SQLSTATE
|
|
186
|
+
travel). A recorded exception's stack trace is sent as frames only.
|
|
187
|
+
|
|
188
|
+
## Settings
|
|
189
|
+
|
|
190
|
+
| Variable | Default | Meaning |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| `ROOTCAT_SAMPLE` | `1` | share of traces recorded, `0` to `1`; a trace is kept or dropped whole, and an incoming `traceparent`'s sampled flag is ignored |
|
|
193
|
+
| `ROOTCAT_CALLSITE_SAMPLE` | `1` | capture a call site for one recorded client span in N; `0` for none |
|
|
194
|
+
| `ROOTCAT_OTLP_URL` | discovered | intake origin, or a full `/v1/traces` URL |
|
|
195
|
+
| `ROOTCAT_SERVICE` | `OTEL_SERVICE_NAME`, then package.json | service name |
|
|
196
|
+
| `ROOTCAT_ENVIRONMENT` | `NODE_ENV` | `deployment.environment.name` |
|
|
197
|
+
| `ROOTCAT_DB_STATEMENT` | `masked` | `off` keeps only the statement's first keyword |
|
|
198
|
+
| `ROOTCAT_DISABLE` | | comma list: `http,undici,pg,postgres,drizzle,mysql2,mongodb,ioredis,redis,prisma` |
|
|
199
|
+
| `ROOTCAT_DEBUG` | | `1` prints the OpenTelemetry diagnostics and the chosen intake to stderr |
|
|
200
|
+
| `ROOTCAT_DISABLED` | | `1` loads nothing |
|
|
201
|
+
|
|
202
|
+
The two sampling settings are the only tuning; batching and the stack
|
|
203
|
+
walk are fixed. The `OTEL_EXPORTER_OTLP_*` and `OTEL_TRACES_SAMPLER`
|
|
204
|
+
variables are not read: spans go to the agent, sampled as above.
|
|
205
|
+
|
|
206
|
+
## Cost
|
|
207
|
+
|
|
208
|
+
Measured in one warmed-up process on a loop of sequential `pg` queries
|
|
209
|
+
over loopback, the worst case for a per-query cost (`npm run bench`;
|
|
210
|
+
WSL2, Node 24.21). Each loopback query costs 174 µs of CPU untraced.
|
|
211
|
+
|
|
212
|
+
| Setting | CPU added per query | Wall added per query |
|
|
213
|
+
|---|---|---|
|
|
214
|
+
| Defaults (every query traced, every call site) | +190 µs | +204 µs |
|
|
215
|
+
| `ROOTCAT_CALLSITE_SAMPLE=0` (no call sites) | +114 µs | +137 µs |
|
|
216
|
+
| `ROOTCAT_CALLSITE_SAMPLE=10` | +142 µs | +166 µs |
|
|
217
|
+
| `ROOTCAT_SAMPLE=0.1` (one trace in ten) | +63 µs | +82 µs |
|
|
218
|
+
| A query in an unsampled trace | +29 µs | +45 µs |
|
|
219
|
+
|
|
220
|
+
On a 20 ms request with five queries that is about 1 ms of CPU with the
|
|
221
|
+
defaults and 0.3 ms at one trace in ten. Hot, a call-site capture costs
|
|
222
|
+
11 µs, a span 4 µs, encoding a span 3.1 µs; in a server waiting on its
|
|
223
|
+
database each query runs on cold caches and pays about four times that.
|
|
224
|
+
Loading the package adds 0.3 to 0.4 s to the start of a process, about
|
|
225
|
+
half of it the module loader hook (every module load waits on its
|
|
226
|
+
thread).
|
|
227
|
+
|
|
228
|
+
Per request (`npm run bench:sentry`: a Hono route running one Drizzle
|
|
229
|
+
query, 2000 sequential requests after a warm-up, medians of six rounds;
|
|
230
|
+
ranges over three runs, which differ by up to a third on this machine):
|
|
231
|
+
|
|
232
|
+
| Setup | Server CPU added per request |
|
|
233
|
+
|---|---|
|
|
234
|
+
| Rootcat on its own (no Sentry) | +990 µs (+76 %) |
|
|
235
|
+
| Rootcat beside an errors-only Sentry | +1005 to +1220 µs (+65 to +88 %) |
|
|
236
|
+
| Rootcat inside a Sentry that traces every request | +235 to +535 µs (+5 to +15 %) |
|
|
237
|
+
|
|
238
|
+
The HTTP server span is the largest piece of a request's cost; budget
|
|
239
|
+
about 1 ms per request and 0.2 ms per query. Beside Sentry, about
|
|
240
|
+
0.2 ms of it is Sentry's context manager, which clones a scope at every
|
|
241
|
+
context switch. Turning Sentry's own tracing on costs more (+2.9 ms on
|
|
242
|
+
the same route).
|
|
243
|
+
|
|
244
|
+
## When the agent is not there
|
|
245
|
+
|
|
246
|
+
Spans are batched (every 10 s, up to 512 per export, 4096 queued; past
|
|
247
|
+
that the newest are dropped and stderr says so once), bounded (4 KiB per
|
|
248
|
+
attribute value, statements and exception stacks included) and posted as
|
|
249
|
+
protobuf in requests of at most 900 KiB, under the agent's 1 MiB bound,
|
|
250
|
+
with a 2 s timeout and at most two exports in flight. A request the
|
|
251
|
+
intake refuses as too large is said once on stderr. A failed export
|
|
252
|
+
drops its batch. The application never waits on the exporter and never
|
|
253
|
+
sees its errors. A process exiting with the intake unreachable waits up
|
|
254
|
+
to 2 s for the last flush; on SIGTERM or SIGINT with no handler of the
|
|
255
|
+
application's own, the flush is bounded to 2 s and the signal re-raised.
|
|
256
|
+
A `process.exit()` ends the process before any flush: the spans of its
|
|
257
|
+
last batch interval are lost.
|
|
258
|
+
|
|
259
|
+
## Next.js details
|
|
260
|
+
|
|
261
|
+
`pg`, `mongodb` and `@prisma/client` are external in Next.js by default;
|
|
262
|
+
`postgres` and `drizzle-orm` are bundled unless listed. With
|
|
263
|
+
`serverSourceMaps` the call sites name the original source files; the
|
|
264
|
+
standalone output does not copy the maps, so a Dockerfile that copies
|
|
265
|
+
`.next/standalone` should also copy every `.map` under `.next/server`,
|
|
266
|
+
keeping its path (route chunks, `chunks/ssr/` for server components, and
|
|
267
|
+
`app/**/page.js.map`), or the call sites name positions in the chunk:
|
|
268
|
+
|
|
269
|
+
```dockerfile
|
|
270
|
+
# after copying .next/standalone and .next/static
|
|
271
|
+
COPY --from=builder /app/.next/server /tmp/next-server
|
|
272
|
+
RUN cd /tmp/next-server && find . -name '*.map' -exec cp --parents {} /app/.next/server/ \; && rm -rf /tmp/next-server
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Bundlers
|
|
276
|
+
|
|
277
|
+
An application bundled into one file (esbuild, webpack, Next.js server
|
|
278
|
+
bundles) no longer loads its drivers through `require` or `import`, so
|
|
279
|
+
nothing can patch them. Keep the drivers external (`--packages=external`
|
|
280
|
+
in esbuild, `externals` in webpack, `serverExternalPackages` in Next.js).
|
|
281
|
+
Call sites inside a bundle resolve through its source map when the bundle
|
|
282
|
+
has one. Source maps are read once per file, at most 32 MiB each and
|
|
283
|
+
64 MiB held at once, synchronously the first time a file appears on a
|
|
284
|
+
captured stack.
|
|
285
|
+
|
|
286
|
+
## Development
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
npm install
|
|
290
|
+
npm test # builds, then node:test; docker tests skip without docker
|
|
291
|
+
npm run setup:next # installs the Next.js fixture for its test (once)
|
|
292
|
+
npm run bench # call-site cost, startup and the pg loop
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
The package is not published yet.
|
package/dist/attach.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { rootcatSpanProcessors, startAlongside, type Mode, type Started, type StartOptions } from './sdk.js';
|
package/dist/attach.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startAlongside = exports.rootcatSpanProcessors = void 0;
|
|
4
|
+
// @rootcat/node/attach: Rootcat in an application where another tracer
|
|
5
|
+
// owns the process's OpenTelemetry setup (Sentry 8 and later, an app's
|
|
6
|
+
// own NodeSDK). In the file that sets that tracer up, after it:
|
|
7
|
+
//
|
|
8
|
+
// import { startAlongside } from "@rootcat/node/attach";
|
|
9
|
+
// Sentry.init({ ... });
|
|
10
|
+
// startAlongside();
|
|
11
|
+
//
|
|
12
|
+
// When that tracer records spans (Sentry with tracesSampleRate or
|
|
13
|
+
// tracesSampler, a NodeSDK), its provider also takes the package's
|
|
14
|
+
// processor:
|
|
15
|
+
//
|
|
16
|
+
// import { rootcatSpanProcessors, startAlongside } from "@rootcat/node/attach";
|
|
17
|
+
// Sentry.init({ ..., openTelemetrySpanProcessors: rootcatSpanProcessors() });
|
|
18
|
+
// startAlongside();
|
|
19
|
+
//
|
|
20
|
+
// See coexist.ts for what each case does.
|
|
21
|
+
var sdk_js_1 = require("./sdk.js");
|
|
22
|
+
Object.defineProperty(exports, "rootcatSpanProcessors", { enumerable: true, get: function () { return sdk_js_1.rootcatSpanProcessors; } });
|
|
23
|
+
Object.defineProperty(exports, "startAlongside", { enumerable: true, get: function () { return sdk_js_1.startAlongside; } });
|
|
24
|
+
//# sourceMappingURL=attach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attach.js","sourceRoot":"","sources":["../src/attach.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,uEAAuE;AACvE,gEAAgE;AAChE,EAAE;AACF,2DAA2D;AAC3D,0BAA0B;AAC1B,sBAAsB;AACtB,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,aAAa;AACb,EAAE;AACF,kFAAkF;AAClF,gFAAgF;AAChF,sBAAsB;AACtB,EAAE;AACF,0CAA0C;AAC1C,mCAA6G;AAApG,+GAAA,qBAAqB,OAAA;AAAE,wGAAA,cAAc,OAAA"}
|