/** * @license * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { SdkLogRecord } from '@opentelemetry/sdk-logs'; /** * Represents the identifier for a telemetry event buffer, which can be a trace ID or a generated UUID. */ type EventId = string; /** * A shared storage engine that buffers telemetry logs and spans in memory, * organizing them by trace/log hierarchies and managing structural capacity limits. * * @internal */ export declare class TelemetryStore { static readonly DEFAULT_BUFFER_LIMIT = 1000; private readonly _rootTelemetryQueue; private readonly _bufferLimit; private readonly _telemetryBufferMap; private _totalTelemetryCount; private _shouldAddLimitLog; /** * Creates a new instance of TelemetryStore. * * @param bufferLimit - The maximum total count of telemetry items (spans + logs) allowed in the store. Defaults to 1000. * @param queueLimit - The maximum number of root telemetry items allowed in the eviction queue. Defaults to 100. */ constructor(bufferLimit?: number, queueLimit?: number); /** The total count of all telemetry items (spans and logs) currently in the store. */ get totalTelemetryCount(): number; /** * Adds a telemetry event (either a span or log) to the store. * Organizes the events by their trace or standalone hierarchies and evicts the oldest items if capacity is exceeded. * * @param event - The telemetry event to add. */ add(event: ReadableSpan | SdkLogRecord): void; /** * Updates an existing span in the store. * If the span is a root span, it enqueues it, marking it as completed. * * @param event - The span to update. */ update(event: ReadableSpan): void; /** * Gets all buffered spans from completed root traces currently in the queue. */ getSpansToExport(): ReadableSpan[]; /** * Gets all buffered log records from completed root traces and standalone root logs currently in the queue. */ getLogsToExport(): SdkLogRecord[]; /** Clear all buffered telemetry and reset state. */ clear(): void; /** * Retrieves the ID associated with a telemetry event. * For root logs, generates a new UUID. * * @param event - The telemetry event. */ private _getEventId; /** * Checks if the buffer currently has capacity for more telemetry events. */ private _bufferHasCapacity; /** * Checks if the root telemetry queue is empty. */ private _isQueueEmpty; /** * Evicts the oldest root telemetry item (trace or root log) to free up buffer capacity. */ private _evictOldest; /** * Evicts a telemetry item (either a trace hierarchy or a standalone root log record) from the buffer * and decrements its size from the total telemetry counter. * * @param key - The map key (trace ID or log UUID) to evict. */ private _maybeEvictIdFromBuffer; } /** * A type-safe queue designed for telemetry tracking with amortized O(1) performance * for both enqueue and dequeue operations. * * @internal */ export declare class RootTelemetryQueue { private readonly _limit; static readonly DEFAULT_LIMIT = 100; private readonly _items; private _head; private _tail; private _size; /** * Creates a new instance of RootTelemetryQueue. * * @param _limit - The maximum size limit of the queue. Defaults to 100. */ constructor(_limit?: number); /** * Gets the current number of items in the queue. */ get size(): number; /** * Checks if the queue has reached its maximum size limit. */ isFull(): boolean; /** * Enqueues an item into the queue. * If the queue is already full, this operation does nothing. * * @param item - The item to enqueue. */ enqueue(item: EventId): void; /** * Dequeues the oldest item from the queue. */ dequeue(): EventId | undefined; /** * Gets the oldest item from the queue without removing it, or `undefined` if the queue is empty. */ peek(): EventId | undefined; /** * Gets the ordered items currently in the queue. */ getValues(): EventId[]; /** * Clears all items from the queue and resets its state. */ clear(): void; } export {};