Skip to content

Commit c6f2675

Browse files
committed
feat: setup logger
1 parent b6d9b20 commit c6f2675

File tree

7 files changed

+26270
-9
lines changed

7 files changed

+26270
-9
lines changed

evault.docker-compose.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- W3ID=${W3ID}
1717
volumes:
1818
- secrets:/app/secrets
19-
networks:
19+
networks:
2020
- graphnet
2121
depends_on:
2222
- neo4j
@@ -45,6 +45,13 @@ services:
4545
- neo4j_logs:/log
4646
networks:
4747
- graphnet
48+
loki:
49+
image: grafana/loki:latest
50+
container_name: loki
51+
networks:
52+
- graphnet
53+
ports:
54+
- "3100:3100"
4855

4956
volumes:
5057
neo4j_data:

infrastructure/web3-adapter/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"axios": "^1.6.7",
1919
"evault-core": "workspace:*",
2020
"graphql-request": "^6.1.0",
21+
"pino": "^9.8.0",
22+
"pino-loki": "^2.6.0",
2123
"sqlite3": "^5.1.7",
2224
"test": "^3.3.0",
2325
"uuid": "^11.1.0",
@@ -35,6 +37,8 @@
3537
"jest": {
3638
"preset": "ts-jest",
3739
"testEnvironment": "node",
38-
"testMatch": ["**/__tests__/**/*.test.ts"]
40+
"testMatch": [
41+
"**/__tests__/**/*.test.ts"
42+
]
3943
}
4044
}

infrastructure/web3-adapter/src/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { fromGlobal, toGlobal } from "./mapper/mapper";
66
import type { IMapping } from "./mapper/mapper.types";
77
import axios from "axios";
88
import { v4 as uuidv4 } from "uuid";
9+
import { logger } from "./logging";
910

1011
/**
1112
* Standalone function to spin up an eVault
@@ -99,7 +100,7 @@ export async function createGroupEVault(
99100
try {
100101
// Step 1: Spin up the eVault
101102
const evault = await spinUpEVault(registryUrl, provisionerUrl, finalVerificationCode);
102-
103+
103104
// Step 2: Create GroupManifest with exponential backoff
104105
const manifestId = await createGroupManifestWithRetry(
105106
registryUrl,
@@ -138,7 +139,7 @@ async function createGroupManifestWithRetry(
138139
maxRetries = 10
139140
): Promise<string> {
140141
const now = new Date().toISOString();
141-
142+
142143
const groupManifest: GroupManifest = {
143144
eName: w3id,
144145
name: groupData.name,
@@ -155,12 +156,12 @@ async function createGroupManifestWithRetry(
155156
for (let attempt = 1; attempt <= maxRetries; attempt++) {
156157
try {
157158
console.log(`Attempting to create GroupManifest in eVault (attempt ${attempt}/${maxRetries})`);
158-
159+
159160
const response = await axios.get(
160161
new URL(`resolve?w3id=${w3id}`, registryUrl).toString()
161162
);
162163
const endpoint = new URL("/graphql", response.data.uri).toString();
163-
164+
164165
const { GraphQLClient } = await import("graphql-request");
165166
const client = new GraphQLClient(endpoint);
166167

@@ -229,7 +230,7 @@ export class Web3Adapter {
229230
dbPath: string;
230231
registryUrl: string;
231232
platform: string;
232-
provisionerUrl?: string;
233+
provisionerUrl?: string;
233234
},
234235
) {
235236
this.readPaths();
@@ -277,6 +278,8 @@ export class Web3Adapter {
277278
data.id as string,
278279
);
279280

281+
logger.info(`Handling change for table ${tableName} with data: ${JSON.stringify(data)}`)
282+
280283
if (!this.mapping[tableName]) return
281284
console.log("We get here?")
282285
// If we already have a mapping, use that global ID
@@ -375,7 +378,7 @@ export class Web3Adapter {
375378
provisionerUrl?: string
376379
): Promise<{ w3id: string; uri: string }> {
377380
const finalProvisionerUrl = provisionerUrl || this.config.provisionerUrl;
378-
381+
379382
if (!finalProvisionerUrl) {
380383
throw new Error("Provisioner URL is required. Please provide it in config or as parameter.");
381384
}
@@ -404,7 +407,7 @@ export class Web3Adapter {
404407
provisionerUrl?: string
405408
): Promise<{ w3id: string; uri: string; manifestId: string }> {
406409
const finalProvisionerUrl = provisionerUrl || this.config.provisionerUrl;
407-
410+
408411
if (!finalProvisionerUrl) {
409412
throw new Error("Provisioner URL is required. Please provide it in config or as parameter.");
410413
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./transport";
2+
export * from "./logger";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pino from "pino";
2+
import { transport } from "./transport";
3+
4+
export const logger = pino(transport)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {transport as pinoTransport} from "pino"
2+
import type { LokiOptions } from "pino-loki"
3+
4+
export const transport = pinoTransport<LokiOptions>({
5+
target: "pino-loki",
6+
options: {
7+
host: process.env.LOKI_URL || "http://loki:3100",
8+
labels: {
9+
app: "web3-adapter",
10+
},
11+
basicAuth:{
12+
username: process.env.LOKI_USERNAME || "admin",
13+
password: process.env.LOKI_PASSWORD || "admin"
14+
}
15+
}
16+
})
17+
18+

0 commit comments

Comments
 (0)