Skip to content

Commit

Permalink
feat: track block building helpers (#11190)
Browse files Browse the repository at this point in the history
This PR refactors the telemetry client so that it's a global instance
that can be used to measure free functions as well and adds spans the
block building helpers in the orchestrator

Stacked on top of #11160 

Fix #11184
  • Loading branch information
alexghr authored Jan 16, 2025
1 parent db3d860 commit a749dc1
Show file tree
Hide file tree
Showing 106 changed files with 745 additions and 692 deletions.
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Fr } from '@aztec/foundation/fields';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { sleep } from '@aztec/foundation/sleep';
import { type InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
import { getTelemetryClient } from '@aztec/telemetry-client';

import { jest } from '@jest/globals';
import { type MockProxy, mock } from 'jest-mock-extended';
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Archiver', () => {
});
blobSinkClient = mock<BlobSinkClientInterface>();

const tracer = new NoopTelemetryClient().getTracer();
const tracer = getTelemetryClient().getTracer('');
instrumentation = mock<ArchiverInstrumentation>({ isEnabled: () => true, tracer });
archiverStore = new MemoryArchiverStore(1000);
l1Constants = {
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/archiver/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
import { TokenBridgeContractArtifact } from '@aztec/noir-contracts.js/TokenBridge';
import { protocolContractNames } from '@aztec/protocol-contracts';
import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';

import { Archiver } from './archiver/archiver.js';
import { type ArchiverConfig } from './archiver/config.js';
Expand All @@ -25,8 +24,8 @@ import { createArchiverClient } from './rpc/index.js';
export async function createArchiver(
config: ArchiverConfig & DataStoreConfig,
blobSinkClient: BlobSinkClientInterface,
telemetry: TelemetryClient = new NoopTelemetryClient(),
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
telemetry: TelemetryClient = getTelemetryClient(),
): Promise<ArchiverApi & Maybe<Service>> {
if (!config.archiverUrl) {
const store = await createStore('archiver', config, createLogger('archiver:lmdb'));
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/aztec-node/src/aztec-node/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '@aztec/circuits.js';
import { type P2P } from '@aztec/p2p';
import { type GlobalVariableBuilder } from '@aztec/sequencer-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';

import { type MockProxy, mock } from 'jest-mock-extended';

Expand Down Expand Up @@ -97,7 +96,6 @@ describe('aztec node', () => {
1,
globalVariablesBuilder,
new TestCircuitVerifier(),
new NoopTelemetryClient(),
);
});

Expand Down
16 changes: 11 additions & 5 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ import {
getDefaultAllowedSetupFunctions,
} from '@aztec/sequencer-client';
import { PublicProcessorFactory } from '@aztec/simulator/server';
import { Attributes, type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
import {
Attributes,
type TelemetryClient,
type Traceable,
type Tracer,
getTelemetryClient,
trackSpan,
} from '@aztec/telemetry-client';
import { createValidatorClient } from '@aztec/validator-client';
import { createWorldStateSynchronizer } from '@aztec/world-state';

Expand Down Expand Up @@ -105,7 +111,7 @@ export class AztecNodeService implements AztecNode, Traceable {
protected readonly version: number,
protected readonly globalVariableBuilder: GlobalVariableBuilder,
private proofVerifier: ClientProtocolCircuitVerifier,
private telemetry: TelemetryClient,
private telemetry: TelemetryClient = getTelemetryClient(),
private log = createLogger('node'),
) {
this.packageVersion = getPackageInfo().version;
Expand Down Expand Up @@ -142,7 +148,7 @@ export class AztecNodeService implements AztecNode, Traceable {
blobSinkClient?: BlobSinkClientInterface;
} = {},
): Promise<AztecNodeService> {
const telemetry = deps.telemetry ?? new NoopTelemetryClient();
const telemetry = deps.telemetry ?? getTelemetryClient();
const log = deps.logger ?? createLogger('node');
const dateProvider = deps.dateProvider ?? new DateProvider();
const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config.blobSinkUrl);
Expand All @@ -154,7 +160,7 @@ export class AztecNodeService implements AztecNode, Traceable {
);
}

const archiver = await createArchiver(config, blobSinkClient, telemetry, { blockUntilSync: true });
const archiver = await createArchiver(config, blobSinkClient, { blockUntilSync: true }, telemetry);

// we identify the P2P transaction protocol by using the rollup contract address.
// this may well change in future
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/aztec_start_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@aztec/prover-client/broker';
import { proverNodeConfigMappings } from '@aztec/prover-node/config';
import { allPxeConfigMappings } from '@aztec/pxe/config';
import { telemetryClientConfigMappings } from '@aztec/telemetry-client/start';
import { telemetryClientConfigMappings } from '@aztec/telemetry-client';

import { DefaultMnemonic } from '../mnemonic.js';

Expand Down
7 changes: 2 additions & 5 deletions yarn-project/aztec/src/cli/cmds/start_archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { ArchiverApiSchema } from '@aztec/circuit-types';
import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/lmdb';
import {
createAndStartTelemetryClient,
getConfigEnvVars as getTelemetryClientConfig,
} from '@aztec/telemetry-client/start';
import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';

import { extractRelevantOptions } from '../util.js';

Expand All @@ -31,7 +28,7 @@ export async function startArchiver(
const store = await createStore('archiver', archiverConfig, storeLog);
const archiverStore = new KVArchiverDataStore(store, archiverConfig.maxLogs);

const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig());
const telemetry = initTelemetryClient(getTelemetryClientConfig());
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/10056): place CL url in config here
const blobSinkClient = createBlobSinkClient();
const archiver = await Archiver.createAndSync(archiverConfig, archiverStore, { telemetry, blobSinkClient }, true);
Expand Down
7 changes: 2 additions & 5 deletions yarn-project/aztec/src/cli/cmds/start_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { type AztecNode, type PXE } from '@aztec/circuit-types';
import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
import { type LogFn } from '@aztec/foundation/log';
import { type TelemetryClient } from '@aztec/telemetry-client';
import {
createAndStartTelemetryClient,
getConfigEnvVars as getTelemetryClientConfig,
} from '@aztec/telemetry-client/start';
import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';

import { extractRelevantOptions } from '../util.js';

Expand All @@ -30,7 +27,7 @@ export async function startBot(
pxe = await addPXE(options, signalHandlers, services, userLog);
}

const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig());
const telemetry = initTelemetryClient(getTelemetryClientConfig());
await addBot(options, signalHandlers, services, { pxe, telemetry });
}

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec/src/cli/cmds/start_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
import { type LogFn } from '@aztec/foundation/log';
import {
type TelemetryClientConfig,
createAndStartTelemetryClient,
initTelemetryClient,
telemetryClientConfigMappings,
} from '@aztec/telemetry-client/start';
} from '@aztec/telemetry-client';

