@nextdog/sveltekit 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christopher Scherban
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * SvelteKit handle hook types — defined locally to avoid requiring
3
+ * @sveltejs/kit as a build-time dependency (it's a peer dep).
4
+ */
5
+ interface ResolveEvent {
6
+ request: Request;
7
+ url: URL;
8
+ route: {
9
+ id: string | null;
10
+ };
11
+ [key: string]: unknown;
12
+ }
13
+ type MaybePromise<T> = T | Promise<T>;
14
+ type Resolve = (event: ResolveEvent) => MaybePromise<Response>;
15
+ type Handle = (input: {
16
+ event: ResolveEvent;
17
+ resolve: Resolve;
18
+ }) => MaybePromise<Response>;
19
+ export interface NextDogOptions {
20
+ serviceName?: string;
21
+ url?: string;
22
+ }
23
+ export declare function withNextDog(options?: NextDogOptions): Handle;
24
+ export {};
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,UAAU,YAAY;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AACtC,KAAK,OAAO,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC/D,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,KAAK,YAAY,CAAC,QAAQ,CAAC,CAAC;AAE3F,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CA4F5D"}
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ export function withNextDog(options) {
2
+ const url = options?.url ?? process.env.NEXTDOG_URL ?? 'http://localhost:6789';
3
+ const serviceName = options?.serviceName ?? process.env.NEXTDOG_SERVICE_NAME ?? 'nextdog-app';
4
+ // Set when the configured port is held by a non-NextDog process; we then skip
5
+ // all telemetry so we never ship it to an unknown local process (issue #17).
6
+ let disabled = false;
7
+ // The init runs exactly once. We cache the in-flight promise so concurrent
8
+ // first-window requests await the SAME setup rather than racing past a flag
9
+ // that was flipped before setup completed.
10
+ let initPromise;
11
+ async function init() {
12
+ const { NodeTracerProvider, BatchSpanProcessor } = await import('@opentelemetry/sdk-trace-node');
13
+ const { Resource } = await import('@opentelemetry/resources');
14
+ const { ATTR_SERVICE_NAME } = await import('@opentelemetry/semantic-conventions');
15
+ const { NextDogExporter } = await import('@nextdog/node/exporter');
16
+ const { ensureSidecar } = await import('@nextdog/node/sidecar');
17
+ const { patchConsole } = await import('@nextdog/node/console-patch');
18
+ const { startRequestCapture } = await import('@nextdog/node/request-capture');
19
+ const { registerInstrumentations } = await import('@nextdog/node/instrumentation');
20
+ const status = await ensureSidecar(url);
21
+ if (status.foreignOccupant) {
22
+ // ensureSidecar already warned. Disable instrumentation for this process.
23
+ disabled = true;
24
+ return;
25
+ }
26
+ const provider = new NodeTracerProvider({
27
+ resource: new Resource({ [ATTR_SERVICE_NAME]: serviceName }),
28
+ spanProcessors: [new BatchSpanProcessor(new NextDogExporter(url))],
29
+ });
30
+ provider.register();
31
+ patchConsole(url, serviceName);
32
+ startRequestCapture();
33
+ // Auto-instrument outbound fetch/HTTP (#4) and DB queries (#5).
34
+ registerInstrumentations();
35
+ console.log(`[nextdog] sveltekit instrumentation registered for "${serviceName}" → ${url}`);
36
+ }
37
+ return async ({ event, resolve }) => {
38
+ if (process.env.NODE_ENV === 'production' || disabled) {
39
+ return resolve(event);
40
+ }
41
+ // Start init once; all concurrent first-window requests await the SAME
42
+ // promise, so none reach startActiveSpan before the provider/fetch-wrap
43
+ // exist. If init throws, clear the cache so a later request can retry.
44
+ if (!initPromise) {
45
+ initPromise = init().catch((err) => {
46
+ initPromise = undefined;
47
+ throw err;
48
+ });
49
+ }
50
+ await initPromise;
51
+ // A foreign occupant was detected during setup → skip telemetry.
52
+ if (disabled) {
53
+ return resolve(event);
54
+ }
55
+ const { trace } = await import('@opentelemetry/api');
56
+ const tracer = trace.getTracer('nextdog-sveltekit');
57
+ return tracer.startActiveSpan(`${event.request.method} ${event.url.pathname}`, async (span) => {
58
+ try {
59
+ span.setAttribute('http.method', event.request.method);
60
+ span.setAttribute('http.route', event.route?.id ?? event.url.pathname);
61
+ span.setAttribute('http.target', event.url.pathname);
62
+ const response = await resolve(event);
63
+ span.setAttribute('http.status_code', response.status);
64
+ if (response.status >= 400) {
65
+ span.setStatus({ code: 2 }); // ERROR
66
+ }
67
+ return response;
68
+ }
69
+ catch (err) {
70
+ span.setStatus({ code: 2, message: err.message });
71
+ throw err;
72
+ }
73
+ finally {
74
+ span.end();
75
+ }
76
+ });
77
+ };
78
+ }
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,WAAW,CAAC,OAAwB;IAClD,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,uBAAuB,CAAC;IAC/E,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,aAAa,CAAC;IAE9F,8EAA8E;IAC9E,6EAA6E;IAC7E,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,2EAA2E;IAC3E,4EAA4E;IAC5E,2CAA2C;IAC3C,IAAI,WAAsC,CAAC;IAE3C,KAAK,UAAU,IAAI;QACjB,MAAM,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAC7D,+BAA+B,CAChC,CAAC;QACF,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;QAC9D,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,qCAAqC,CAAC,CAAC;QAClF,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;QACnE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;QAChE,MAA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CAAC,EAAE,OAAO,EAAG,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC7D,MAAM,GAAG,CAAC;YACZ,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
package/dist/vite.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from 'vite';
2
+ export interface NextDogViteOptions {
3
+ serviceName?: string;
4
+ url?: string;
5
+ }
6
+ export declare function nextdog(options?: NextDogViteOptions): Plugin;
7
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAS5D"}
package/dist/vite.js ADDED
@@ -0,0 +1,12 @@
1
+ export function nextdog(options) {
2
+ return {
3
+ name: 'nextdog',
4
+ configResolved(config) {
5
+ if (config.mode === 'production')
6
+ return;
7
+ process.env.NEXTDOG_URL = options?.url ?? 'http://localhost:6789';
8
+ process.env.NEXTDOG_SERVICE_NAME = options?.serviceName ?? 'nextdog-app';
9
+ },
10
+ };
11
+ }
12
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,OAAO,CAAC,OAA4B;IAClD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,cAAc,CAAC,MAAM;YACnB,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY;gBAAE,OAAO;YACzC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,OAAO,EAAE,GAAG,IAAI,uBAAuB,CAAC;YAClE,OAAO,CAAC,GAAG,CAAC,oBAAoB,GAAG,OAAO,EAAE,WAAW,IAAI,aAAa,CAAC;QAC3E,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@nextdog/sveltekit",
3
+ "version": "1.1.1",
4
+ "description": "SvelteKit plugin for NextDog — zero-config dev observability",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
+ },
11
+ "./vite": {
12
+ "import": "./dist/vite.js",
13
+ "types": "./dist/vite.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "@opentelemetry/api": "^1",
24
+ "@opentelemetry/sdk-trace-node": "^1",
25
+ "@opentelemetry/resources": "^1",
26
+ "@opentelemetry/semantic-conventions": "^1",
27
+ "@nextdog/core": "1.1.1",
28
+ "@nextdog/node": "1.1.1"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^25",
32
+ "vite": "^6",
33
+ "vitest": "^3"
34
+ },
35
+ "peerDependencies": {
36
+ "@sveltejs/kit": "^2"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "@sveltejs/kit": {
40
+ "optional": false
41
+ }
42
+ },
43
+ "license": "MIT",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/cscherban/NextDog"
47
+ },
48
+ "keywords": [
49
+ "sveltekit",
50
+ "svelte",
51
+ "observability",
52
+ "tracing",
53
+ "opentelemetry",
54
+ "devtools",
55
+ "instrumentation"
56
+ ],
57
+ "scripts": {
58
+ "build": "tsc",
59
+ "test": "vitest run --passWithNoTests",
60
+ "typecheck": "tsc --noEmit"
61
+ }
62
+ }