@watchtowerobservability/node 0.7.5 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/dist/cjs/filter.d.ts +10 -0
- package/dist/cjs/filter.js +45 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/integrations/next-build.d.ts +6 -0
- package/dist/cjs/integrations/next-build.js +25 -1
- package/dist/cjs/integrations/next-tunnel.d.ts +2 -0
- package/dist/cjs/integrations/next-tunnel.js +8 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/filter.d.ts +10 -0
- package/dist/esm/filter.js +42 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +4 -3
- package/dist/esm/integrations/next-build.d.ts +6 -0
- package/dist/esm/integrations/next-build.js +23 -1
- package/dist/esm/integrations/next-tunnel.d.ts +2 -0
- package/dist/esm/integrations/next-tunnel.js +8 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.7 (2026-11-16)
|
|
4
|
+
|
|
5
|
+
- Quieter traces by default: `pg-pool.connect`, bare `BEGIN` / `COMMIT` / `ROLLBACK` statement spans and Express middleware layer spans (`middleware - *`, `expressInit`, `query`) are dropped before export; errored spans are always kept. `noisySpans: true` (or `WT_NOISY_SPANS=1`) keeps them. Your own `spanFilter` still runs on what is left.
|
|
6
|
+
- When the ingest endpoint refuses traces with HTTP 429 (the project's daily quota is spent), the SDK prints one `[watchtower] traces are being dropped: daily quota reached (...)` warning instead of failing silently. The server now answers with a body naming the quota and `Retry-After` until 00:00 UTC.
|
|
7
|
+
- `tunnelHandler` takes `otlpEndpoint` (base URL for `/v1/traces` and `/v1/logs`, default `endpoint`) and logs one warning when the upstream answers 404 for those paths. The edge now serves `/v1/traces` for publishable keys, so the documented single-endpoint tunnel works.
|
|
8
|
+
|
|
9
|
+
## 0.7.6 (2026-11-15)
|
|
10
|
+
|
|
11
|
+
- Next.js: `withWatchtower` now keeps every OpenTelemetry instrumentation package the SDK loads (`instrumentation-http`, `-undici`, `-runtime-node`, `-pg`, `-mysql2`, `-ioredis`) in `serverExternalPackages`. Bundled, they extended an undefined `InstrumentationBase` and a standalone build failed every request with `Class extends value undefined`. A test keeps the list in step with `package.json`.
|
|
12
|
+
- Next.js next to Sentry: when `@sentry/nextjs` or `@sentry/node` is in the app's `package.json` (or `sentry: true`), `withWatchtower` no longer externalises `@opentelemetry/api` and `@opentelemetry/instrumentation`. Sentry's nested OTel copies stay bundled and imported them; externalised, its bundled `HttpInstrumentation` extended `undefined` and every request failed in the instrumentation hook.
|
|
13
|
+
|
|
3
14
|
## 0.7.5 (2026-11-15)
|
|
4
15
|
|
|
5
16
|
- Telemetry that is off is now visible: the `register` preload prints `[watchtower] telemetry is OFF: <reason>` when `WT_INGEST_KEY` is unset or the SDK cannot start, and the first helper call that is dropped (`log`, `observe`, `checkin` ...) prints it once more with the reason.
|
|
@@ -33,8 +44,6 @@
|
|
|
33
44
|
- Behaviour change: datastore `requireParent` now defaults to true only when HTTP server instrumentation is active, so queue workers (BullMQ) record their queries as root spans. `WATCHTOWER_DB_REQUIRE_PARENT=0/1` still overrides.
|
|
34
45
|
- `instrumentPostgres()` logs one warning when `postgres` is installed but `diagnostics_channel.tracingChannel` is unavailable (needs `postgres@>=4`).
|
|
35
46
|
|
|
36
|
-
## 0.7.5
|
|
37
|
-
|
|
38
47
|
- `wt-next-sourcemaps` / `uploadSourcemaps()` send the maps in one `POST /v1/projects/{prj}/artifacts/bundle?release=` request per ~120 MB (tar.gz plus a manifest) instead of one request per map. A server without the bundle route is detected and the batch falls back to the concurrent, gzipped single uploads (429/5xx retried with backoff). The final line is still `{uploaded, skipped, failed}`; a failed map is logged with its reason. Re-posting the same bytes returns 200 and counts as `skipped`.
|
|
39
48
|
|
|
40
49
|
## 0.7.4
|
package/dist/cjs/filter.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
// @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
|
|
2
2
|
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace';
|
|
3
3
|
export declare function filterExporter(inner: SpanExporter, keep: (s: ReadableSpan) => boolean): SpanExporter;
|
|
4
|
+
/**
|
|
5
|
+
* Low-value auto-instrumentation spans dropped by default (`noisySpans: true` keeps them): the `pg-pool.connect` wait, bare
|
|
6
|
+
* `BEGIN` / `COMMIT` / `ROLLBACK` statements, and Express middleware layers (`middleware - *`, `expressInit`, `query`).
|
|
7
|
+
* Errored spans are always kept.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isNoisySpan(s: ReadableSpan): boolean;
|
|
10
|
+
/** Logs once when the ingest endpoint answers 429 (daily quota or rate limit), which the OTLP exporter would otherwise swallow. */
|
|
11
|
+
export declare function quotaWarnExporter(inner: SpanExporter, warn?: (msg: string) => void): SpanExporter;
|
|
12
|
+
/** Test hook: lets the once-only warning fire again. */
|
|
13
|
+
export declare function resetQuotaWarning(): void;
|
package/dist/cjs/filter.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.filterExporter = filterExporter;
|
|
4
|
+
exports.isNoisySpan = isNoisySpan;
|
|
5
|
+
exports.quotaWarnExporter = quotaWarnExporter;
|
|
6
|
+
exports.resetQuotaWarning = resetQuotaWarning;
|
|
4
7
|
function filterExporter(inner, keep) {
|
|
5
8
|
return {
|
|
6
9
|
export(spans, done) {
|
|
@@ -14,3 +17,45 @@ function filterExporter(inner, keep) {
|
|
|
14
17
|
forceFlush: () => inner.forceFlush?.() ?? Promise.resolve(),
|
|
15
18
|
};
|
|
16
19
|
}
|
|
20
|
+
const BRACKET = /^\s*(BEGIN|COMMIT|ROLLBACK)\s*;?\s*$/i;
|
|
21
|
+
const BRACKET_NAME = /^(pg\.query:)?(BEGIN|COMMIT|ROLLBACK)$/i;
|
|
22
|
+
const EXPRESS_LAYER = /^(middleware - |router - )?(query|expressInit)$/;
|
|
23
|
+
/**
|
|
24
|
+
* Low-value auto-instrumentation spans dropped by default (`noisySpans: true` keeps them): the `pg-pool.connect` wait, bare
|
|
25
|
+
* `BEGIN` / `COMMIT` / `ROLLBACK` statements, and Express middleware layers (`middleware - *`, `expressInit`, `query`).
|
|
26
|
+
* Errored spans are always kept.
|
|
27
|
+
*/
|
|
28
|
+
function isNoisySpan(s) {
|
|
29
|
+
if (s.status.code === 2)
|
|
30
|
+
return false; // SpanStatusCode.ERROR
|
|
31
|
+
const name = s.name;
|
|
32
|
+
if (name === 'pg-pool.connect')
|
|
33
|
+
return true;
|
|
34
|
+
const stmt = s.attributes['db.query.text'] ?? s.attributes['db.statement'];
|
|
35
|
+
if (typeof stmt === 'string' ? BRACKET.test(stmt) : BRACKET_NAME.test(name))
|
|
36
|
+
return true;
|
|
37
|
+
return name.startsWith('middleware - ') || s.attributes['express.type'] === 'middleware' || EXPRESS_LAYER.test(name);
|
|
38
|
+
}
|
|
39
|
+
let quotaWarned = false;
|
|
40
|
+
/** Logs once when the ingest endpoint answers 429 (daily quota or rate limit), which the OTLP exporter would otherwise swallow. */
|
|
41
|
+
function quotaWarnExporter(inner, warn = (m) => console.warn(m)) {
|
|
42
|
+
return {
|
|
43
|
+
export(spans, done) {
|
|
44
|
+
inner.export(spans, (r) => {
|
|
45
|
+
const e = r.error;
|
|
46
|
+
if (!quotaWarned && e && (e.code === 429 || /\b429\b|daily quota/.test(`${e.message} ${e.data ?? ''}`))) {
|
|
47
|
+
quotaWarned = true;
|
|
48
|
+
const why = /daily quota reached[^"\n]*/.exec(`${e.data ?? ''} ${e.message}`)?.[0] ?? 'ingest answered 429, usually the daily quota; check GET /v1/projects/{prj}/settings/quotas';
|
|
49
|
+
warn(`[watchtower] traces are being dropped: daily quota reached (${why})`);
|
|
50
|
+
}
|
|
51
|
+
done(r);
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
shutdown: () => inner.shutdown(),
|
|
55
|
+
forceFlush: () => inner.forceFlush?.() ?? Promise.resolve(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Test hook: lets the once-only warning fire again. */
|
|
59
|
+
function resetQuotaWarning() {
|
|
60
|
+
quotaWarned = false;
|
|
61
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -96,6 +96,12 @@ export interface InitOptions {
|
|
|
96
96
|
otel?: 'auto' | 'own' | 'attach';
|
|
97
97
|
/** Return false to drop a finished span before export (the `/next` entry uses it for `nextInternals`). */
|
|
98
98
|
spanFilter?: (span: ReadableSpan) => boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Keep the low-value auto-instrumentation spans that are dropped by default: `pg-pool.connect`, bare `BEGIN` / `COMMIT` /
|
|
101
|
+
* `ROLLBACK` statements and Express middleware layers (`middleware - *`, `expressInit`, `query`). Errored spans are always kept.
|
|
102
|
+
* Default false; `WT_NOISY_SPANS=1` sets it.
|
|
103
|
+
*/
|
|
104
|
+
noisySpans?: boolean;
|
|
99
105
|
/**
|
|
100
106
|
* Next.js's own spans (`next.span_type` set: load route module, prepare route module, resolve page components, start
|
|
101
107
|
* response, middleware, generateMetadata ...), root ones included. `"sample"` keeps `nextInternalsRate` of them, `"drop"`
|
package/dist/cjs/index.js
CHANGED
|
@@ -163,8 +163,9 @@ class Client {
|
|
|
163
163
|
if (o.bufferDir)
|
|
164
164
|
exporter = new buffer_js_1.SpoolExporter(exporter, nodePath.join(o.bufferDir, 'traces'), url, this.headers, this.fetch);
|
|
165
165
|
}
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
const keepNoisy = o.noisySpans ?? env.WT_NOISY_SPANS === '1';
|
|
167
|
+
const user = o.spanFilter;
|
|
168
|
+
exporter = (0, filter_js_1.filterExporter)((0, filter_js_1.quotaWarnExporter)(exporter), keepNoisy ? user ?? (() => true) : user ? (s) => !(0, filter_js_1.isNoisySpan)(s) && user(s) : (s) => !(0, filter_js_1.isNoisySpan)(s));
|
|
168
169
|
// the scrubber and redactor run first, so the batch processor exports scrubbed attributes (the user's `redact` sees scrubbed URLs)
|
|
169
170
|
const { BatchSpanProcessor, TracerProvider: TP } = (0, load_js_1.need)('@opentelemetry/sdk-trace');
|
|
170
171
|
let sampler;
|
|
@@ -31,7 +31,13 @@ export interface WatchtowerNextOptions {
|
|
|
31
31
|
});
|
|
32
32
|
/** Release: injected as `NEXT_PUBLIC_WT_RELEASE` (read by `<WatchtowerRUM>`). Default WT_RELEASE, then the git sha of the CI/host env. */
|
|
33
33
|
release?: string;
|
|
34
|
+
/** Sentry is in the app (default: `@sentry/nextjs` or `@sentry/node` in package.json): keep the OTel packages it shares bundled. */
|
|
35
|
+
sentry?: boolean;
|
|
34
36
|
}
|
|
37
|
+
/** Is a Sentry Node/Next SDK installed in the app being built? */
|
|
38
|
+
export declare function hasSentry(cwd?: string): boolean;
|
|
39
|
+
/** The `serverExternalPackages` withWatchtower adds; `sentry` drops the packages a bundled Sentry shares. */
|
|
40
|
+
export declare function externalPackages(sentry: boolean): string[];
|
|
35
41
|
/**
|
|
36
42
|
* `module.exports = withWatchtower(nextConfig, { sourcemaps: true })`. Makes `output: 'standalone'` work with no other
|
|
37
43
|
* config: the node SDK and its OpenTelemetry peers go into `serverExternalPackages` and (npm and pnpm layouts) into
|
|
@@ -33,6 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.hasSentry = hasSentry;
|
|
37
|
+
exports.externalPackages = externalPackages;
|
|
36
38
|
exports.withWatchtower = withWatchtower;
|
|
37
39
|
exports.makeTar = makeTar;
|
|
38
40
|
exports.uploadSourcemaps = uploadSourcemaps;
|
|
@@ -45,10 +47,32 @@ const next_debugid_js_1 = require("./next-debugid.js");
|
|
|
45
47
|
const OTEL = [
|
|
46
48
|
'@opentelemetry/api', '@opentelemetry/context-async-hooks', '@opentelemetry/core', '@opentelemetry/exporter-logs-otlp-http',
|
|
47
49
|
'@opentelemetry/exporter-metrics-otlp-http', '@opentelemetry/exporter-trace-otlp-http', '@opentelemetry/instrumentation',
|
|
50
|
+
// every instrumentation too, so none of ours is bundled against an external base class
|
|
51
|
+
'@opentelemetry/instrumentation-http', '@opentelemetry/instrumentation-ioredis', '@opentelemetry/instrumentation-mysql2',
|
|
52
|
+
'@opentelemetry/instrumentation-pg', '@opentelemetry/instrumentation-runtime-node', '@opentelemetry/instrumentation-undici',
|
|
48
53
|
'@opentelemetry/otlp-transformer', '@opentelemetry/resources', '@opentelemetry/sdk-logs', '@opentelemetry/sdk-metrics',
|
|
49
54
|
'@opentelemetry/sdk-trace',
|
|
50
55
|
];
|
|
51
56
|
const EXTERNAL = ['@watchtowerobservability/node', ...OTEL];
|
|
57
|
+
// Packages Sentry's own nested OTel copies import. Sentry stays bundled, so externalising these made its bundled
|
|
58
|
+
// `HttpInstrumentation` extend an `InstrumentationBase` that resolved to undefined (B9b). With Sentry present they stay
|
|
59
|
+
// bundled for Sentry, while ours (external) still resolve them from node_modules at run time.
|
|
60
|
+
const SHARED_WITH_SENTRY = new Set(['@opentelemetry/api', '@opentelemetry/instrumentation']);
|
|
61
|
+
/** Is a Sentry Node/Next SDK installed in the app being built? */
|
|
62
|
+
function hasSentry(cwd = process.cwd()) {
|
|
63
|
+
try {
|
|
64
|
+
const pkg = JSON.parse(fs.readFileSync(nodePath.join(cwd, 'package.json'), 'utf8'));
|
|
65
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
66
|
+
return Object.keys(deps).some((n) => n === '@sentry/nextjs' || n === '@sentry/node');
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** The `serverExternalPackages` withWatchtower adds; `sentry` drops the packages a bundled Sentry shares. */
|
|
73
|
+
function externalPackages(sentry) {
|
|
74
|
+
return sentry ? EXTERNAL.filter((n) => !SHARED_WITH_SENTRY.has(n)) : EXTERNAL;
|
|
75
|
+
}
|
|
52
76
|
const SHA_ENV = ['WT_RELEASE', 'GITHUB_SHA', 'CI_COMMIT_SHA', 'VERCEL_GIT_COMMIT_SHA', 'SOURCE_VERSION', 'BUILD_SHA', 'RENDER_GIT_COMMIT', 'HEROKU_SLUG_COMMIT'];
|
|
53
77
|
const INCLUDE = ['@watchtowerobservability/node', '@opentelemetry'].flatMap((p) => [`./node_modules/${p}/**/*`, `./node_modules/.pnpm/${p.replace('/', '+')}*/**/*`]);
|
|
54
78
|
/**
|
|
@@ -66,7 +90,7 @@ function withWatchtower(config = {}, opts = {}) {
|
|
|
66
90
|
inc['/*'] = [...new Set([...(inc['/*'] ?? []), ...INCLUDE])];
|
|
67
91
|
const out = {
|
|
68
92
|
...c,
|
|
69
|
-
serverExternalPackages: [...new Set([...(c.serverExternalPackages ?? []), ...
|
|
93
|
+
serverExternalPackages: [...new Set([...(c.serverExternalPackages ?? []), ...externalPackages(opts.sentry ?? hasSentry())])],
|
|
70
94
|
outputFileTracingIncludes: inc,
|
|
71
95
|
};
|
|
72
96
|
if (release)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface TunnelOptions {
|
|
2
2
|
/** Edge base URL the requests are forwarded to. */
|
|
3
3
|
endpoint: string;
|
|
4
|
+
/** Base URL for `/v1/traces` and `/v1/logs` (for example the ingest host); default: `endpoint`. */
|
|
5
|
+
otlpEndpoint?: string;
|
|
4
6
|
/** Route prefix to strip; default `/api/wt`. */
|
|
5
7
|
basePath?: string;
|
|
6
8
|
/** Request body cap in bytes; default 1 MiB (over it: 413). */
|
|
@@ -15,7 +15,9 @@ function tunnelHandler(o) {
|
|
|
15
15
|
const max = o.maxBodyBytes ?? 1024 * 1024;
|
|
16
16
|
const edge = o.endpoint.replace(/\/+$/, '');
|
|
17
17
|
const allow = o.allowKey === undefined ? [] : [].concat(o.allowKey);
|
|
18
|
+
const otlp = (o.otlpEndpoint ?? o.endpoint).replace(/\/+$/, '');
|
|
18
19
|
const send = o.fetch ?? fetch;
|
|
20
|
+
let warned = false;
|
|
19
21
|
const handle = async (req) => {
|
|
20
22
|
const url = new URL(req.url);
|
|
21
23
|
const path = url.pathname.startsWith(base) ? url.pathname.slice(base.length) : url.pathname;
|
|
@@ -48,7 +50,12 @@ function tunnelHandler(o) {
|
|
|
48
50
|
return new Response('payload too large', { status: 413 });
|
|
49
51
|
}
|
|
50
52
|
try {
|
|
51
|
-
const
|
|
53
|
+
const isOtlp = path === '/v1/traces' || path === '/v1/logs';
|
|
54
|
+
const res = await send(`${isOtlp ? otlp : edge}${path}${k ? `?k=${encodeURIComponent(k)}` : ''}`, { method: req.method, headers, body });
|
|
55
|
+
if (isOtlp && res.status === 404 && !warned) {
|
|
56
|
+
warned = true; // once per process: a 404 here drops every browser span silently
|
|
57
|
+
console.warn(`[watchtower] tunnel: ${isOtlp ? otlp : edge}${path} answered 404; upgrade the edge or set tunnelHandler({ otlpEndpoint })`);
|
|
58
|
+
}
|
|
52
59
|
const out = new Headers();
|
|
53
60
|
const ct = res.headers.get('content-type');
|
|
54
61
|
if (ct)
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** This package's version (test/distro.test.ts checks it against package.json); sent as `telemetry.distro.version`. */
|
|
2
|
-
export declare const VERSION = "0.7.
|
|
2
|
+
export declare const VERSION = "0.7.7";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/filter.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
// @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
|
|
2
2
|
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace';
|
|
3
3
|
export declare function filterExporter(inner: SpanExporter, keep: (s: ReadableSpan) => boolean): SpanExporter;
|
|
4
|
+
/**
|
|
5
|
+
* Low-value auto-instrumentation spans dropped by default (`noisySpans: true` keeps them): the `pg-pool.connect` wait, bare
|
|
6
|
+
* `BEGIN` / `COMMIT` / `ROLLBACK` statements, and Express middleware layers (`middleware - *`, `expressInit`, `query`).
|
|
7
|
+
* Errored spans are always kept.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isNoisySpan(s: ReadableSpan): boolean;
|
|
10
|
+
/** Logs once when the ingest endpoint answers 429 (daily quota or rate limit), which the OTLP exporter would otherwise swallow. */
|
|
11
|
+
export declare function quotaWarnExporter(inner: SpanExporter, warn?: (msg: string) => void): SpanExporter;
|
|
12
|
+
/** Test hook: lets the once-only warning fire again. */
|
|
13
|
+
export declare function resetQuotaWarning(): void;
|
package/dist/esm/filter.js
CHANGED
|
@@ -11,3 +11,45 @@ export function filterExporter(inner, keep) {
|
|
|
11
11
|
forceFlush: () => inner.forceFlush?.() ?? Promise.resolve(),
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
const BRACKET = /^\s*(BEGIN|COMMIT|ROLLBACK)\s*;?\s*$/i;
|
|
15
|
+
const BRACKET_NAME = /^(pg\.query:)?(BEGIN|COMMIT|ROLLBACK)$/i;
|
|
16
|
+
const EXPRESS_LAYER = /^(middleware - |router - )?(query|expressInit)$/;
|
|
17
|
+
/**
|
|
18
|
+
* Low-value auto-instrumentation spans dropped by default (`noisySpans: true` keeps them): the `pg-pool.connect` wait, bare
|
|
19
|
+
* `BEGIN` / `COMMIT` / `ROLLBACK` statements, and Express middleware layers (`middleware - *`, `expressInit`, `query`).
|
|
20
|
+
* Errored spans are always kept.
|
|
21
|
+
*/
|
|
22
|
+
export function isNoisySpan(s) {
|
|
23
|
+
if (s.status.code === 2)
|
|
24
|
+
return false; // SpanStatusCode.ERROR
|
|
25
|
+
const name = s.name;
|
|
26
|
+
if (name === 'pg-pool.connect')
|
|
27
|
+
return true;
|
|
28
|
+
const stmt = s.attributes['db.query.text'] ?? s.attributes['db.statement'];
|
|
29
|
+
if (typeof stmt === 'string' ? BRACKET.test(stmt) : BRACKET_NAME.test(name))
|
|
30
|
+
return true;
|
|
31
|
+
return name.startsWith('middleware - ') || s.attributes['express.type'] === 'middleware' || EXPRESS_LAYER.test(name);
|
|
32
|
+
}
|
|
33
|
+
let quotaWarned = false;
|
|
34
|
+
/** Logs once when the ingest endpoint answers 429 (daily quota or rate limit), which the OTLP exporter would otherwise swallow. */
|
|
35
|
+
export function quotaWarnExporter(inner, warn = (m) => console.warn(m)) {
|
|
36
|
+
return {
|
|
37
|
+
export(spans, done) {
|
|
38
|
+
inner.export(spans, (r) => {
|
|
39
|
+
const e = r.error;
|
|
40
|
+
if (!quotaWarned && e && (e.code === 429 || /\b429\b|daily quota/.test(`${e.message} ${e.data ?? ''}`))) {
|
|
41
|
+
quotaWarned = true;
|
|
42
|
+
const why = /daily quota reached[^"\n]*/.exec(`${e.data ?? ''} ${e.message}`)?.[0] ?? 'ingest answered 429, usually the daily quota; check GET /v1/projects/{prj}/settings/quotas';
|
|
43
|
+
warn(`[watchtower] traces are being dropped: daily quota reached (${why})`);
|
|
44
|
+
}
|
|
45
|
+
done(r);
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
shutdown: () => inner.shutdown(),
|
|
49
|
+
forceFlush: () => inner.forceFlush?.() ?? Promise.resolve(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Test hook: lets the once-only warning fire again. */
|
|
53
|
+
export function resetQuotaWarning() {
|
|
54
|
+
quotaWarned = false;
|
|
55
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -96,6 +96,12 @@ export interface InitOptions {
|
|
|
96
96
|
otel?: 'auto' | 'own' | 'attach';
|
|
97
97
|
/** Return false to drop a finished span before export (the `/next` entry uses it for `nextInternals`). */
|
|
98
98
|
spanFilter?: (span: ReadableSpan) => boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Keep the low-value auto-instrumentation spans that are dropped by default: `pg-pool.connect`, bare `BEGIN` / `COMMIT` /
|
|
101
|
+
* `ROLLBACK` statements and Express middleware layers (`middleware - *`, `expressInit`, `query`). Errored spans are always kept.
|
|
102
|
+
* Default false; `WT_NOISY_SPANS=1` sets it.
|
|
103
|
+
*/
|
|
104
|
+
noisySpans?: boolean;
|
|
99
105
|
/**
|
|
100
106
|
* Next.js's own spans (`next.span_type` set: load route module, prepare route module, resolve page components, start
|
|
101
107
|
* response, middleware, generateMetadata ...), root ones included. `"sample"` keeps `nextInternalsRate` of them, `"drop"`
|
package/dist/esm/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { LOG_BODY_KEY, redactor } from './redact.js';
|
|
|
10
10
|
import { resolveRedact } from './redact-presets.js';
|
|
11
11
|
import { foreignProvider, attachProcessors } from './attach.js';
|
|
12
12
|
import { scrubUrl, urlScrubber } from './scrub.js';
|
|
13
|
-
import { filterExporter } from './filter.js';
|
|
13
|
+
import { filterExporter, isNoisySpan, quotaWarnExporter } from './filter.js';
|
|
14
14
|
import { nextInternalsFilter } from './next-filter.js';
|
|
15
15
|
import { checkin as runCheckin } from './checkin.js';
|
|
16
16
|
import { checkIn as checkInFor, withMonitor as withMonitorFor } from './cron/monitor.js';
|
|
@@ -116,8 +116,9 @@ export class Client {
|
|
|
116
116
|
if (o.bufferDir)
|
|
117
117
|
exporter = new SpoolExporter(exporter, nodePath.join(o.bufferDir, 'traces'), url, this.headers, this.fetch);
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
const keepNoisy = o.noisySpans ?? env.WT_NOISY_SPANS === '1';
|
|
120
|
+
const user = o.spanFilter;
|
|
121
|
+
exporter = filterExporter(quotaWarnExporter(exporter), keepNoisy ? user ?? (() => true) : user ? (s) => !isNoisySpan(s) && user(s) : (s) => !isNoisySpan(s));
|
|
121
122
|
// the scrubber and redactor run first, so the batch processor exports scrubbed attributes (the user's `redact` sees scrubbed URLs)
|
|
122
123
|
const { BatchSpanProcessor, TracerProvider: TP } = needPeer('@opentelemetry/sdk-trace');
|
|
123
124
|
let sampler;
|
|
@@ -31,7 +31,13 @@ export interface WatchtowerNextOptions {
|
|
|
31
31
|
});
|
|
32
32
|
/** Release: injected as `NEXT_PUBLIC_WT_RELEASE` (read by `<WatchtowerRUM>`). Default WT_RELEASE, then the git sha of the CI/host env. */
|
|
33
33
|
release?: string;
|
|
34
|
+
/** Sentry is in the app (default: `@sentry/nextjs` or `@sentry/node` in package.json): keep the OTel packages it shares bundled. */
|
|
35
|
+
sentry?: boolean;
|
|
34
36
|
}
|
|
37
|
+
/** Is a Sentry Node/Next SDK installed in the app being built? */
|
|
38
|
+
export declare function hasSentry(cwd?: string): boolean;
|
|
39
|
+
/** The `serverExternalPackages` withWatchtower adds; `sentry` drops the packages a bundled Sentry shares. */
|
|
40
|
+
export declare function externalPackages(sentry: boolean): string[];
|
|
35
41
|
/**
|
|
36
42
|
* `module.exports = withWatchtower(nextConfig, { sourcemaps: true })`. Makes `output: 'standalone'` work with no other
|
|
37
43
|
* config: the node SDK and its OpenTelemetry peers go into `serverExternalPackages` and (npm and pnpm layouts) into
|
|
@@ -7,10 +7,32 @@ import { injectDebugIds } from './next-debugid.js';
|
|
|
7
7
|
const OTEL = [
|
|
8
8
|
'@opentelemetry/api', '@opentelemetry/context-async-hooks', '@opentelemetry/core', '@opentelemetry/exporter-logs-otlp-http',
|
|
9
9
|
'@opentelemetry/exporter-metrics-otlp-http', '@opentelemetry/exporter-trace-otlp-http', '@opentelemetry/instrumentation',
|
|
10
|
+
// every instrumentation too, so none of ours is bundled against an external base class
|
|
11
|
+
'@opentelemetry/instrumentation-http', '@opentelemetry/instrumentation-ioredis', '@opentelemetry/instrumentation-mysql2',
|
|
12
|
+
'@opentelemetry/instrumentation-pg', '@opentelemetry/instrumentation-runtime-node', '@opentelemetry/instrumentation-undici',
|
|
10
13
|
'@opentelemetry/otlp-transformer', '@opentelemetry/resources', '@opentelemetry/sdk-logs', '@opentelemetry/sdk-metrics',
|
|
11
14
|
'@opentelemetry/sdk-trace',
|
|
12
15
|
];
|
|
13
16
|
const EXTERNAL = ['@watchtowerobservability/node', ...OTEL];
|
|
17
|
+
// Packages Sentry's own nested OTel copies import. Sentry stays bundled, so externalising these made its bundled
|
|
18
|
+
// `HttpInstrumentation` extend an `InstrumentationBase` that resolved to undefined (B9b). With Sentry present they stay
|
|
19
|
+
// bundled for Sentry, while ours (external) still resolve them from node_modules at run time.
|
|
20
|
+
const SHARED_WITH_SENTRY = new Set(['@opentelemetry/api', '@opentelemetry/instrumentation']);
|
|
21
|
+
/** Is a Sentry Node/Next SDK installed in the app being built? */
|
|
22
|
+
export function hasSentry(cwd = process.cwd()) {
|
|
23
|
+
try {
|
|
24
|
+
const pkg = JSON.parse(fs.readFileSync(nodePath.join(cwd, 'package.json'), 'utf8'));
|
|
25
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
26
|
+
return Object.keys(deps).some((n) => n === '@sentry/nextjs' || n === '@sentry/node');
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The `serverExternalPackages` withWatchtower adds; `sentry` drops the packages a bundled Sentry shares. */
|
|
33
|
+
export function externalPackages(sentry) {
|
|
34
|
+
return sentry ? EXTERNAL.filter((n) => !SHARED_WITH_SENTRY.has(n)) : EXTERNAL;
|
|
35
|
+
}
|
|
14
36
|
const SHA_ENV = ['WT_RELEASE', 'GITHUB_SHA', 'CI_COMMIT_SHA', 'VERCEL_GIT_COMMIT_SHA', 'SOURCE_VERSION', 'BUILD_SHA', 'RENDER_GIT_COMMIT', 'HEROKU_SLUG_COMMIT'];
|
|
15
37
|
const INCLUDE = ['@watchtowerobservability/node', '@opentelemetry'].flatMap((p) => [`./node_modules/${p}/**/*`, `./node_modules/.pnpm/${p.replace('/', '+')}*/**/*`]);
|
|
16
38
|
/**
|
|
@@ -28,7 +50,7 @@ export function withWatchtower(config = {}, opts = {}) {
|
|
|
28
50
|
inc['/*'] = [...new Set([...(inc['/*'] ?? []), ...INCLUDE])];
|
|
29
51
|
const out = {
|
|
30
52
|
...c,
|
|
31
|
-
serverExternalPackages: [...new Set([...(c.serverExternalPackages ?? []), ...
|
|
53
|
+
serverExternalPackages: [...new Set([...(c.serverExternalPackages ?? []), ...externalPackages(opts.sentry ?? hasSentry())])],
|
|
32
54
|
outputFileTracingIncludes: inc,
|
|
33
55
|
};
|
|
34
56
|
if (release)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface TunnelOptions {
|
|
2
2
|
/** Edge base URL the requests are forwarded to. */
|
|
3
3
|
endpoint: string;
|
|
4
|
+
/** Base URL for `/v1/traces` and `/v1/logs` (for example the ingest host); default: `endpoint`. */
|
|
5
|
+
otlpEndpoint?: string;
|
|
4
6
|
/** Route prefix to strip; default `/api/wt`. */
|
|
5
7
|
basePath?: string;
|
|
6
8
|
/** Request body cap in bytes; default 1 MiB (over it: 413). */
|
|
@@ -12,7 +12,9 @@ export function tunnelHandler(o) {
|
|
|
12
12
|
const max = o.maxBodyBytes ?? 1024 * 1024;
|
|
13
13
|
const edge = o.endpoint.replace(/\/+$/, '');
|
|
14
14
|
const allow = o.allowKey === undefined ? [] : [].concat(o.allowKey);
|
|
15
|
+
const otlp = (o.otlpEndpoint ?? o.endpoint).replace(/\/+$/, '');
|
|
15
16
|
const send = o.fetch ?? fetch;
|
|
17
|
+
let warned = false;
|
|
16
18
|
const handle = async (req) => {
|
|
17
19
|
const url = new URL(req.url);
|
|
18
20
|
const path = url.pathname.startsWith(base) ? url.pathname.slice(base.length) : url.pathname;
|
|
@@ -45,7 +47,12 @@ export function tunnelHandler(o) {
|
|
|
45
47
|
return new Response('payload too large', { status: 413 });
|
|
46
48
|
}
|
|
47
49
|
try {
|
|
48
|
-
const
|
|
50
|
+
const isOtlp = path === '/v1/traces' || path === '/v1/logs';
|
|
51
|
+
const res = await send(`${isOtlp ? otlp : edge}${path}${k ? `?k=${encodeURIComponent(k)}` : ''}`, { method: req.method, headers, body });
|
|
52
|
+
if (isOtlp && res.status === 404 && !warned) {
|
|
53
|
+
warned = true; // once per process: a 404 here drops every browser span silently
|
|
54
|
+
console.warn(`[watchtower] tunnel: ${isOtlp ? otlp : edge}${path} answered 404; upgrade the edge or set tunnelHandler({ otlpEndpoint })`);
|
|
55
|
+
}
|
|
49
56
|
const out = new Headers();
|
|
50
57
|
const ct = res.headers.get('content-type');
|
|
51
58
|
if (ct)
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** This package's version (test/distro.test.ts checks it against package.json); sent as `telemetry.distro.version`. */
|
|
2
|
-
export declare const VERSION = "0.7.
|
|
2
|
+
export declare const VERSION = "0.7.7";
|
package/dist/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** This package's version (test/distro.test.ts checks it against package.json); sent as `telemetry.distro.version`. */
|
|
2
|
-
export const VERSION = '0.7.
|
|
2
|
+
export const VERSION = '0.7.7';
|