@compas/stdlib
Advanced tools
Comparing version 0.10.0 to 0.10.1
@@ -18,1 +18,2 @@ export { uuid } from "./src/datatypes.js"; | ||
export { newEvent, eventStart, eventRename, eventStop, newEventFromEvent } from "./src/events.js"; | ||
export { _compasSentryExport, compasWithSentry } from "./src/sentry.js"; |
@@ -95,1 +95,3 @@ /// <reference path="./types/advanced-types.d.ts"> | ||
} from "./src/events.js"; | ||
export { _compasSentryExport, compasWithSentry } from "./src/sentry.js"; |
{ | ||
"name": "@compas/stdlib", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "All kinds of utility functions", | ||
@@ -23,7 +23,10 @@ "exports": { | ||
"dependencies": { | ||
"@types/node": "20.10.8", | ||
"dotenv": "16.3.1", | ||
"@types/node": "20.12.7", | ||
"dotenv": "16.4.5", | ||
"lodash.merge": "4.6.2", | ||
"pino": "8.17.2" | ||
"pino": "8.20.0" | ||
}, | ||
"devDependencies": { | ||
"@sentry/node": "^7.110.0" | ||
}, | ||
"author": { | ||
@@ -30,0 +33,0 @@ "name": "Dirk de Visser", |
@@ -19,3 +19,3 @@ /** | ||
name?: string | undefined; | ||
location?: "user" | "project" | undefined; | ||
location?: "project" | "user" | undefined; | ||
} | undefined): void; | ||
@@ -22,0 +22,0 @@ /** |
@@ -60,4 +60,4 @@ /** | ||
* The insight event is a tool for tracking the duration of (async) functions manually. | ||
* By utilizing the insight event, you can gain access to a task or request-specific logger and | ||
* obtain insights into the execution time of your functions. | ||
* By utilizing the insight event, you can gain access to a task or request-specific | ||
* logger and obtain insights into the execution time of your functions. | ||
* | ||
@@ -75,2 +75,3 @@ * How to use the Insight Event: | ||
span: InsightEventSpan; | ||
_compasSentrySpan?: import("@sentry/node").Span | undefined; | ||
}; |
import { AppError } from "./error.js"; | ||
import { isNil } from "./lodash.js"; | ||
import { _compasSentryExport } from "./sentry.js"; | ||
@@ -16,4 +17,4 @@ /** | ||
* The insight event is a tool for tracking the duration of (async) functions manually. | ||
* By utilizing the insight event, you can gain access to a task or request-specific logger and | ||
* obtain insights into the execution time of your functions. | ||
* By utilizing the insight event, you can gain access to a task or request-specific | ||
* logger and obtain insights into the execution time of your functions. | ||
* | ||
@@ -28,3 +29,4 @@ * How to use the Insight Event: | ||
* You could pass the event object down through your (async) functions as an argument. | ||
* This allows the insight event to associate the event with the specific task or request. | ||
* This allows the insight event to associate the event with the specific task or | ||
* request. | ||
* | ||
@@ -69,2 +71,3 @@ * Finally, you should stop the event for correct logging by calling {@link eventStop}. | ||
* @property {InsightEventSpan} span | ||
* @property {import("@sentry/node").Span} [_compasSentrySpan] | ||
*/ | ||
@@ -97,2 +100,4 @@ | ||
}, | ||
_compasSentrySpan: undefined, | ||
}; | ||
@@ -127,2 +132,6 @@ } | ||
if (event._compasSentrySpan) { | ||
event._compasSentrySpan.end(); | ||
} | ||
throw AppError.serverError({ | ||
@@ -159,5 +168,17 @@ message: "Operation aborted", | ||
if (typeof _compasSentryExport?.startInactiveSpan === "function") { | ||
event._compasSentrySpan = _compasSentryExport.startInactiveSpan({ | ||
op: "event", | ||
name: name, | ||
description: name, | ||
}); | ||
} | ||
if (event.signal?.aborted) { | ||
event.span.abortedTime = Date.now(); | ||
if (event._compasSentrySpan) { | ||
event._compasSentrySpan.end(); | ||
} | ||
throw AppError.serverError({ | ||
@@ -183,5 +204,14 @@ message: "Operation aborted", | ||
if (event._compasSentrySpan) { | ||
event._compasSentrySpan.description = name; | ||
event._compasSentrySpan.updateName(name); | ||
} | ||
if (event.signal?.aborted) { | ||
event.span.abortedTime = Date.now(); | ||
if (event._compasSentrySpan) { | ||
event._compasSentrySpan.end(); | ||
} | ||
throw AppError.serverError({ | ||
@@ -209,2 +239,6 @@ message: "Operation aborted", | ||
if (event._compasSentrySpan) { | ||
event._compasSentrySpan.end(); | ||
} | ||
if (isNil(event.rootEvent)) { | ||
@@ -211,0 +245,0 @@ event.log.info({ |
@@ -6,2 +6,3 @@ import { pino } from "pino"; | ||
import { loggerWriteGithubActions, loggerWritePretty } from "./log-writers.js"; | ||
import { _compasSentryExport } from "./sentry.js"; | ||
@@ -127,2 +128,59 @@ /** | ||
if (typeof _compasSentryExport?.addBreadcrumb === "function") { | ||
let addedContextAsBreadcrumb = false; | ||
return { | ||
info: (message) => { | ||
if (!addedContextAsBreadcrumb) { | ||
// @ts-expect-error | ||
_compasSentryExport.addBreadcrumb({ | ||
category: context.type, | ||
data: { | ||
...context, | ||
}, | ||
level: "info", | ||
type: "default", | ||
}); | ||
addedContextAsBreadcrumb = true; | ||
} | ||
// @ts-expect-error | ||
_compasSentryExport.addBreadcrumb({ | ||
category: context.type, | ||
data: typeof message === "string" ? undefined : message, | ||
message: typeof message === "string" ? message : undefined, | ||
level: "info", | ||
type: "default", | ||
}); | ||
childLogger.info({ message }); | ||
}, | ||
error: (message) => { | ||
if (!addedContextAsBreadcrumb) { | ||
// @ts-expect-error | ||
_compasSentryExport.addBreadcrumb({ | ||
category: "log", | ||
data: { | ||
...context, | ||
}, | ||
level: "info", | ||
type: "default", | ||
}); | ||
addedContextAsBreadcrumb = true; | ||
} | ||
// @ts-expect-error | ||
_compasSentryExport.addBreadcrumb({ | ||
category: "log", | ||
data: typeof message === "string" ? undefined : message, | ||
message: typeof message === "string" ? message : undefined, | ||
level: "error", | ||
type: "error", | ||
}); | ||
childLogger.error({ message }); | ||
}, | ||
}; | ||
} | ||
return { | ||
@@ -129,0 +187,0 @@ info: (message) => childLogger.info({ message }), |
@@ -12,5 +12,6 @@ import { lstatSync, realpathSync } from "node:fs"; | ||
loggerDetermineDefaultDestination, | ||
loggerExtendGlobalContext, | ||
newLogger, | ||
loggerExtendGlobalContext, | ||
} from "./logger.js"; | ||
import { _compasSentryExport } from "./sentry.js"; | ||
@@ -101,3 +102,7 @@ /** | ||
process.on("unhandledRejection", (reason, promise) => | ||
process.on("unhandledRejection", (reason, promise) => { | ||
if (_compasSentryExport) { | ||
_compasSentryExport.captureException(reason); | ||
} | ||
unhandled({ | ||
@@ -107,6 +112,10 @@ type: "unhandledRejection", | ||
promise, | ||
}), | ||
); | ||
}); | ||
}); | ||
process.on("uncaughtException", (error, origin) => | ||
process.on("uncaughtException", (error, origin) => { | ||
if (_compasSentryExport) { | ||
_compasSentryExport.captureException(error); | ||
} | ||
unhandled({ | ||
@@ -116,13 +125,17 @@ type: "uncaughtException", | ||
origin, | ||
}), | ||
); | ||
}); | ||
}); | ||
process.on("warning", (warn) => | ||
process.on("warning", (warn) => { | ||
logger.error({ | ||
type: "warning", | ||
warning: AppError.format(warn), | ||
}), | ||
); | ||
}); | ||
}); | ||
Promise.resolve(cb(logger)).catch((e) => { | ||
if (_compasSentryExport) { | ||
_compasSentryExport.captureException(e); | ||
} | ||
unhandled({ | ||
@@ -129,0 +142,0 @@ type: "error", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73523
30
2429
1
+ Added@types/node@20.12.7(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addeddotenv@16.4.5(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedpino@8.20.0(transitive)
+ Addedpino-abstract-transport@1.2.0(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedreadable-stream@4.5.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsplit2@4.2.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
- Removed@types/node@20.10.8(transitive)
- Removeddotenv@16.3.1(transitive)
- Removedpino@8.17.2(transitive)
Updated@types/node@20.12.7
Updateddotenv@16.4.5
Updatedpino@8.20.0