diff --git a/docker-compose.yml b/docker-compose.yml index 8e57ddd3532..996a31a373c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,7 +62,7 @@ services: P2P_ENABLED: true PEER_ID_PRIVATE_KEY: AZTEC_PORT: 8999 - TEL_COLLECTOR_BASE_URL: ${TEL_COLLECTOR_BASE_URL:-http://otel-collector:4318} + OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318} secrets: - ethereum-host - p2p-boot-node @@ -77,13 +77,13 @@ services: # if the stack is started with --profile metrics --profile node, give the collector a chance to start before the node i=0 max=3 - while ! curl --head --silent $$TEL_COLLECTOR_BASE_URL > /dev/null; do + while ! curl --head --silent $$OTEL_EXPORTER_OTLP_ENDPOINT > /dev/null; do echo "OpenTelemetry collector not up. Retrying after 1s"; sleep 1; i=$$((i+1)); if [ $$i -eq $$max ]; then - echo "OpenTelemetry collector at $$TEL_COLLECTOR_BASE_URL not up after $${max}s. Running without metrics"; - unset TEL_COLLECTOR_BASE_URL; + echo "OpenTelemetry collector at $$OTEL_EXPORTER_OTLP_ENDPOINT not up after $${max}s. Running without metrics"; + unset OTEL_EXPORTER_OTLP_ENDPOINT; break fi; done; diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index fb611a1709b..a276f7cc3a1 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -28,6 +28,7 @@ import { type EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; +import { Timer } from '@aztec/foundation/timer'; import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer'; import { type TelemetryClient } from '@aztec/telemetry-client'; import { @@ -291,8 +292,12 @@ export class Archiver implements ArchiveSource { ); if (retrievedBlocks.retrievedData.length > 0) { + const timer = new Timer(); await this.store.addBlocks(retrievedBlocks); - this.instrumentation.processNewBlocks(retrievedBlocks.retrievedData); + this.instrumentation.processNewBlocks( + timer.ms() / retrievedBlocks.retrievedData.length, + retrievedBlocks.retrievedData, + ); const lastL2BlockNumber = retrievedBlocks.retrievedData[retrievedBlocks.retrievedData.length - 1].number; this.log.verbose(`Processed ${retrievedBlocks.retrievedData.length} new L2 blocks up to ${lastL2BlockNumber}`); } diff --git a/yarn-project/archiver/src/archiver/instrumentation.ts b/yarn-project/archiver/src/archiver/instrumentation.ts index 837b00af7f2..ccfaf063de8 100644 --- a/yarn-project/archiver/src/archiver/instrumentation.ts +++ b/yarn-project/archiver/src/archiver/instrumentation.ts @@ -1,9 +1,17 @@ import { type L2Block } from '@aztec/circuit-types'; -import { type Gauge, type Histogram, Metrics, type TelemetryClient, ValueType } from '@aztec/telemetry-client'; +import { + type Gauge, + type Histogram, + Metrics, + type TelemetryClient, + ValueType, + exponentialBuckets, +} from '@aztec/telemetry-client'; export class ArchiverInstrumentation { private blockHeight: Gauge; - private blockSize: Histogram; + private blockSize: Gauge; + private syncDuration: Histogram; constructor(telemetry: TelemetryClient) { const meter = telemetry.getMeter('Archiver'); @@ -12,16 +20,23 @@ export class ArchiverInstrumentation { valueType: ValueType.INT, }); - this.blockSize = meter.createHistogram(Metrics.ARCHIVER_BLOCK_SIZE, { - description: 'The number of transactions processed per block', + this.blockSize = meter.createGauge(Metrics.ARCHIVER_BLOCK_SIZE, { + description: 'The number of transactions in a block', + valueType: ValueType.INT, + }); + + this.syncDuration = meter.createHistogram(Metrics.ARCHIVER_SYNC_DURATION, { + unit: 'ms', + description: 'Duration to sync a block', valueType: ValueType.INT, advice: { - explicitBucketBoundaries: [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192], + explicitBucketBoundaries: exponentialBuckets(1, 16), }, }); } - public processNewBlocks(blocks: L2Block[]) { + public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) { + this.syncDuration.record(syncTimePerBlock); this.blockHeight.record(Math.max(...blocks.map(b => b.number))); for (const block of blocks) { this.blockSize.record(block.body.txEffects.length); diff --git a/yarn-project/aztec/terraform/node/main.tf b/yarn-project/aztec/terraform/node/main.tf index d4d8ffd881e..4b34b91b9fd 100644 --- a/yarn-project/aztec/terraform/node/main.tf +++ b/yarn-project/aztec/terraform/node/main.tf @@ -337,11 +337,11 @@ resource "aws_ecs_task_definition" "aztec-node" { value = tostring(var.PROVING_ENABLED) }, { - name = "TEL_COLLECTOR_BASE_URL" + name = "OTEL_EXPORTER_OTLP_ENDPOINT" value = "http://aztec-otel.local:4318" }, { - name = "TEL_SERVICE_NAME" + name = "OTEL_SERVICE_NAME" value = "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}" }, { @@ -357,7 +357,7 @@ resource "aws_ecs_task_definition" "aztec-node" { value = "info" }, { - name = "TEL_NETWORK_ID", + name = "NETWORK_NAME", value = "${var.DEPLOY_TAG}" } ] diff --git a/yarn-project/aztec/terraform/prover/main.tf b/yarn-project/aztec/terraform/prover/main.tf index c6e3ff8c206..8068de53442 100644 --- a/yarn-project/aztec/terraform/prover/main.tf +++ b/yarn-project/aztec/terraform/prover/main.tf @@ -270,15 +270,15 @@ resource "aws_ecs_task_definition" "aztec-proving-agent" { "value": "${var.PROVING_ENABLED}" }, { - "name": "TEL_COLLECTOR_BASE_URL", + "name": "OTEL_EXPORTER_OTLP_ENDPOINT", "value": "http://aztec-otel.local:4318" }, { - "name": "TEL_SERVICE_NAME", + "name": "OTEL_SERVICE_NAME", "value": "${var.DEPLOY_TAG}-aztec-proving-agent-group-${count.index + 1}" }, { - "name": "TEL_NETWORK_ID", + "name": "NETWORK_NAME", "value": "${var.DEPLOY_TAG}" } ], diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index e303604f2b9..c050f4cc42c 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -476,7 +476,7 @@ export class BBNativeRollupProver implements ServerCircuitProver { this.instrumentation.recordSize('witGenInputSize', circuitName, input.toBuffer().length); this.instrumentation.recordSize('witGenOutputSize', circuitName, output.toBuffer().length); - logger.debug(`Generated witness`, { + logger.info(`Generated witness`, { circuitName, duration: timer.ms(), inputSize: input.toBuffer().length, diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index 93706d65689..6e05a4bfcd8 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -35,10 +35,9 @@ export type EnvVar = | 'P2P_QUERY_FOR_IP' | 'P2P_TX_POOL_KEEP_PROVEN_FOR' | 'TELEMETRY' - | 'TEL_COLLECTOR_BASE_URL' - | 'TEL_SERVICE_NAME' - | 'TEL_SERVICE_VERSION' - | 'TEL_NETWORK_ID' + | 'OTEL_EXPORTER_OTLP_ENDPOINT' + | 'OTEL_SERVICE_NAME' + | 'NETWORK_NAME' | 'NETWORK' | 'API_KEY' | 'AZTEC_NODE_URL' diff --git a/yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.ts b/yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.ts index 043869d3121..4037e4cbb15 100644 --- a/yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.ts +++ b/yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.ts @@ -42,12 +42,16 @@ export class AztecKVTxPool implements TxPool { public markAsMined(txHashes: TxHash[]): Promise { return this.#store.transaction(() => { + let deleted = 0; for (const hash of txHashes) { const key = hash.toString(); void this.#minedTxs.add(key); - void this.#pendingTxs.delete(key); + if (this.#pendingTxs.has(key)) { + deleted++; + void this.#pendingTxs.delete(key); + } } - this.#metrics.recordRemovedTxs('pending', txHashes.length); + this.#metrics.recordRemovedTxs('pending', deleted); this.#metrics.recordAddedTxs('mined', txHashes.length); }); } diff --git a/yarn-project/sequencer-client/src/sequencer/metrics.ts b/yarn-project/sequencer-client/src/sequencer/metrics.ts index 858c42455cb..8610a868b79 100644 --- a/yarn-project/sequencer-client/src/sequencer/metrics.ts +++ b/yarn-project/sequencer-client/src/sequencer/metrics.ts @@ -1,5 +1,6 @@ import { Attributes, + type Gauge, type Histogram, Metrics, type TelemetryClient, @@ -9,20 +10,21 @@ import { millisecondBuckets, } from '@aztec/telemetry-client'; +type SequencerStateCallback = () => number; + export class SequencerMetrics { public readonly tracer: Tracer; - private cancelledBlockCounter: UpDownCounter; - private blocksBuiltCounter: UpDownCounter; + private blockCounter: UpDownCounter; private blockBuildDuration: Histogram; - private blockTxCount: Histogram; + private currentBlockNumber: Gauge; + private currentBlockSize: Gauge; - constructor(client: TelemetryClient, name = 'Sequencer') { + constructor(client: TelemetryClient, getState: SequencerStateCallback, name = 'Sequencer') { const meter = client.getMeter(name); this.tracer = client.getTracer(name); - this.cancelledBlockCounter = meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_BUILD_CANCELLED_COUNT); - this.blocksBuiltCounter = meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_BUILD_COUNT); + this.blockCounter = meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT); this.blockBuildDuration = meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, { unit: 'ms', description: 'Duration to build a block', @@ -32,30 +34,53 @@ export class SequencerMetrics { }, }); - this.blockTxCount = meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_TX_COUNT, { - description: 'Number of transactions in a block', - valueType: ValueType.INT, + const currentState = meter.createObservableGauge(Metrics.SEQUENCER_CURRENT_STATE, { + description: 'Current state of the sequencer', + }); + + currentState.addCallback(observer => { + observer.observe(getState()); + }); + + this.currentBlockNumber = meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_NUMBER, { + description: 'Current block number', }); + + this.currentBlockSize = meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_SIZE, { + description: 'Current block number', + }); + + this.setCurrentBlock(0, 0); } recordCancelledBlock() { - this.cancelledBlockCounter.add(1); + this.blockCounter.add(1, { + [Attributes.STATUS]: 'cancelled', + }); + this.setCurrentBlock(0, 0); } recordPublishedBlock(buildDurationMs: number) { - this.blocksBuiltCounter.add(1, { - [Attributes.OK]: true, + this.blockCounter.add(1, { + [Attributes.STATUS]: 'published', }); this.blockBuildDuration.record(Math.ceil(buildDurationMs)); + this.setCurrentBlock(0, 0); } recordFailedBlock() { - this.blocksBuiltCounter.add(1, { - [Attributes.OK]: false, + this.blockCounter.add(1, { + [Attributes.STATUS]: 'failed', }); + this.setCurrentBlock(0, 0); + } + + recordNewBlock(blockNumber: number, txCount: number) { + this.setCurrentBlock(blockNumber, txCount); } - recordNewBlock(txCount: number) { - this.blockTxCount.record(txCount); + private setCurrentBlock(blockNumber: number, txCount: number) { + this.currentBlockNumber.record(blockNumber); + this.currentBlockSize.record(txCount); } } diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 2a08c56dae2..758cfa7b740 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -71,7 +71,7 @@ export class Sequencer { private log = createDebugLogger('aztec:sequencer'), ) { this.updateConfig(config); - this.metrics = new SequencerMetrics(telemetry, 'Sequencer'); + this.metrics = new SequencerMetrics(telemetry, () => this.state, 'Sequencer'); this.log.verbose(`Initialized sequencer with ${this.minTxsPerBLock}-${this.maxTxsPerBlock} txs per block.`); } @@ -284,7 +284,7 @@ export class Sequencer { historicalHeader: Header | undefined, elapsedSinceLastBlock: number, ): Promise { - this.metrics.recordNewBlock(validTxs.length); + this.metrics.recordNewBlock(newGlobalVariables.blockNumber.toNumber(), validTxs.length); const workTimer = new Timer(); this.state = SequencerState.CREATING_BLOCK; this.log.info(`Building block ${newGlobalVariables.blockNumber.toNumber()} with ${validTxs.length} transactions`); @@ -368,7 +368,9 @@ export class Sequencer { try { await this.publishL2Block(block); this.metrics.recordPublishedBlock(workDuration); - this.log.info(`Submitted rollup block ${block.number} with ${processedTxs.length} transactions`); + this.log.info( + `Submitted rollup block ${block.number} with ${processedTxs.length} transactions duration=${workDuration}ms`, + ); } catch (err) { this.metrics.recordFailedBlock(); throw err; diff --git a/yarn-project/telemetry-client/package.json b/yarn-project/telemetry-client/package.json index d937716d35f..6647847ff44 100644 --- a/yarn-project/telemetry-client/package.json +++ b/yarn-project/telemetry-client/package.json @@ -31,6 +31,7 @@ "@opentelemetry/exporter-metrics-otlp-http": "^0.52.0", "@opentelemetry/exporter-trace-otlp-http": "^0.52.0", "@opentelemetry/host-metrics": "^0.35.2", + "@opentelemetry/resource-detector-aws": "^1.5.2", "@opentelemetry/resources": "^1.25.0", "@opentelemetry/sdk-metrics": "^1.25.0", "@opentelemetry/sdk-trace-node": "^1.25.0", diff --git a/yarn-project/telemetry-client/src/attributes.ts b/yarn-project/telemetry-client/src/attributes.ts index 8a47a7d486e..728d2b0c73e 100644 --- a/yarn-project/telemetry-client/src/attributes.ts +++ b/yarn-project/telemetry-client/src/attributes.ts @@ -15,7 +15,7 @@ */ /** The Aztec network identifier */ -export const NETWORK_ID = 'aztec.network.id'; +export const NETWORK_NAME = 'aztec.network_name'; /** * The name of the protocol circuit being run (e.g. public-kernel-setup or base-rollup) diff --git a/yarn-project/telemetry-client/src/aztec_resource_detector.ts b/yarn-project/telemetry-client/src/aztec_resource_detector.ts new file mode 100644 index 00000000000..24da4e0d92e --- /dev/null +++ b/yarn-project/telemetry-client/src/aztec_resource_detector.ts @@ -0,0 +1,19 @@ +import { type DetectorSync, type IResource, Resource } from '@opentelemetry/resources'; + +import { NETWORK_NAME } from './attributes.js'; +import { getConfigEnvVars } from './config.js'; + +/** + * Detector for custom Aztec attributes + */ +class AztecDetector implements DetectorSync { + detect(): IResource { + const config = getConfigEnvVars(); + + return new Resource({ + [NETWORK_NAME]: config.networkName, + }); + } +} + +export const aztecDetector = new AztecDetector(); diff --git a/yarn-project/telemetry-client/src/config.ts b/yarn-project/telemetry-client/src/config.ts new file mode 100644 index 00000000000..0943394b842 --- /dev/null +++ b/yarn-project/telemetry-client/src/config.ts @@ -0,0 +1,29 @@ +import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config'; + +export interface TelemetryClientConfig { + collectorBaseUrl?: URL; + serviceName: string; + networkName: string; +} + +export const telemetryClientConfigMappings: ConfigMappingsType = { + collectorBaseUrl: { + env: 'OTEL_EXPORTER_OTLP_ENDPOINT', + description: 'The URL of the telemetry collector', + parseEnv: (val: string) => new URL(val), + }, + serviceName: { + env: 'OTEL_SERVICE_NAME', + description: 'The URL of the telemetry collector', + default: 'aztec', + }, + networkName: { + env: 'NETWORK_NAME', + description: 'The network ID of the telemetry service', + default: 'local', + }, +}; + +export function getConfigEnvVars(): TelemetryClientConfig { + return getConfigFromMappings(telemetryClientConfigMappings); +} diff --git a/yarn-project/telemetry-client/src/metrics.ts b/yarn-project/telemetry-client/src/metrics.ts index 67095735d0e..984862b425a 100644 --- a/yarn-project/telemetry-client/src/metrics.ts +++ b/yarn-project/telemetry-client/src/metrics.ts @@ -26,16 +26,18 @@ export const CIRCUIT_SIZE = 'aztec.circuit.size'; export const MEMPOOL_TX_COUNT = 'aztec.mempool.tx_count'; export const MEMPOOL_TX_SIZE = 'aztec.mempool.tx_size'; +export const ARCHIVER_SYNC_DURATION = 'aztec.archiver.sync_duration'; export const ARCHIVER_BLOCK_HEIGHT = 'aztec.archiver.block_height'; export const ARCHIVER_BLOCK_SIZE = 'aztec.archiver.block_size'; export const NODE_RECEIVE_TX_DURATION = 'aztec.node.receive_tx.duration'; export const NODE_RECEIVE_TX_COUNT = 'aztec.node.receive_tx.count'; -export const SEQUENCER_BLOCK_BUILD_DURATION = 'aztec.sequencer.block_build.duration'; -export const SEQUENCER_BLOCK_BUILD_COUNT = 'aztec.sequencer.block_build.ok_count'; -export const SEQUENCER_BLOCK_BUILD_CANCELLED_COUNT = 'aztec.sequencer.block_build.cancelled_count'; -export const SEQUENCER_BLOCK_BUILD_TX_COUNT = 'aztec.sequencer.block_build.tx_count'; +export const SEQUENCER_BLOCK_BUILD_DURATION = 'aztec.sequencer.block.build_duration'; +export const SEQUENCER_BLOCK_COUNT = 'aztec.sequencer.block.count'; +export const SEQUENCER_CURRENT_STATE = 'aztec.sequencer.current.state'; +export const SEQUENCER_CURRENT_BLOCK_NUMBER = 'aztec.sequencer.current.block_number'; +export const SEQUENCER_CURRENT_BLOCK_SIZE = 'aztec.sequencer.current.block_size'; export const L1_PUBLISHER_GAS_PRICE = 'aztec.l1_publisher.gas_price'; export const L1_PUBLISHER_TX_COUNT = 'aztec.l1_publisher.tx_count'; diff --git a/yarn-project/telemetry-client/src/otel.ts b/yarn-project/telemetry-client/src/otel.ts index 8d1e5be21a4..0a95433dc2b 100644 --- a/yarn-project/telemetry-client/src/otel.ts +++ b/yarn-project/telemetry-client/src/otel.ts @@ -11,12 +11,20 @@ import { import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; import { HostMetrics } from '@opentelemetry/host-metrics'; -import { Resource } from '@opentelemetry/resources'; +import { awsEc2Detector, awsEcsDetector } from '@opentelemetry/resource-detector-aws'; +import { + type IResource, + detectResourcesSync, + envDetectorSync, + osDetectorSync, + processDetectorSync, + serviceInstanceIdDetectorSync, +} from '@opentelemetry/resources'; import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'; import { BatchSpanProcessor, NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION } from '@opentelemetry/semantic-conventions'; -import { NETWORK_ID } from './attributes.js'; +import { aztecDetector } from './aztec_resource_detector.js'; import { type Gauge, type TelemetryClient } from './telemetry.js'; export class OpenTelemetryClient implements TelemetryClient { @@ -24,7 +32,7 @@ export class OpenTelemetryClient implements TelemetryClient { targetInfo: Gauge | undefined; protected constructor( - private resource: Resource, + private resource: IResource, private meterProvider: MeterProvider, private traceProvider: TracerProvider, private log: DebugLogger, @@ -53,7 +61,14 @@ export class OpenTelemetryClient implements TelemetryClient { this.targetInfo = this.meterProvider.getMeter('target').createGauge('target_info', { description: 'Target information', }); - this.targetInfo.record(1, this.resource.attributes); + + 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.hostMetrics.start(); } @@ -62,17 +77,17 @@ export class OpenTelemetryClient implements TelemetryClient { await Promise.all([this.meterProvider.shutdown()]); } - public static createAndStart( - name: string, - version: string, - networkIdentifier: string, - collectorBaseUrl: URL, - log: DebugLogger, - ): OpenTelemetryClient { - const resource = new Resource({ - [SEMRESATTRS_SERVICE_NAME]: name, - [SEMRESATTRS_SERVICE_VERSION]: version, - [NETWORK_ID]: networkIdentifier, + public static createAndStart(collectorBaseUrl: URL, log: DebugLogger): OpenTelemetryClient { + const resource = detectResourcesSync({ + detectors: [ + osDetectorSync, + envDetectorSync, + processDetectorSync, + serviceInstanceIdDetectorSync, + awsEc2Detector, + awsEcsDetector, + aztecDetector, + ], }); const tracerProvider = new NodeTracerProvider({ diff --git a/yarn-project/telemetry-client/src/start.ts b/yarn-project/telemetry-client/src/start.ts index ca8e557f6c6..5425107e7ee 100644 --- a/yarn-project/telemetry-client/src/start.ts +++ b/yarn-project/telemetry-client/src/start.ts @@ -1,57 +1,19 @@ -import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config'; import { createDebugLogger } from '@aztec/foundation/log'; +import { type TelemetryClientConfig } from './config.js'; import { NoopTelemetryClient } from './noop.js'; import { OpenTelemetryClient } from './otel.js'; import { type TelemetryClient } from './telemetry.js'; -export interface TelemetryClientConfig { - collectorBaseUrl?: URL; - serviceName: string; - serviceVersion: string; - networkId: string; -} - -export const telemetryClientConfigMappings: ConfigMappingsType = { - collectorBaseUrl: { - env: 'TEL_COLLECTOR_BASE_URL', - description: 'The URL of the telemetry collector', - parseEnv: (val: string) => new URL(val), - }, - serviceName: { - env: 'TEL_SERVICE_NAME', - description: 'The name of the telemetry service', - default: 'aztec', - }, - serviceVersion: { - env: 'TEL_SERVICE_VERSION', - description: 'The version of the telemetry service', - default: '0.0.0', - }, - networkId: { - env: 'TEL_NETWORK_ID', - description: 'The network ID of the telemetry service', - default: 'local', - }, -}; +export * from './config.js'; export function createAndStartTelemetryClient(config: TelemetryClientConfig): TelemetryClient { const log = createDebugLogger('aztec:telemetry-client'); if (config.collectorBaseUrl) { log.info('Using OpenTelemetry client'); - return OpenTelemetryClient.createAndStart( - config.serviceName, - config.serviceVersion, - config.networkId, - config.collectorBaseUrl, - log, - ); + return OpenTelemetryClient.createAndStart(config.collectorBaseUrl, log); } else { log.info('Using NoopTelemetryClient'); return new NoopTelemetryClient(); } } - -export function getConfigEnvVars(): TelemetryClientConfig { - return getConfigFromMappings(telemetryClientConfigMappings); -} diff --git a/yarn-project/telemetry-client/src/telemetry.ts b/yarn-project/telemetry-client/src/telemetry.ts index bf56bf51af5..b52e5bae1e8 100644 --- a/yarn-project/telemetry-client/src/telemetry.ts +++ b/yarn-project/telemetry-client/src/telemetry.ts @@ -3,6 +3,8 @@ import { type MetricOptions, type Gauge as OtelGauge, type Histogram as OtelHistogram, + type ObservableGauge as OtelObservableGauge, + type ObservableUpDownCounter as OtelObservableUpDownCounter, type UpDownCounter as OtelUpDownCounter, type Span, SpanStatusCode, @@ -27,6 +29,8 @@ export { Metrics }; export type Gauge = OtelGauge; export type Histogram = OtelHistogram; export type UpDownCounter = OtelUpDownCounter; +export type ObservableGauge = OtelObservableGauge; +export type ObservableUpDownCounter = OtelObservableUpDownCounter; export { Tracer }; @@ -42,6 +46,13 @@ export interface Meter { */ createGauge(name: Metrics, options?: MetricOptions): Gauge; + /** + * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down. + * @param name - The name of the gauge + * @param options - The options for the gauge + */ + createObservableGauge(name: Metrics, options?: MetricOptions): ObservableGauge; + /** * Creates a new histogram instrument. A histogram is a metric that samples observations (usually things like request durations or response sizes) and counts them in configurable buckets. * @param name - The name of the histogram @@ -55,6 +66,13 @@ export interface Meter { * @param options - The options for the counter */ createUpDownCounter(name: Metrics, options?: MetricOptions): UpDownCounter; + + /** + * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down. + * @param name - The name of the gauge + * @param options - The options for the gauge + */ + createObservableUpDownCounter(name: Metrics, options?: MetricOptions): ObservableUpDownCounter; } /** diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 39a58dd856e..27e1a445520 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -1031,6 +1031,7 @@ __metadata: "@opentelemetry/exporter-metrics-otlp-http": ^0.52.0 "@opentelemetry/exporter-trace-otlp-http": ^0.52.0 "@opentelemetry/host-metrics": ^0.35.2 + "@opentelemetry/resource-detector-aws": ^1.5.2 "@opentelemetry/resources": ^1.25.0 "@opentelemetry/sdk-metrics": ^1.25.0 "@opentelemetry/sdk-trace-node": ^1.25.0 @@ -3148,6 +3149,17 @@ __metadata: languageName: node linkType: hard +"@opentelemetry/core@npm:1.25.1, @opentelemetry/core@npm:^1.0.0": + version: 1.25.1 + resolution: "@opentelemetry/core@npm:1.25.1" + dependencies: + "@opentelemetry/semantic-conventions": 1.25.1 + peerDependencies: + "@opentelemetry/api": ">=1.0.0 <1.10.0" + checksum: ba1672fde4a1cfd9b55bf6070db71b808702fe59c4a70cda52a6156b2c813827954a6b4d3c3641283d394ff75a69b6359a0487459b4d26cd7d714ab3d21bc780 + languageName: node + linkType: hard + "@opentelemetry/exporter-metrics-otlp-http@npm:^0.52.0": version: 0.52.0 resolution: "@opentelemetry/exporter-metrics-otlp-http@npm:0.52.0" @@ -3241,6 +3253,19 @@ __metadata: languageName: node linkType: hard +"@opentelemetry/resource-detector-aws@npm:^1.5.2": + version: 1.5.2 + resolution: "@opentelemetry/resource-detector-aws@npm:1.5.2" + dependencies: + "@opentelemetry/core": ^1.0.0 + "@opentelemetry/resources": ^1.0.0 + "@opentelemetry/semantic-conventions": ^1.22.0 + peerDependencies: + "@opentelemetry/api": ^1.0.0 + checksum: c58274117fb6a44593aab1135f11d39770a69a1a14108a826086a36a7108de13d0d9df333cf5533e98d40f751b20d8a3284426bfcd5dcc941157458bbba7fe1c + languageName: node + linkType: hard + "@opentelemetry/resources@npm:1.25.0, @opentelemetry/resources@npm:^1.25.0": version: 1.25.0 resolution: "@opentelemetry/resources@npm:1.25.0" @@ -3253,6 +3278,18 @@ __metadata: languageName: node linkType: hard +"@opentelemetry/resources@npm:^1.0.0": + version: 1.25.1 + resolution: "@opentelemetry/resources@npm:1.25.1" + dependencies: + "@opentelemetry/core": 1.25.1 + "@opentelemetry/semantic-conventions": 1.25.1 + peerDependencies: + "@opentelemetry/api": ">=1.0.0 <1.10.0" + checksum: 806e5aabbc93afcab767dc84707f702ca51bbc93e4565eb69a8591ed2fe78439aca19c5ca0d9f044c85ed97b9efb35936fdb65bef01f5f3e68504002c8a07220 + languageName: node + linkType: hard + "@opentelemetry/sdk-logs@npm:0.52.0": version: 0.52.0 resolution: "@opentelemetry/sdk-logs@npm:0.52.0" @@ -3315,6 +3352,13 @@ __metadata: languageName: node linkType: hard +"@opentelemetry/semantic-conventions@npm:1.25.1, @opentelemetry/semantic-conventions@npm:^1.22.0": + version: 1.25.1 + resolution: "@opentelemetry/semantic-conventions@npm:1.25.1" + checksum: fea418a4b09c55121c6da11c49dd2105116533838c484aead17e8acf8029dad711e145849812f9c61f9e48fad8e2b6cf103d2c18847ca993032ce9b27c2f863d + languageName: node + linkType: hard + "@pkgjs/parseargs@npm:^0.11.0": version: 0.11.0 resolution: "@pkgjs/parseargs@npm:0.11.0"