sendou.ink/app/utils/newrelic.server.ts
2024-03-24 14:38:05 +02:00

37 lines
841 B
TypeScript

const isEnabled =
process.env["NEW_RELIC_APP_NAME"] && process.env["NEW_RELIC_LICENSE_KEY"];
import newrelic from "newrelic";
export const browserTimingHeader = () =>
isEnabled
? newrelic.getBrowserTimingHeader({
hasToRemoveScriptWrapper: true,
})
: null;
export const noticeError = (
error: Error,
attributes?: {
"enduser.id"?: number;
formData?: string;
searchParams?: string;
params?: string;
},
) =>
isEnabled &&
newrelic.noticeError(error, {
...attributes,
"tags.commit": process.env["RENDER_GIT_COMMIT"]!,
});
export const setTransactionName = (name: string) =>
isEnabled && newrelic.setTransactionName(name);
export const ignoreTransaction = () => {
if (!isEnabled) return;
const transactionHandle = newrelic.getTransaction();
transactionHandle.ignore();
};