Skip to content

Commit 7a4ca83

Browse files
committed
Merge branch 'feature/monitoring' into feature/static-dependency-factory
2 parents 332d51f + bd3105f commit 7a4ca83

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

packages/persistance/src/PrismaDatabaseConnection.ts

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

@@ -38,6 +39,10 @@ export class PrismaDatabaseConnection
3839
extends SequencerModule<PrismaDatabaseConfig>
3940
implements DependencyFactory, PrismaConnection
4041
{
42+
public constructor(private readonly tracer: Tracer) {
43+
super();
44+
}
45+
4146
private initializedClient: PrismaClient | undefined = undefined;
4247

4348
public get prismaClient(): PrismaClient {
@@ -53,7 +58,7 @@ export class PrismaDatabaseConnection
5358
> {
5459
return {
5560
asyncStateService: {
56-
useFactory: () => new PrismaStateService(this, "batch"),
61+
useFactory: () => new PrismaStateService(this, "batch", this.tracer),
5762
},
5863
batchStorage: {
5964
useClass: PrismaBatchStore,
@@ -65,7 +70,7 @@ export class PrismaDatabaseConnection
6570
useClass: PrismaBlockStorage,
6671
},
6772
unprovenStateService: {
68-
useFactory: () => new PrismaStateService(this, "block"),
73+
useFactory: () => new PrismaStateService(this, "block", this.tracer),
6974
},
7075
settlementStorage: {
7176
useClass: PrismaSettlementStorage,

packages/persistance/src/PrismaRedisDatabase.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
StorageDependencyMinimumDependencies,
55
Database,
66
closeable,
7+
Tracer,
78
} from "@proto-kit/sequencer";
89
import { ChildContainerProvider } from "@proto-kit/common";
910
import { PrismaClient } from "@prisma/client";
@@ -20,6 +21,7 @@ import {
2021
RedisConnectionModule,
2122
RedisTransaction,
2223
} from "./RedisConnection";
24+
import { inject } from "tsyringe";
2325

2426
export interface PrismaRedisCombinedConfig {
2527
prisma: PrismaDatabaseConfig;
@@ -36,10 +38,10 @@ export class PrismaRedisDatabase
3638

3739
public redis: RedisConnectionModule;
3840

39-
public constructor() {
41+
public constructor(@inject("Tracer") tracer: Tracer) {
4042
super();
41-
this.prisma = new PrismaDatabaseConnection();
42-
this.redis = new RedisConnectionModule();
43+
this.prisma = new PrismaDatabaseConnection(tracer);
44+
this.redis = new RedisConnectionModule(tracer);
4345
}
4446

4547
public get prismaClient(): PrismaClient {

packages/persistance/src/RedisConnection.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ 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";
@@ -26,6 +27,10 @@ export class RedisConnectionModule
2627
extends SequencerModule<RedisConnectionConfig>
2728
implements DependencyFactory, RedisConnection
2829
{
30+
public constructor(private readonly tracer: Tracer) {
31+
super();
32+
}
33+
2934
private client?: RedisClientType;
3035

3136
public get redisClient(): RedisClientType {
@@ -43,13 +48,15 @@ export class RedisConnectionModule
4348
> {
4449
return {
4550
asyncMerkleStore: {
46-
useFactory: () => new RedisMerkleTreeStore(this),
51+
useFactory: () => new RedisMerkleTreeStore(this, this.tracer),
4752
},
4853
unprovenMerkleStore: {
49-
useFactory: () => new RedisMerkleTreeStore(this, "unproven"),
54+
useFactory: () =>
55+
new RedisMerkleTreeStore(this, this.tracer, "unproven"),
5056
},
5157
blockTreeStore: {
52-
useFactory: () => new RedisMerkleTreeStore(this, "blockHash"),
58+
useFactory: () =>
59+
new RedisMerkleTreeStore(this, this.tracer, "blockHash"),
5360
},
5461
};
5562
}

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)