Skip to content

Commit

Permalink
Merge pull request #1826 from balena-io/loki
Browse files Browse the repository at this point in the history
Loki
  • Loading branch information
Page- authored Oct 30, 2024
2 parents d0aea3e + f40297f commit 0a47be6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/features/device-logs/lib/backends/loki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class LokiBackend implements DeviceLogsBackend {
streams.push(...queryResponse.getStreamsList());
});
call.on('error', (error: Error & { details: string }) => {
const message = `Failed to query logs from ${lokiQueryAddress} for device ${ctx.uuid}`;
const message = `Failed to query logs for device ${ctx.uuid}`;
captureException(error, message);
reject(new BadRequestError(message));
});
Expand Down
4 changes: 3 additions & 1 deletion src/features/device-logs/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function handleStoreErrors(req: Request, res: Response, err: Error) {
res.status(500).end();
}

const lokiBackend = LOKI_ENABLED ? await getLokiBackend() : undefined;

const publishBackend = LOKI_ENABLED
? async (
backend: DeviceLogsBackend,
Expand All @@ -140,7 +142,7 @@ const publishBackend = LOKI_ENABLED
) => {
const publishingToRedis = backend.publish(ctx, buffer);
const publishingToLoki = shouldPublishToLoki()
? (await getLokiBackend()).publish(ctx, buffer).catch((err) => {
? lokiBackend?.publish(ctx, buffer).catch((err) => {
captureException(err, 'Failed to publish logs to Loki');
})
: undefined;
Expand Down

0 comments on commit 0a47be6

Please sign in to comment.