Skip to content

Commit 9abfa30

Browse files
authored
log errors to honeycomb (#436)
1 parent 584a70d commit 9abfa30

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

apps/passport-server/src/database/queries/historicSemaphore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ function historicRowToGroup(row: QueryResultRow): HistoricSemaphoreGroup {
6363
groupId: row.groupid,
6464
rootHash: row.roothash,
6565
serializedGroup: row.serializedgroup,
66-
timeCreated: row.timecreated,
66+
timeCreated: row.timecreated
6767
};
6868
}

apps/passport-server/src/routing/server.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { initZuzaluRoutes } from "./routes/zuzaluRoutes";
1919

2020
export async function startServer(
2121
context: ApplicationContext,
22-
globalServices: GlobalServices,
22+
globalServices: GlobalServices
2323
): Promise<{ app: Application; server: http.Server }> {
2424
return new Promise<{ app: Application; server: http.Server }>(
2525
(resolve, reject) => {
@@ -32,16 +32,16 @@ export async function startServer(
3232

3333
app.use(
3434
express.json({
35-
limit: "5mb",
36-
}),
35+
limit: "5mb"
36+
})
3737
);
3838
app.use(cors());
3939
app.use(tracingMiddleware());
4040
app.use(
4141
cors({
4242
origin: "*",
43-
methods: ["GET", "POST", "PUT", "DELETE"],
44-
}),
43+
methods: ["GET", "POST", "PUT", "DELETE"]
44+
})
4545
);
4646

4747
initAllRoutes(app, context, globalServices);
@@ -51,13 +51,13 @@ export async function startServer(
5151
err: Error,
5252
req: express.Request,
5353
res: express.Response,
54-
_next: NextFunction,
54+
_next: NextFunction
5555
) => {
5656
logger(`[ERROR] ${req.method} ${req.url}`);
5757
logger(err.stack);
5858
globalServices.rollbarService?.reportError(err);
5959
res.status(500).send(err.message);
60-
},
60+
}
6161
);
6262

6363
const server = app.listen(port, () => {
@@ -69,14 +69,14 @@ export async function startServer(
6969
server.on("error", (e: Error) => {
7070
reject(e);
7171
});
72-
},
72+
}
7373
);
7474
}
7575

7676
function initAllRoutes(
7777
app: express.Application,
7878
context: ApplicationContext,
79-
globalServices: GlobalServices,
79+
globalServices: GlobalServices
8080
): void {
8181
initStatusRoutes(app, context, globalServices);
8282
initHealthcheckRoutes(app, context);

apps/passport-server/src/services/devconnectPretixSyncService.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { pretixTicketsDifferent } from "../util/devconnectTicket";
3333
import { logger } from "../util/logger";
3434
import { RollbarService } from "./rollbarService";
3535
import { SemaphoreService } from "./semaphoreService";
36-
import { traced } from "./telemetryService";
36+
import { setError, traced } from "./telemetryService";
3737

3838
const NAME = "Devconnect Pretix";
3939

@@ -153,7 +153,7 @@ export class DevconnectPretixSyncService {
153153
"[DEVCONNECT PRETIX] Failed to save tickets for one or more events",
154154
e
155155
);
156-
span?.setAttribute("error", e + "");
156+
setError(e, span);
157157
this.rollbarService?.reportError(e);
158158
}
159159

@@ -349,7 +349,7 @@ export class DevconnectPretixSyncService {
349349
`[DEVCONNECT PRETIX] Sync aborted for organizer ${organizer.id} due to errors`,
350350
e
351351
);
352-
span?.setAttribute("error", e + "");
352+
setError(e, span);
353353
this.rollbarService?.reportError(e);
354354
}
355355
});
@@ -395,7 +395,7 @@ export class DevconnectPretixSyncService {
395395
}
396396
} catch (e) {
397397
logger("[DEVCONNECT PRETIX] Sync aborted due to errors", e);
398-
span?.setAttribute("error", e + "");
398+
setError(e, span);
399399
this.rollbarService?.reportError(e);
400400
}
401401
});
@@ -445,7 +445,7 @@ export class DevconnectPretixSyncService {
445445
{ error: e }
446446
);
447447
this.rollbarService?.reportError(e);
448-
span?.setAttribute("error", e + "");
448+
setError(e, span);
449449
return false;
450450
}
451451

@@ -580,7 +580,7 @@ export class DevconnectPretixSyncService {
580580
{ error: e }
581581
);
582582
this.rollbarService?.reportError(e);
583-
span?.setAttribute("error", e + "");
583+
setError(e, span);
584584
return false;
585585
}
586586

@@ -709,7 +709,7 @@ export class DevconnectPretixSyncService {
709709
{ error: e }
710710
);
711711
this.rollbarService?.reportError(e);
712-
span?.setAttribute("error", e + "");
712+
setError(e, span);
713713
return false;
714714
}
715715
return true;

apps/passport-server/src/services/telemetryService.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,29 @@ export async function traced<T>(
6666
if (process.env.ROLLBAR_ENV_NAME) {
6767
span.setAttribute("env_name", process.env.ROLLBAR_ENV_NAME);
6868
}
69-
const result = await func(span);
70-
if (
71-
options == null ||
72-
options.autoEndSpan == null ||
73-
options.autoEndSpan == true
74-
) {
69+
try {
70+
const result = await func(span);
71+
if (
72+
options == null ||
73+
options.autoEndSpan == null ||
74+
options.autoEndSpan == true
75+
) {
76+
span.end();
77+
}
78+
return result;
79+
} catch (e) {
80+
setError(e, span);
7581
span.end();
82+
throw e;
7683
}
77-
return result;
7884
});
7985
}
86+
87+
export function setError(e: Error | any, span?: Span): void {
88+
span?.setAttribute("error", true);
89+
span?.setAttribute("error_msg", e + "");
90+
91+
if (e instanceof Error && e.stack) {
92+
span?.setAttribute("error_trace", e.stack);
93+
}
94+
}

0 commit comments

Comments
 (0)