Skip to content

Commit 179cfbc

Browse files
committed
Added tracing to DB
1 parent 18554ad commit 179cfbc

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

packages/persistance/src/PrismaDatabaseConnection.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {
33
sequencerModule,
44
SequencerModule,
55
StorageDependencyMinimumDependencies,
6+
Tracer,
67
} from "@proto-kit/sequencer";
78
import { DependencyFactory, OmitKeys } from "@proto-kit/common";
9+
import { inject } from "tsyringe";
810

911
import { PrismaStateService } from "./services/prisma/PrismaStateService";
1012
import { PrismaBatchStore } from "./services/prisma/PrismaBatchStore";
@@ -38,6 +40,10 @@ export class PrismaDatabaseConnection
3840
extends SequencerModule<PrismaDatabaseConfig>
3941
implements DependencyFactory, PrismaConnection
4042
{
43+
public constructor(@inject("Tracer") private readonly tracer: Tracer) {
44+
super();
45+
}
46+
4147
private initializedClient: PrismaClient | undefined = undefined;
4248

4349
public get prismaClient(): PrismaClient {
@@ -53,7 +59,7 @@ export class PrismaDatabaseConnection
5359
> {
5460
return {
5561
asyncStateService: {
56-
useFactory: () => new PrismaStateService(this, "batch"),
62+
useFactory: () => new PrismaStateService(this, "batch", this.tracer),
5763
},
5864
batchStorage: {
5965
useClass: PrismaBatchStore,
@@ -65,7 +71,7 @@ export class PrismaDatabaseConnection
6571
useClass: PrismaBlockStorage,
6672
},
6773
unprovenStateService: {
68-
useFactory: () => new PrismaStateService(this, "block"),
74+
useFactory: () => new PrismaStateService(this, "block", this.tracer),
6975
},
7076
settlementStorage: {
7177
useClass: PrismaSettlementStorage,

packages/persistance/src/RedisConnection.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { createClient, RedisClientType } from "redis";
22
import {
33
SequencerModule,
44
StorageDependencyMinimumDependencies,
5+
Tracer,
56
} from "@proto-kit/sequencer";
67
import { DependencyFactory } from "@proto-kit/common";
78
import isArray from "lodash/isArray";
89

910
import { RedisMerkleTreeStore } from "./services/redis/RedisMerkleTreeStore";
11+
import { inject } from "tsyringe";
1012

1113
export interface RedisConnectionConfig {
1214
host: string;
@@ -26,6 +28,10 @@ export class RedisConnectionModule
2628
extends SequencerModule<RedisConnectionConfig>
2729
implements DependencyFactory, RedisConnection
2830
{
31+
public constructor(@inject("Tracer") private readonly tracer: Tracer) {
32+
super();
33+
}
34+
2935
private client?: RedisClientType;
3036

3137
public get redisClient(): RedisClientType {
@@ -43,13 +49,15 @@ export class RedisConnectionModule
4349
> {
4450
return {
4551
asyncMerkleStore: {
46-
useFactory: () => new RedisMerkleTreeStore(this),
52+
useFactory: () => new RedisMerkleTreeStore(this, this.tracer),
4753
},
4854
unprovenMerkleStore: {
49-
useFactory: () => new RedisMerkleTreeStore(this, "unproven"),
55+
useFactory: () =>
56+
new RedisMerkleTreeStore(this, this.tracer, "unproven"),
5057
},
5158
blockTreeStore: {
52-
useFactory: () => new RedisMerkleTreeStore(this, "blockHash"),
59+
useFactory: () =>
60+
new RedisMerkleTreeStore(this, this.tracer, "blockHash"),
5361
},
5462
};
5563
}

packages/persistance/src/services/prisma/PrismaStateService.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { AsyncStateService, StateEntry } from "@proto-kit/sequencer";
1+
import {
2+
AsyncStateService,
3+
StateEntry,
4+
Tracer,
5+
trace,
6+
} from "@proto-kit/sequencer";
27
import { Field } from "o1js";
38
import { Prisma } from "@prisma/client";
49
import { noop } from "@proto-kit/common";
@@ -19,12 +24,15 @@ export class PrismaStateService implements AsyncStateService {
1924
/**
2025
* @param connection
2126
* @param mask A indicator to which masking level the values belong
27+
* @param tracer
2228
*/
2329
public constructor(
2430
private readonly connection: PrismaConnection,
25-
private readonly mask: string
31+
private readonly mask: string,
32+
public readonly tracer: Tracer
2633
) {}
2734

35+
@trace("db.state.commit")
2836
public async commit(): Promise<void> {
2937
const { prismaClient } = this.connection;
3038

packages/persistance/src/services/prisma/PrismaTransactionStorage.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { inject, injectable } from "tsyringe";
2-
import { PendingTransaction, TransactionStorage } from "@proto-kit/sequencer";
2+
import {
3+
PendingTransaction,
4+
trace,
5+
Tracer,
6+
TransactionStorage,
7+
} from "@proto-kit/sequencer";
38

49
import type { PrismaConnection } from "../../PrismaDatabaseConnection";
510

@@ -9,9 +14,11 @@ import { TransactionMapper } from "./mappers/TransactionMapper";
914
export class PrismaTransactionStorage implements TransactionStorage {
1015
public constructor(
1116
@inject("Database") private readonly connection: PrismaConnection,
12-
private readonly transactionMapper: TransactionMapper
17+
private readonly transactionMapper: TransactionMapper,
18+
@inject("Tracer") public readonly tracer: Tracer
1319
) {}
1420

21+
@trace("db.txs.get")
1522
public async getPendingUserTransactions(): Promise<PendingTransaction[]> {
1623
const { prismaClient } = this.connection;
1724

packages/persistance/src/services/redis/RedisMerkleTreeStore.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
AsyncMerkleTreeStore,
33
MerkleTreeNode,
44
MerkleTreeNodeQuery,
5+
trace,
6+
Tracer,
57
} from "@proto-kit/sequencer";
68
import { log, noop } from "@proto-kit/common";
79

@@ -12,6 +14,7 @@ export class RedisMerkleTreeStore implements AsyncMerkleTreeStore {
1214

1315
public constructor(
1416
private readonly connection: RedisConnection,
17+
public readonly tracer: Tracer,
1518
private readonly mask: string = "base"
1619
) {}
1720

@@ -23,6 +26,7 @@ export class RedisMerkleTreeStore implements AsyncMerkleTreeStore {
2326
noop();
2427
}
2528

29+
@trace("db.tree.commit")
2630
public async commit(): Promise<void> {
2731
const start = Date.now();
2832
const array: [string, string][] = this.cache.map(
@@ -45,6 +49,7 @@ export class RedisMerkleTreeStore implements AsyncMerkleTreeStore {
4549
this.cache = [];
4650
}
4751

52+
@trace("db.tree.read")
4853
public async getNodesAsync(
4954
nodes: MerkleTreeNodeQuery[]
5055
): Promise<(bigint | undefined)[]> {

packages/sequencer/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,6 @@ export * from "./settlement/transactions/MinaTransactionSender";
102102
export * from "./settlement/transactions/MinaTransactionSimulator";
103103
export * from "./settlement/transactions/MinaSimulationService";
104104
export * from "./logging/Tracer";
105+
export * from "./logging/trace";
105106
export * from "./logging/ConsoleLoggingFactory";
106107
export * from "./logging/ConsoleTracer";

0 commit comments

Comments
 (0)