UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

44 lines (43 loc) 1.96 kB
import { QueryMetricsRequest, QueryMetricsResponse } from '../../internal-common/src/public-types/metric.public-types'; /** * A client for reporting user metrics and querying both application-related Squid and user metrics. * @category Platform */ export declare class ObservabilityClient { private readonly rpcManager; private pendingPromises; private isReporting; /** * Reports metrics to the metric submission queue. * The metric can be sent immediately or with some (several seconds) delay * due to optimizations applied by Squid client. * If no tags are provided tags are set to an empty record ({}). * If no timestamp is provided the timestamp is set to now(). */ reportMetric<MetricNameType = string>(metric: MetricReport<MetricNameType>): void; /** * Flushes all pending (unsent) metrics. * Note: Even after flushing, it may take some time for these metrics to become visible via 'queryMetrics' due to the * eventual consistency of the metrics storage. */ flush(): Promise<void>; /** Queries a batch of metric values. */ queryMetrics<MetricName extends string = string>(metricRequest: QueryMetricsRequest<MetricName>): Promise<QueryMetricsResponse<MetricName>>; } /** A single metric event. */ export interface Metric<MetricNameType = string> { /** Name of the metric. */ name: MetricNameType; /** Value of the metric. */ value: number; /** Time associated with the metric. Milliseconds since UNIX epoch. */ timestamp: number; /** Set of tags for the metric. */ tags: Record<string, string>; } /** * MetricReport represents a single metric event with some optional fields. * These optional fields are automatically populated by Squid with default values. * @category Platform */ export type MetricReport<MetricNameType = string> = Omit<Metric<MetricNameType>, 'tags' | 'timestamp'> & Partial<Pick<Metric, 'tags' | 'timestamp'>>;