@graphql-hive/core
Version:
88 lines • 2.31 kB
text/typescript
import { fetch as defaultFetch } from '@whatwg-node/fetch';
import type { Logger } from './types.cjs';
type ReadOnlyResponse = Pick<Response, 'status' | 'text' | 'json' | 'statusText'>;
export type AgentCircuitBreakerConfiguration = {
/**
* Percentage after what the circuit breaker should kick in.
* Default: 50
*/
errorThresholdPercentage: number;
/**
* Count of requests before starting evaluating.
* Default: 5
*/
volumeThreshold: number;
/**
* After what time the circuit breaker is attempting to retry sending requests in milliseconds
* Default: 30_000
*/
resetTimeout: number;
};
export interface AgentOptions {
enabled?: boolean;
name?: string;
version?: string;
/**
* Hive endpoint or proxy
*/
endpoint: string;
/**
* API Token
*/
token: string;
/**
* 30s by default
*/
timeout?: number;
/**
* false by default
*/
debug?: boolean;
/**
* 5 by default
*/
maxRetries?: number;
/**
* 200 by default
*/
minTimeout?: number;
/**
* Send reports in interval (defaults to 10_000ms)
*/
sendInterval?: number;
/**
* Max number of traces to send at once (defaults to 25)
*/
maxSize?: number;
/**
* Custom logger (defaults to console)
*/
logger?: Logger;
/**
* WHATWG Compatible fetch implementation
* used by the agent to send reports
*/
fetch?: typeof defaultFetch;
/**
* Circuit Breaker Configuration.
* true -> Use default configuration
* false -> Disable
* object -> use custom configuration see {AgentCircuitBreakerConfiguration}
*/
circuitBreaker?: boolean | AgentCircuitBreakerConfiguration;
}
export declare function createAgent<TEvent>(pluginOptions: AgentOptions, { data, body, headers, }: {
data: {
clear(): void;
set(data: TEvent): void;
size(): number;
};
body(): Buffer | string | Promise<string | Buffer>;
headers?(): Record<string, string>;
}): {
capture: (event: TEvent | Promise<TEvent>) => void;
sendImmediately: (event: TEvent) => Promise<ReadOnlyResponse | null>;
dispose: () => Promise<void>;
};
export {};
//# sourceMappingURL=agent.d.ts.map