Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade tap, pino-pretty and sentry #311

Open
wants to merge 17 commits into
base: beta
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.nyc_output
.tap
coverage
node_modules
node_modules
5 changes: 0 additions & 5 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
files:
- test/**/*.test.js

lines: 91
functions: 100
branches: 83
statements: 91
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const log = pino(
{
name: "probot",
},
getTransformStream()
getTransformStream(),
);
```

Expand All @@ -46,7 +46,7 @@ const log = pino(
{
name: "probot",
},
transform
transform,
);
```

Expand Down
4 changes: 3 additions & 1 deletion cli.js → bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use strict";

const pump = require("pump");
const split = require("split2");

const { getTransformStream } = require("./");
const { getTransformStream } = require("..");

const options = {
logFormat: process.env.LOG_FORMAT,
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transform } from "readable-stream";
import { Transform } from "node:stream";

export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";

Expand Down
43 changes: 26 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = { getTransformStream };
"use strict";

const { Transform } = require("node:stream");

const prettyFactory = require("pino-pretty");
const Sentry = require("@sentry/node");
const { prettyFactory } = require("pino-pretty");
const { init, withScope, captureException } = require("@sentry/node");

const LEVEL_MAP = {
10: "trace",
Expand All @@ -15,7 +15,7 @@ const LEVEL_MAP = {
};

/**
* Implements Probot's default logging formatting and error captionaing using Sentry.
* Implements Probot's default logging formatting and error captioning using Sentry.
*
* @param {import("./").Options} options
* @returns Transform
Expand All @@ -28,7 +28,7 @@ function getTransformStream(options = {}) {
const sentryEnabled = !!options.sentryDsn;

if (sentryEnabled) {
Sentry.init({
init({
dsn: options.sentryDsn,
// See https://github.com/getsentry/sentry-javascript/issues/1964#issuecomment-688482615
// 6 is enough to serialize the deepest property across all GitHub Event payloads
Expand All @@ -48,7 +48,7 @@ function getTransformStream(options = {}) {
"responseTime",
].join(","),
errorProps: ["event", "status", "headers", "request", "sentryEventId"].join(
","
",",
),
});

Expand All @@ -75,19 +75,24 @@ function getTransformStream(options = {}) {
return;
}

Sentry.withScope(function (scope) {
const sentryLevelName =
data.level === 50 ? Sentry.Severity.Error : Sentry.Severity.Fatal;
scope.setLevel(sentryLevelName);
withScope((scope) => {
scope.setLevel(data.level === 50 ? "error" : "fatal");

for (const extra of ["event", "headers", "request", "status"]) {
if (!data[extra]) continue;

scope.setExtra(extra, data[extra]);
if (data.event) {
scope.setExtra("event", data.event);
}
if (data.headers) {
scope.setExtra("headers", data.headers);
}
if (data.request) {
scope.setExtra("request", data.request);
}
if (data.status) {
scope.setExtra("status", data.status);
}

// set user id and username to installation ID and account login
if (data.event && data.event.payload) {
if (data.event?.payload) {
const {
// When GitHub App is installed organization wide
installation: { id, account: { login: account } = {} } = {},
Expand All @@ -99,12 +104,12 @@ function getTransformStream(options = {}) {
} = data.event.payload;

scope.setUser({
id: id,
id,
username: account || organization || owner,
});
}

const sentryEventId = Sentry.captureException(toSentryError(data));
const sentryEventId = captureException(toSentryError(data));

// reduce logging data and add reference to sentry event instead
if (data.event) {
Expand Down Expand Up @@ -144,3 +149,7 @@ function toSentryError(data) {
error.stack = data.stack;
return error;
}

module.exports = getTransformStream;
module.exports.default = module.exports;
module.exports.getTransformStream = getTransformStream;
Loading
Loading