Skip to content

Commit

Permalink
feat(observability): utilise new logger in stats-web
Browse files Browse the repository at this point in the history
ref #436
  • Loading branch information
forbesus committed Nov 26, 2024
1 parent 8ad72fa commit 7c994da
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 11 deletions.
3 changes: 2 additions & 1 deletion apps/stats-web/mvm.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"dependencies": {
"@akashnetwork/network-store": "1.0.1",
"@akashnetwork/ui": "1.0.0"
"@akashnetwork/ui": "1.0.0",
"@akashnetwork/logging": "2.0.1"
},
"devDependencies": {
"@akashnetwork/dev-config": "1.0.0"
Expand Down
8 changes: 8 additions & 0 deletions apps/stats-web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ try {

/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config, { isServer }) => {
if (isServer) {
if (process.env.NODE_ENV !== 'production') {
config.externals = [...config.externals, 'pino', 'pino-pretty'];
}
}
return config;
},
output: "standalone",
publicRuntimeConfig: {
version
Expand Down
1 change: 1 addition & 0 deletions apps/stats-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@akashnetwork/network-store": "*",
"@akashnetwork/ui": "*",
"@akashnetwork/logging": "*",
"@cosmjs/encoding": "^0.32.4",
"@json2csv/plainjs": "^7.0.4",
"@nivo/line": "^0.87.0",
Expand Down
5 changes: 4 additions & 1 deletion apps/stats-web/src/app/blocks/[height]/errors.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"use client"; // Error components must be Client Components

import { useEffect } from "react";
import { LoggerService } from "@akashnetwork/logging";

const blockErrorLogger = LoggerService.forContext("apps/stats-web/src/app/blocks/[height]/errors.tsx");

export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
blockErrorLogger.debug(error);
}, [error]);

return (
Expand Down
5 changes: 4 additions & 1 deletion apps/stats-web/src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"use client"; // Error components must be Client Components

import { useEffect } from "react";
import { LoggerService } from "@akashnetwork/logging";
import { Button } from "@akashnetwork/ui/components";

import PageContainer from "@/components/PageContainer";
import { Title } from "@/components/Title";

const errorLogger = LoggerService.forContext("apps/stats-web/src/app/error.tsx");

export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
errorLogger.debug(error);
}, [error]);

return (
Expand Down
5 changes: 4 additions & 1 deletion apps/stats-web/src/app/transactions/[hash]/error.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"use client"; // Error components must be Client Components

import { useEffect } from "react";
import { LoggerService } from "@akashnetwork/logging";
import { Button } from "@akashnetwork/ui/components";

import PageContainer from "@/components/PageContainer";
import { Title } from "@/components/Title";

const transactionLogger = LoggerService.forContext("apps/stats-web/src/app/transactions/[hash]/errors.tsx");

export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
transactionLogger.debug(error);
}, [error]);

return (
Expand Down
5 changes: 4 additions & 1 deletion apps/stats-web/src/app/transactions/[hash]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import { LoggerService } from "@akashnetwork/logging";
import type { Network } from "@akashnetwork/network-store";
import { Alert, Card, CardContent } from "@akashnetwork/ui/components";
import type { Metadata } from "next";
Expand All @@ -14,6 +15,8 @@ import { getSplitText } from "@/hooks/useShortText";
import { serverApiUrlService } from "@/services/api-url/server-api-url.service";
import { TransactionDetail } from "@/types";

const transactionLogger = LoggerService.forContext("apps/stats-web/src/app/transactions/[hash]/page.tsx");

const TransactionDetailPageSchema = z.object({
params: z.object({
hash: z.string()
Expand All @@ -33,7 +36,7 @@ export async function generateMetadata({ params: { hash } }: TransactionDetailPa

async function fetchTransactionData(hash: string, network: Network["id"]): Promise<TransactionDetail | null> {
const apiUrl = serverApiUrlService.getBaseApiUrlFor(network);
console.log("DEBUG apiUrl", apiUrl);
transactionLogger.debug(`DEBUG apiUrl: ${apiUrl}`);
const response = await fetch(`${apiUrl}/v1/transactions/${hash}`);

if (!response.ok && response.status !== 404) {
Expand Down
12 changes: 8 additions & 4 deletions apps/stats-web/src/lib/copyClipboard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { LoggerService } from "@akashnetwork/logging";

const libLogger = LoggerService.forContext("apps/stats-web/src/lib/copyClipboard.ts");

function fallbackCopyTextToClipboard(text: string) {
const textArea = document.createElement("textarea");
textArea.value = text;
Expand All @@ -14,9 +18,9 @@ function fallbackCopyTextToClipboard(text: string) {
try {
const successful = document.execCommand("copy");
const msg = successful ? "successful" : "unsuccessful";
console.log("Fallback: Copying text command was " + msg);
libLogger.debug("Fallback: Copying text command was " + msg);
} catch (err) {
console.error("Fallback: Oops, unable to copy", err);
libLogger.debug(`Fallback: Oops, unable to copy: ${err}`);
}

document.body.removeChild(textArea);
Expand All @@ -28,10 +32,10 @@ export const copyTextToClipboard = (text: string) => {
}
navigator.clipboard.writeText(text).then(
() => {
console.log("Async: Copying to clipboard was successful!");
libLogger.debug("Async: Copying to clipboard was successful!");
},
err => {
console.error("Async: Could not copy text: ", err);
libLogger.debug(`Async: Could not copy text: ${err}`);
}
);
};
4 changes: 2 additions & 2 deletions packages/logging/src/servicies/logger/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export class LoggerService implements Logger {
}

setContext(context: string) {
this.pino.setBindings({ context });
this.pino.child({ context });

return this;
}

bind(bindings: pino.Bindings) {
this.pino.setBindings(bindings);
this.pino.child(bindings);

return this;
}
Expand Down

0 comments on commit 7c994da

Please sign in to comment.