@bugsnag/svelte-kit-performance 2.14.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/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # `@bugsnag/svelte-kit-performance`
2
+
3
+ > A svelte kit integration for BugSnag performance
4
+
5
+ ## Usage
6
+
7
+ We recommend initializing BugSnag in a shared `+layout.svelte` component at the top level of your application
8
+
9
+ ```svelte
10
+ <script>
11
+ let { children, data } = $props();
12
+
13
+ import BugsnagPerformance from '@bugsnag/browser-performance'
14
+ import { SvelteKitRoutingProvider } from '@bugsnag/svelte-kit-performance'
15
+ import { beforeNavigate, afterNavigate } from '$app/navigation'
16
+ import { page } from '$app/state'
17
+
18
+ BugsnagPerformance.start({
19
+ apiKey: 'YOUR_API_KEY',
20
+ routingProvider: new SvelteKitRoutingProvider(beforeNavigate, afterNavigate, page.route.id)
21
+ })
22
+ </script>
23
+
24
+ {@render children()}
25
+ ```
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { SvelteKitRoutingProvider } from './svelte-kit-routing-provider.js';
@@ -0,0 +1,32 @@
1
+ import { defaultRouteResolver, onSettle } from '@bugsnag/browser-performance';
2
+
3
+ class SvelteKitRoutingProvider {
4
+ constructor(beforeNavigate, afterNavigate, initialRoute) {
5
+ this.beforeNavigate = beforeNavigate;
6
+ this.afterNavigate = afterNavigate;
7
+ this.currentRoute = initialRoute;
8
+ }
9
+ // resolveRoute is only ever used to get the current route in SvelteKit
10
+ // so we just return the current route and ignore the parameter
11
+ resolveRoute(url) {
12
+ return this.currentRoute || defaultRouteResolver(url);
13
+ }
14
+ listenForRouteChanges(startRouteChangeSpan) {
15
+ this.beforeNavigate(({ to, type }) => {
16
+ const startTime = performance.now();
17
+ const url = to ? to.url : new URL(window.location.href);
18
+ this.currentRoute = to?.route.id ?? this.currentRoute;
19
+ this.currentSpan = startRouteChangeSpan(url, type, { startTime });
20
+ });
21
+ this.afterNavigate(() => {
22
+ onSettle((endTime) => {
23
+ if (this.currentSpan) {
24
+ this.currentSpan.end(endTime);
25
+ this.currentSpan = undefined;
26
+ }
27
+ });
28
+ });
29
+ }
30
+ }
31
+
32
+ export { SvelteKitRoutingProvider };
@@ -0,0 +1,2 @@
1
+ export { SvelteKitRoutingProvider } from './svelte-kit-routing-provider';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA"}
@@ -0,0 +1,14 @@
1
+ import type { RoutingProvider, StartRouteChangeCallback } from '@bugsnag/browser-performance';
2
+ import type { AfterNavigate, BeforeNavigate } from '@sveltejs/kit';
3
+ type NavigateCallback<T> = (callback: (navigation: T) => void) => void;
4
+ export declare class SvelteKitRoutingProvider implements RoutingProvider {
5
+ private beforeNavigate;
6
+ private afterNavigate;
7
+ private currentRoute;
8
+ private currentSpan;
9
+ constructor(beforeNavigate: NavigateCallback<BeforeNavigate>, afterNavigate: NavigateCallback<AfterNavigate>, initialRoute?: string);
10
+ resolveRoute(url: URL): string;
11
+ listenForRouteChanges(startRouteChangeSpan: StartRouteChangeCallback): void;
12
+ }
13
+ export {};
14
+ //# sourceMappingURL=svelte-kit-routing-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svelte-kit-routing-provider.d.ts","sourceRoot":"","sources":["../../lib/svelte-kit-routing-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,eAAe,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AAE9G,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAElE,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,IAAI,KAAK,IAAI,CAAA;AAEtE,qBAAa,wBAAyB,YAAW,eAAe;IAK5D,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,aAAa;IALvB,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,WAAW,CAA6B;gBAGtC,cAAc,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAChD,aAAa,EAAE,gBAAgB,CAAC,aAAa,CAAC,EACtD,YAAY,CAAC,EAAE,MAAM;IAOvB,YAAY,CAAE,GAAG,EAAE,GAAG;IAItB,qBAAqB,CAAE,oBAAoB,EAAE,wBAAwB;CAiBtE"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@bugsnag/svelte-kit-performance",
3
+ "version": "2.14.0",
4
+ "description": "BugSnag performance monitoring for SvelteKit",
5
+ "homepage": "https://www.bugsnag.com/",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/bugsnag/bugsnag-js-performance.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "build": "rollup --config rollup.config.mjs",
16
+ "clean": "rm -rf dist/*"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "!dist/**/*.test.*",
21
+ "!dist/**/*.spec.*"
22
+ ],
23
+ "sideEffects": [
24
+ "**/*.css"
25
+ ],
26
+ "svelte": "./dist/index.js",
27
+ "types": "./dist/types/index.d.ts",
28
+ "type": "module",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/types/index.d.ts",
32
+ "svelte": "./dist/index.js"
33
+ }
34
+ },
35
+ "peerDependencies": {
36
+ "@bugsnag/browser-performance": "^2.13.0",
37
+ "svelte": "^5.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@bugsnag/browser-performance": "^2.14.0",
41
+ "@sveltejs/adapter-auto": "^6.0.0",
42
+ "@sveltejs/kit": "^2.16.0",
43
+ "@sveltejs/package": "^2.0.0",
44
+ "@sveltejs/vite-plugin-svelte": "^5.0.0",
45
+ "publint": "^0.3.2",
46
+ "svelte": "^5.0.0",
47
+ "svelte-check": "^4.0.0",
48
+ "vite": "^6.2.6"
49
+ },
50
+ "keywords": [
51
+ "svelte"
52
+ ]
53
+ }