@aiolaapp/logger 0.1.1 → 0.1.3
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/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/node.d.mts +4 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.js +2 -2
- package/dist/node.mjs +2 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -28,6 +28,7 @@ interface StackFrame {
|
|
|
28
28
|
lineno: number;
|
|
29
29
|
colno?: number;
|
|
30
30
|
in_app?: boolean;
|
|
31
|
+
source_mapped?: boolean;
|
|
31
32
|
}
|
|
32
33
|
interface Breadcrumb {
|
|
33
34
|
timestamp: string;
|
|
@@ -95,6 +96,7 @@ declare class AiolaClient {
|
|
|
95
96
|
captureException(error: unknown, extra?: {
|
|
96
97
|
tags?: Record<string, string>;
|
|
97
98
|
level?: LogEvent["level"];
|
|
99
|
+
request?: LogEvent["request"];
|
|
98
100
|
}): void;
|
|
99
101
|
/** Capture a plain message */
|
|
100
102
|
captureMessage(message: string, level?: LogEvent["level"], tags?: Record<string, string>): void;
|
|
@@ -119,6 +121,8 @@ declare class AiolaClient {
|
|
|
119
121
|
wrapRouteHandler<T extends (...args: unknown[]) => unknown>(handler: T): T;
|
|
120
122
|
/** Wrap a server action to auto-capture errors */
|
|
121
123
|
wrapServerAction<T extends (...args: unknown[]) => unknown>(action: T): T;
|
|
124
|
+
/** Extract request context from a Request-like object (Next.js, Fetch API, Express) */
|
|
125
|
+
private _extractRequestContext;
|
|
122
126
|
private _buildEvent;
|
|
123
127
|
private _send;
|
|
124
128
|
/** Instrument console — breadcrumbs for all, promote console.error to real errors */
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ interface StackFrame {
|
|
|
28
28
|
lineno: number;
|
|
29
29
|
colno?: number;
|
|
30
30
|
in_app?: boolean;
|
|
31
|
+
source_mapped?: boolean;
|
|
31
32
|
}
|
|
32
33
|
interface Breadcrumb {
|
|
33
34
|
timestamp: string;
|
|
@@ -95,6 +96,7 @@ declare class AiolaClient {
|
|
|
95
96
|
captureException(error: unknown, extra?: {
|
|
96
97
|
tags?: Record<string, string>;
|
|
97
98
|
level?: LogEvent["level"];
|
|
99
|
+
request?: LogEvent["request"];
|
|
98
100
|
}): void;
|
|
99
101
|
/** Capture a plain message */
|
|
100
102
|
captureMessage(message: string, level?: LogEvent["level"], tags?: Record<string, string>): void;
|
|
@@ -119,6 +121,8 @@ declare class AiolaClient {
|
|
|
119
121
|
wrapRouteHandler<T extends (...args: unknown[]) => unknown>(handler: T): T;
|
|
120
122
|
/** Wrap a server action to auto-capture errors */
|
|
121
123
|
wrapServerAction<T extends (...args: unknown[]) => unknown>(action: T): T;
|
|
124
|
+
/** Extract request context from a Request-like object (Next.js, Fetch API, Express) */
|
|
125
|
+
private _extractRequestContext;
|
|
122
126
|
private _buildEvent;
|
|
123
127
|
private _send;
|
|
124
128
|
/** Instrument console — breadcrumbs for all, promote console.error to real errors */
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);for(let n of
|
|
1
|
+
"use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var v=(o,e)=>{for(var t in e)d(o,t,{get:e[t],enumerable:!0})},E=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of w(e))!y.call(o,r)&&r!==t&&d(o,r,{get:()=>e[r],enumerable:!(n=g(e,r))||n.enumerable});return o};var b=o=>E(d({},"__esModule",{value:!0}),o);var q={};v(q,{Aiola:()=>R});module.exports=b(q);var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,r){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:r,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(r,s){let i=typeof r=="string"?r:r instanceof URL?r.href:r.url,u=s?.method||"GET";if(e&&i.includes(e))return t.apply(globalThis,[r,s]);let h=Date.now();return t.apply(globalThis,[r,s]).then(c=>(n.add("http",`${u} ${i}`,{status_code:c.status,duration_ms:Date.now()-h}),c),c=>{throw n.add("http",`${u} ${i} (failed)`,{error:String(c),duration_ms:Date.now()-h},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,r=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(s,i){return this._clawMethod=s,this._clawUrl=typeof i=="string"?i:i.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let s=this;if(e&&s._clawUrl.includes(e))return r.apply(this,arguments);let i=Date.now();return s.addEventListener("loadend",function(){let u=Date.now()-i;s.status>0?t.add("http",`${s._clawMethod} ${s._clawUrl}`,{status_code:s.status,duration_ms:u,type:"xhr"}):t.add("http",`${s._clawMethod} ${s._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),r.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),r=t.textContent?.slice(0,50)?.trim(),s=t.id?`#${t.id}`:"",i=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${s}${i}${r?` "${r}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let s=window.location.href;s!==e&&(this.add("navigation",`${e} \u2192 ${s}`),e=s)};window.addEventListener("popstate",t);let n=history.pushState,r=history.replaceState;history.pushState=function(...s){n.apply(this,s),t()},history.replaceState=function(...s){r.apply(this,s),t()}}};var k=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,_=/^(.+?)@(.+?):(\d+):(\d+)$/;function m(o){let e=[],t=o.split(`
|
|
2
|
+
`);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=k.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")});continue}s=_.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")})}return e}function f(o){return!(!o||o.includes("node_modules")||o.startsWith("node:")||o.includes("internal/")||o.includes("<anonymous>"))}var x="https://aiola.app/api/app-logs/ingest",L="aiola-js",T="0.1.3",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:x,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}this.initialized=!0,this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?m(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let i=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(i)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let i=t._extractRequestContext(n);throw t.captureException(s,{request:i}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:L,sdk_version:T,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var R=new l;0&&(module.exports={Aiola});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);for(let n of t){let
|
|
1
|
+
var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,r){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:r,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(r,s){let o=typeof r=="string"?r:r instanceof URL?r.href:r.url,u=s?.method||"GET";if(e&&o.includes(e))return t.apply(globalThis,[r,s]);let d=Date.now();return t.apply(globalThis,[r,s]).then(c=>(n.add("http",`${u} ${o}`,{status_code:c.status,duration_ms:Date.now()-d}),c),c=>{throw n.add("http",`${u} ${o} (failed)`,{error:String(c),duration_ms:Date.now()-d},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,r=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(s,o){return this._clawMethod=s,this._clawUrl=typeof o=="string"?o:o.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let s=this;if(e&&s._clawUrl.includes(e))return r.apply(this,arguments);let o=Date.now();return s.addEventListener("loadend",function(){let u=Date.now()-o;s.status>0?t.add("http",`${s._clawMethod} ${s._clawUrl}`,{status_code:s.status,duration_ms:u,type:"xhr"}):t.add("http",`${s._clawMethod} ${s._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),r.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),r=t.textContent?.slice(0,50)?.trim(),s=t.id?`#${t.id}`:"",o=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${s}${o}${r?` "${r}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let s=window.location.href;s!==e&&(this.add("navigation",`${e} \u2192 ${s}`),e=s)};window.addEventListener("popstate",t);let n=history.pushState,r=history.replaceState;history.pushState=function(...s){n.apply(this,s),t()},history.replaceState=function(...s){r.apply(this,s),t()}}};var m=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,g=/^(.+?)@(.+?):(\d+):(\d+)$/;function f(i){let e=[],t=i.split(`
|
|
2
|
+
`);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=m.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")});continue}s=g.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")})}return e}function h(i){return!(!i||i.includes("node_modules")||i.startsWith("node:")||i.includes("internal/")||i.includes("<anonymous>"))}var w="https://aiola.app/api/app-logs/ingest",y="aiola-js",v="0.1.3",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:w,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}this.initialized=!0,this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?f(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let o=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(o)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let o=t._extractRequestContext(n);throw t.captureException(s,{request:o}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:y,sdk_version:v,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var q=new l;export{q as Aiola};
|
package/dist/node.d.mts
CHANGED
|
@@ -28,6 +28,7 @@ interface StackFrame {
|
|
|
28
28
|
lineno: number;
|
|
29
29
|
colno?: number;
|
|
30
30
|
in_app?: boolean;
|
|
31
|
+
source_mapped?: boolean;
|
|
31
32
|
}
|
|
32
33
|
interface Breadcrumb {
|
|
33
34
|
timestamp: string;
|
|
@@ -95,6 +96,7 @@ declare class AiolaClient {
|
|
|
95
96
|
captureException(error: unknown, extra?: {
|
|
96
97
|
tags?: Record<string, string>;
|
|
97
98
|
level?: LogEvent["level"];
|
|
99
|
+
request?: LogEvent["request"];
|
|
98
100
|
}): void;
|
|
99
101
|
/** Capture a plain message */
|
|
100
102
|
captureMessage(message: string, level?: LogEvent["level"], tags?: Record<string, string>): void;
|
|
@@ -119,6 +121,8 @@ declare class AiolaClient {
|
|
|
119
121
|
wrapRouteHandler<T extends (...args: unknown[]) => unknown>(handler: T): T;
|
|
120
122
|
/** Wrap a server action to auto-capture errors */
|
|
121
123
|
wrapServerAction<T extends (...args: unknown[]) => unknown>(action: T): T;
|
|
124
|
+
/** Extract request context from a Request-like object (Next.js, Fetch API, Express) */
|
|
125
|
+
private _extractRequestContext;
|
|
122
126
|
private _buildEvent;
|
|
123
127
|
private _send;
|
|
124
128
|
/** Instrument console — breadcrumbs for all, promote console.error to real errors */
|
package/dist/node.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ interface StackFrame {
|
|
|
28
28
|
lineno: number;
|
|
29
29
|
colno?: number;
|
|
30
30
|
in_app?: boolean;
|
|
31
|
+
source_mapped?: boolean;
|
|
31
32
|
}
|
|
32
33
|
interface Breadcrumb {
|
|
33
34
|
timestamp: string;
|
|
@@ -95,6 +96,7 @@ declare class AiolaClient {
|
|
|
95
96
|
captureException(error: unknown, extra?: {
|
|
96
97
|
tags?: Record<string, string>;
|
|
97
98
|
level?: LogEvent["level"];
|
|
99
|
+
request?: LogEvent["request"];
|
|
98
100
|
}): void;
|
|
99
101
|
/** Capture a plain message */
|
|
100
102
|
captureMessage(message: string, level?: LogEvent["level"], tags?: Record<string, string>): void;
|
|
@@ -119,6 +121,8 @@ declare class AiolaClient {
|
|
|
119
121
|
wrapRouteHandler<T extends (...args: unknown[]) => unknown>(handler: T): T;
|
|
120
122
|
/** Wrap a server action to auto-capture errors */
|
|
121
123
|
wrapServerAction<T extends (...args: unknown[]) => unknown>(action: T): T;
|
|
124
|
+
/** Extract request context from a Request-like object (Next.js, Fetch API, Express) */
|
|
125
|
+
private _extractRequestContext;
|
|
122
126
|
private _buildEvent;
|
|
123
127
|
private _send;
|
|
124
128
|
/** Instrument console — breadcrumbs for all, promote console.error to real errors */
|
package/dist/node.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);for(let n of
|
|
1
|
+
"use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var E=(o,e)=>{for(var t in e)d(o,t,{get:e[t],enumerable:!0})},b=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of y(e))!v.call(o,s)&&s!==t&&d(o,s,{get:()=>e[s],enumerable:!(n=w(e,s))||n.enumerable});return o};var k=o=>b(d({},"__esModule",{value:!0}),o);var S={};E(S,{Aiola:()=>g});module.exports=k(S);var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,s){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:s,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(s,r){let i=typeof s=="string"?s:s instanceof URL?s.href:s.url,u=r?.method||"GET";if(e&&i.includes(e))return t.apply(globalThis,[s,r]);let h=Date.now();return t.apply(globalThis,[s,r]).then(c=>(n.add("http",`${u} ${i}`,{status_code:c.status,duration_ms:Date.now()-h}),c),c=>{throw n.add("http",`${u} ${i} (failed)`,{error:String(c),duration_ms:Date.now()-h},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(r,i){return this._clawMethod=r,this._clawUrl=typeof i=="string"?i:i.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let r=this;if(e&&r._clawUrl.includes(e))return s.apply(this,arguments);let i=Date.now();return r.addEventListener("loadend",function(){let u=Date.now()-i;r.status>0?t.add("http",`${r._clawMethod} ${r._clawUrl}`,{status_code:r.status,duration_ms:u,type:"xhr"}):t.add("http",`${r._clawMethod} ${r._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),s.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),s=t.textContent?.slice(0,50)?.trim(),r=t.id?`#${t.id}`:"",i=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${r}${i}${s?` "${s}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let r=window.location.href;r!==e&&(this.add("navigation",`${e} \u2192 ${r}`),e=r)};window.addEventListener("popstate",t);let n=history.pushState,s=history.replaceState;history.pushState=function(...r){n.apply(this,r),t()},history.replaceState=function(...r){s.apply(this,r),t()}}};var x=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,_=/^(.+?)@(.+?):(\d+):(\d+)$/;function m(o){let e=[],t=o.split(`
|
|
2
|
+
`);for(let n of t){let s=n.trim();if(!s||s.startsWith("Error"))continue;let r=x.exec(s);if(r){e.push({function:r[1]||"<anonymous>",filename:r[2]||r[5]||"<unknown>",lineno:parseInt(r[3],10)||0,colno:parseInt(r[4],10)||void 0,in_app:f(r[2]||"")});continue}r=_.exec(s),r&&e.push({function:r[1]||"<anonymous>",filename:r[2]||"<unknown>",lineno:parseInt(r[3],10)||0,colno:parseInt(r[4],10)||void 0,in_app:f(r[2]||"")})}return e}function f(o){return!(!o||o.includes("node_modules")||o.startsWith("node:")||o.includes("internal/")||o.includes("<anonymous>"))}var L="https://aiola.app/api/app-logs/ingest",T="aiola-js",R="0.1.3",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:L,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}this.initialized=!0,this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),s=n.stack?m(n.stack):[],r=`${n.name}:${n.message}`;if(this.seen.has(r))return;this.seen.add(r),setTimeout(()=>this.seen.delete(r),5e3);let i=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:s.length>0?{frames:s}:void 0},tags:t?.tags,request:t?.request});this._send(i)}captureMessage(e,t="info",n){if(!this.initialized)return;let s=this._buildEvent({level:t,message:e,tags:n});this._send(s)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let s=e.apply(this,n);return s instanceof Promise?s.catch(r=>{throw t.captureException(r),r}):s}catch(s){throw t.captureException(s),s}}}wrapApiHandler(e){let t=this;return async function(n,s){try{return await e(n,s)}catch(r){let i=t._extractRequestContext(n);throw t.captureException(r,{request:i}),t.transport.flush(),r}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(s){let r=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(s,{request:r}),t.transport.flush(),s}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(s){throw t.captureException(s),t.transport.flush(),s}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:T,sdk_version:R,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let s=n.map(String).join(" ");if(t.breadcrumbs.add("console",s,void 0,"error"),t.options.captureConsoleErrors){let r=n[0]instanceof Error?n[0]:null;r?t.captureException(r,{tags:{source:"console.error"}}):t.captureMessage(s,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,s=n.tagName.toLowerCase(),r=n.src||n.href||"";this.captureMessage(`Failed to load ${s}: ${r}`,"error",{source:"resource",element:s,url:r});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var g=new l;0&&(module.exports={Aiola});
|
package/dist/node.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);for(let n of t){let
|
|
1
|
+
var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,s){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:s,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(s,r){let o=typeof s=="string"?s:s instanceof URL?s.href:s.url,u=r?.method||"GET";if(e&&o.includes(e))return t.apply(globalThis,[s,r]);let d=Date.now();return t.apply(globalThis,[s,r]).then(c=>(n.add("http",`${u} ${o}`,{status_code:c.status,duration_ms:Date.now()-d}),c),c=>{throw n.add("http",`${u} ${o} (failed)`,{error:String(c),duration_ms:Date.now()-d},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(r,o){return this._clawMethod=r,this._clawUrl=typeof o=="string"?o:o.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let r=this;if(e&&r._clawUrl.includes(e))return s.apply(this,arguments);let o=Date.now();return r.addEventListener("loadend",function(){let u=Date.now()-o;r.status>0?t.add("http",`${r._clawMethod} ${r._clawUrl}`,{status_code:r.status,duration_ms:u,type:"xhr"}):t.add("http",`${r._clawMethod} ${r._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),s.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),s=t.textContent?.slice(0,50)?.trim(),r=t.id?`#${t.id}`:"",o=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${r}${o}${s?` "${s}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let r=window.location.href;r!==e&&(this.add("navigation",`${e} \u2192 ${r}`),e=r)};window.addEventListener("popstate",t);let n=history.pushState,s=history.replaceState;history.pushState=function(...r){n.apply(this,r),t()},history.replaceState=function(...r){s.apply(this,r),t()}}};var m=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,g=/^(.+?)@(.+?):(\d+):(\d+)$/;function f(i){let e=[],t=i.split(`
|
|
2
|
+
`);for(let n of t){let s=n.trim();if(!s||s.startsWith("Error"))continue;let r=m.exec(s);if(r){e.push({function:r[1]||"<anonymous>",filename:r[2]||r[5]||"<unknown>",lineno:parseInt(r[3],10)||0,colno:parseInt(r[4],10)||void 0,in_app:h(r[2]||"")});continue}r=g.exec(s),r&&e.push({function:r[1]||"<anonymous>",filename:r[2]||"<unknown>",lineno:parseInt(r[3],10)||0,colno:parseInt(r[4],10)||void 0,in_app:h(r[2]||"")})}return e}function h(i){return!(!i||i.includes("node_modules")||i.startsWith("node:")||i.includes("internal/")||i.includes("<anonymous>"))}var w="https://aiola.app/api/app-logs/ingest",y="aiola-js",v="0.1.3",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:w,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}this.initialized=!0,this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),s=n.stack?f(n.stack):[],r=`${n.name}:${n.message}`;if(this.seen.has(r))return;this.seen.add(r),setTimeout(()=>this.seen.delete(r),5e3);let o=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:s.length>0?{frames:s}:void 0},tags:t?.tags,request:t?.request});this._send(o)}captureMessage(e,t="info",n){if(!this.initialized)return;let s=this._buildEvent({level:t,message:e,tags:n});this._send(s)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let s=e.apply(this,n);return s instanceof Promise?s.catch(r=>{throw t.captureException(r),r}):s}catch(s){throw t.captureException(s),s}}}wrapApiHandler(e){let t=this;return async function(n,s){try{return await e(n,s)}catch(r){let o=t._extractRequestContext(n);throw t.captureException(r,{request:o}),t.transport.flush(),r}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(s){let r=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(s,{request:r}),t.transport.flush(),s}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(s){throw t.captureException(s),t.transport.flush(),s}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:y,sdk_version:v,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let s=n.map(String).join(" ");if(t.breadcrumbs.add("console",s,void 0,"error"),t.options.captureConsoleErrors){let r=n[0]instanceof Error?n[0]:null;r?t.captureException(r,{tags:{source:"console.error"}}):t.captureMessage(s,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,s=n.tagName.toLowerCase(),r=n.src||n.href||"";this.captureMessage(`Failed to load ${s}: ${r}`,"error",{source:"resource",element:s,url:r});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var E=new l;export{E as Aiola};
|