Skip to content

Commit

Permalink
fix: wait for resource attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Aug 23, 2024
1 parent f54ba9a commit 81c86f3
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ configs:
prometheus-config:
content: |
global:
evaluation_interval: 30s
scrape_interval: 10s
evaluation_interval: 15s
scrape_interval: 15s
scrape_configs:
- job_name: otel-collector
static_configs:
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const startArchiver = async (options: any, signalHandlers: (() => Promise
const store = await createStore(archiverConfig, rollupAddress, storeLog);
const archiverStore = new KVArchiverDataStore(store, archiverConfig.maxLogs);

const telemetry = createAndStartTelemetryClient(getTelemetryClientConfig());
const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig());
const archiver = await Archiver.createAndSync(archiverConfig, archiverStore, telemetry, true);
const archiverServer = createArchiverRpcServer(archiver);
services.push({ archiver: archiverServer });
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const startNode = async (
}

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

// Create and start Aztec Node.
const node = await createAztecNode(nodeConfig, telemetryClient);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_prover_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const startProverAgent: ServiceStarter = async (options, signalHandlers,
const source = createProvingJobSourceClient(proverConfig.nodeUrl, 'provingJobSource');

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

let circuitProver: ServerCircuitProver;
if (proverConfig.realProofs) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_prover_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const startProverNode = async (
proverConfig.l1Contracts = await createAztecNodeClient(nodeUrl).getL1ContractAddresses();
}

const telemetry = createAndStartTelemetryClient(getTelemetryClientConfig());
const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig());
const proverNode = await createProverNode(proverConfig, { telemetry });

services.push({ node: createProverNodeRpcServer(proverNode) });
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
await deployContractsToL1(aztecNodeConfig, hdAccount);
}

const client = createAndStartTelemetryClient(getTelemetryClientConfig());
const client = await createAndStartTelemetryClient(getTelemetryClientConfig());
const node = await createAztecNode(aztecNodeConfig, client);
const pxe = await createAztecPXE(node);

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/fixtures/snapshot_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ async function setupFromFresh(
aztecNodeConfig.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
}

const telemetry = createAndStartTelemetryClient(getTelemetryConfig());
const telemetry = await createAndStartTelemetryClient(getTelemetryConfig());
logger.verbose('Creating and synching an aztec node...');
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, telemetry);

Expand Down Expand Up @@ -408,7 +408,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrl, mnemonicToAccount(MNEMONIC));

logger.verbose('Creating aztec node...');
const telemetry = createAndStartTelemetryClient(getTelemetryConfig());
const telemetry = await createAndStartTelemetryClient(getTelemetryConfig());
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, telemetry);

const proverNodePrivateKey = getPrivateKeyFromIndex(2);
Expand Down
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ export { deployAndInitializeTokenAndBridgeContracts } from '../shared/cross_chai

const { PXE_URL = '' } = process.env;

const telemetry = createAndStartTelemetryClient(getTelemetryConfig());
const telemetryPromise = createAndStartTelemetryClient(getTelemetryConfig());
if (typeof afterAll === 'function') {
afterAll(async () => {
await telemetry.stop();
const client = await telemetryPromise;
await client.stop();
});
}

Expand Down Expand Up @@ -395,6 +396,7 @@ export async function setup(
}
config.l1PublishRetryIntervalMS = 100;

const telemetry = await telemetryPromise;
const aztecNode = await AztecNodeService.createAndSync(config, telemetry);
const sequencer = aztecNode.getSequencer();

Expand Down
17 changes: 7 additions & 10 deletions yarn-project/telemetry-client/src/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,19 @@ export class OpenTelemetryClient implements TelemetryClient {
description: 'Target information',
});

if (this.resource.asyncAttributesPending) {
void this.resource.waitForAsyncAttributes!().then(() => {
this.targetInfo!.record(1, this.resource.attributes);
});
} else {
this.targetInfo.record(1, this.resource.attributes);
}

this.targetInfo.record(1, this.resource.attributes);
this.hostMetrics.start();
}

public async stop() {
await Promise.all([this.meterProvider.shutdown()]);
}

public static createAndStart(
public static async createAndStart(
metricsCollector: URL,
tracesCollector: URL | undefined,
log: DebugLogger,
): OpenTelemetryClient {
): Promise<OpenTelemetryClient> {
const resource = detectResourcesSync({
detectors: [
osDetectorSync,
Expand All @@ -94,6 +87,10 @@ export class OpenTelemetryClient implements TelemetryClient {
],
});

if (resource.asyncAttributesPending) {
await resource.waitForAsyncAttributes!();
}

const tracerProvider = new NodeTracerProvider({
resource,
});
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/telemetry-client/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { type TelemetryClient } from './telemetry.js';

export * from './config.js';

export function createAndStartTelemetryClient(config: TelemetryClientConfig): TelemetryClient {
export async function createAndStartTelemetryClient(config: TelemetryClientConfig): Promise<TelemetryClient> {
const log = createDebugLogger('aztec:telemetry-client');
if (config.metricsCollectorUrl) {
log.info('Using OpenTelemetry client');
return OpenTelemetryClient.createAndStart(config.metricsCollectorUrl, config.tracesCollectorUrl, log);
return await OpenTelemetryClient.createAndStart(config.metricsCollectorUrl, config.tracesCollectorUrl, log);
} else {
log.info('Using NoopTelemetryClient');
return new NoopTelemetryClient();
Expand Down

0 comments on commit 81c86f3

Please sign in to comment.