import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';

Expand Down Expand Up @@ -88,7 +88,7 @@ export async function startNode(
}

const telemetryConfig = extractRelevantOptions<TelemetryClientConfig>(options, telemetryClientConfigMappings, 'tel');
const telemetry = await createAndStartTelemetryClient(telemetryConfig);
const telemetry = initTelemetryClient(telemetryConfig);

// Create and start Aztec Node
const node = await createAztecNode(nodeConfig, { telemetry });
Expand Down
7 changes: 2 additions & 5 deletions yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
import { type LogFn, createLogger } from '@aztec/foundation/log';
import { createStore } from '@aztec/kv-store/lmdb';
import { type BootnodeConfig, BootstrapNode, bootnodeConfigMappings } from '@aztec/p2p';
import {
createAndStartTelemetryClient,
getConfigEnvVars as getTelemetryClientConfig,
} from '@aztec/telemetry-client/start';
import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';

import { extractRelevantOptions } from '../util.js';

Expand All @@ -18,7 +15,7 @@ export async function startP2PBootstrap(
) {
// Start a P2P bootstrap node.
const config = extractRelevantOptions<BootnodeConfig>(options, bootnodeConfigMappings, 'p2p');
const telemetryClient = await createAndStartTelemetryClient(getTelemetryClientConfig());
const telemetryClient = initTelemetryClient(getTelemetryClientConfig());
const store = await createStore('p2p-bootstrap', config, createLogger('p2p:bootstrap:store'));
const node = new BootstrapNode(store, telemetryClient);
await node.start(config);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec/src/cli/cmds/start_proof_verifier.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { type LogFn } from '@aztec/foundation/log';
import { ProofVerifier, proofVerifierConfigMappings } from '@aztec/proof-verifier';
import { createAndStartTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client/start';
import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client';

import { extractRelevantOptions } from '../util.js';

export async function startProofVerifier(options: any, signalHandlers: (() => Promise<void>)[], userLog: LogFn) {
const config = extractRelevantOptions(options, proofVerifierConfigMappings, 'proofVerifier');

const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings, 'tel');
const telemetry = await createAndStartTelemetryClient(telemetryConfig);
const telemetry = initTelemetryClient(telemetryConfig);
const proofVerifier = await ProofVerifier.new(config, telemetry);

userLog('Starting proof verifier');
Expand Down
8 changes: 3 additions & 5 deletions yarn-project/aztec/src/cli/cmds/start_prover_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
proverAgentConfigMappings,
} from '@aztec/prover-client/broker';
import { getProverNodeAgentConfigFromEnv } from '@aztec/prover-node';
import { createAndStartTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client/start';
import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client';

import { extractRelevantOptions } from '../util.js';

Expand Down Expand Up @@ -40,9 +40,7 @@ export async function startProverAgent(

const broker = createProvingJobBrokerClient(config.proverBrokerUrl);

const telemetry = await createAndStartTelemetryClient(
extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'),
);
const telemetry = initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
const prover = await buildServerCircuitProver(config, telemetry);
const proofStore = new InlineProofStore();
const agents = times(
Expand All @@ -52,9 +50,9 @@ export async function startProverAgent(
broker,
proofStore,
prover,
telemetry,
config.proverAgentProofTypes,
config.proverAgentPollIntervalMs,
telemetry,
),
);

Expand Down
7 changes: 2 additions & 5 deletions yarn-project/aztec/src/cli/cmds/start_prover_broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
proverBrokerConfigMappings,
} from '@aztec/prover-client/broker';
import { getProverNodeBrokerConfigFromEnv } from '@aztec/prover-node';
import {
createAndStartTelemetryClient,
getConfigEnvVars as getTelemetryClientConfig,
} from '@aztec/telemetry-client/start';
import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';

import { extractRelevantOptions } from '../util.js';

Expand All @@ -31,7 +28,7 @@ export async function startProverBroker(
...extractRelevantOptions<ProverBrokerConfig>(options, proverBrokerConfigMappings, 'proverBroker'), // override with command line options
};

const client = await createAndStartTelemetryClient(getTelemetryClientConfig());
const client = initTelemetryClient(getTelemetryClientConfig());
const broker = await createAndStartProvingBroker(config, client);
services.proverBroker = [broker, ProvingJobBrokerSchema];
signalHandlers.push(() => broker.stop());
Expand Down
6 changes: 2 additions & 4 deletions yarn-project/aztec/src/cli/cmds/start_prover_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getProverNodeConfigFromEnv,
proverNodeConfigMappings,
} from '@aztec/prover-node';
import { createAndStartTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client/start';
import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client';

import { mnemonicToAccount } from 'viem/accounts';

Expand Down Expand Up @@ -58,9 +58,7 @@ export async function startProverNode(
proverConfig.l1Contracts = await createAztecNodeClient(nodeUrl).getL1ContractAddresses();
}

const telemetry = await createAndStartTelemetryClient(
extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'),
);
const telemetry = initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));

let broker: ProvingJobBroker;
if (proverConfig.proverBrokerUrl) {
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { createLogger } from '@aztec/foundation/log';
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks';
import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts';
import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe';
import { type TelemetryClient } from '@aztec/telemetry-client';
import {
createAndStartTelemetryClient,
type TelemetryClient,
getConfigEnvVars as getTelemetryClientConfig,
} from '@aztec/telemetry-client/start';
initTelemetryClient,
} from '@aztec/telemetry-client';

import { type HDAccount, type PrivateKeyAccount, createPublicClient, http as httpViemTransport } from 'viem';
import { mnemonicToAccount } from 'viem/accounts';
Expand Down Expand Up @@ -144,7 +144,7 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
await watcher.start();
}

const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig());
const telemetry = initTelemetryClient(getTelemetryClientConfig());
// Create a local blob sink client inside the sandbox, no http connectivity
const blobSinkClient = createBlobSinkClient();
const node = await createAztecNode(aztecNodeConfig, { telemetry, blobSinkClient });
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/bb-prover/src/prover/bb_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import {
convertSingleTxBlockRootRollupOutputsFromWitnessMap,
} from '@aztec/noir-protocol-circuits-types/server';
import { NativeACVMSimulator } from '@aztec/simulator/server';
import { Attributes, type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
import { Attributes, type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';

import { type WitnessMap } from '@noir-lang/types';
import { assert } from 'console';
Expand Down Expand Up @@ -129,7 +129,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
return this.instrumentation.tracer;
}

static async new(config: BBProverConfig, telemetry: TelemetryClient) {
static async new(config: BBProverConfig, telemetry: TelemetryClient = getTelemetryClient()) {
await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
await fs.mkdir(config.acvmWorkingDirectory, { recursive: true });
await fs.access(config.bbBinaryPath, fs.constants.R_OK);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/bb-prover/src/test/test_circuit_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {
} from '@aztec/noir-protocol-circuits-types/server';
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
import { type SimulationProvider, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator/server';
import { type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
import { type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';

import { type WitnessMap } from '@noir-lang/types';

Expand All @@ -81,9 +81,9 @@ export class TestCircuitProver implements ServerCircuitProver {
private logger = createLogger('bb-prover:test-prover');

constructor(
telemetry: TelemetryClient,
private simulationProvider?: SimulationProvider,
private opts: { proverTestDelayMs: number } = { proverTestDelayMs: 0 },
telemetry: TelemetryClient = getTelemetryClient(),
) {
this.instrumentation = new ProverInstrumentation(telemetry, 'TestCircuitProver');
}
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/blob-sink/src/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Blob } from '@aztec/foundation/blob';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { type AztecKVStore } from '@aztec/kv-store';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';

import express, { type Express, type Request, type Response, json } from 'express';
import { type Server } from 'http';
Expand Down Expand Up @@ -32,7 +31,7 @@ export class BlobSinkServer {
private metrics: BlobSinkMetrics;
private log: Logger = createLogger('aztec:blob-sink');

constructor(config?: BlobSinkConfig, store?: AztecKVStore, telemetry: TelemetryClient = new NoopTelemetryClient()) {
constructor(config?: BlobSinkConfig, store?: AztecKVStore, telemetry: TelemetryClient = getTelemetryClient()) {
this.port = config?.port ?? 5052; // 5052 is beacon chain default http port
this.app = express();

Expand Down
Loading

0 comments on commit a749dc1

Please sign in to comment.