Skip to content

Commit 7f1b837

Browse files
authored
docs(js-sdk): document agent and logger configuration options (#7269)
1 parent ebee749 commit 7f1b837

File tree

2 files changed

+101
-11
lines changed

2 files changed

+101
-11
lines changed

packages/libraries/core/src/client/agent.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ export interface AgentOptions {
5454
* 5 by default
5555
*/
5656
maxRetries?: number;
57-
/**
58-
* 200 by default
59-
*/
60-
minTimeout?: number;
6157
/**
6258
* Send reports in interval (defaults to 10_000ms)
6359
*/
@@ -86,6 +82,8 @@ export interface AgentOptions {
8682
* used by the agent to send reports
8783
*/
8884
fetch?: typeof fetch;
85+
/** @deprecated This is no longer used. */
86+
minTimeout?: number;
8987
}
9088

9189
export function createAgent<TEvent>(

packages/web/docs/src/content/api-reference/client.mdx

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ Refer to the
4949
for complete list of options and configurations you can pass to the Hive JavaScript Client of
5050
choice.
5151

52-
#### Client Information
52+
#### Usage reporting
53+
54+
##### Client Information
5355

5456
By default, the client information is retrieved by looking up the `x-graphql-client-name` and
5557
`x-graphql-client-version` headers in the HTTP request. For operations executed via the
@@ -82,9 +84,9 @@ useHive({
8284
The context object is the context object as used within the GraphQL execution. Depending on your
8385
server framework and GraphQL protocol, the context object may contain different properties.
8486

85-
We recommend to always try to safely decode the context.
87+
We recommend to safely decode the context in order to avoid runtime errors.
8688

87-
#### Excluding Operations
89+
##### Excluding Operations
8890

8991
You can pass a custom `exclude` array to the `HivePluginOptions` to ignore specific operations from
9092
being reported to Hive.
@@ -97,9 +99,9 @@ useHive({
9799
})
98100
```
99101

100-
#### Sampling
102+
##### Sampling
101103

102-
##### Basic sampling
104+
###### Basic sampling
103105

104106
With `sampleRate` option, you're able to control the sampling rate of the usage reporting. Setting
105107
it to `0.5` will result in 50% of the operations being sent to Hive. There is no guarantee that
@@ -116,7 +118,7 @@ useHive({
116118
})
117119
```
118120

119-
##### Dynamic sampling
121+
###### Dynamic sampling
120122

121123
GraphQL Hive client accepts a function that returns a number between 0 and 1. This allows you to
122124
implement dynamic sampling based on the operation's context.
@@ -151,7 +153,7 @@ useHive({
151153
})
152154
```
153155

154-
##### At-least-once sampling
156+
###### At-least-once sampling
155157

156158
If you want to make sure that every operation is reported at least once, you can use the
157159
`atLeastOnceSampler`. Every operation is reported at least once, but every next occurrence is
@@ -321,6 +323,68 @@ useHive({
321323

322324
</Tabs>
323325

326+
##### Agent
327+
328+
The agent collects and schedules usage reporting call to the Hive Console usage reporting service.
329+
The configuration can be customized.
330+
331+
###### `maxRetries`
332+
333+
- Type: `number`
334+
- Default: `3`
335+
336+
Configure the maximum amount of retries per usage reporting batch before dropping the reporting
337+
attempts.
338+
339+
###### `maxSize`
340+
341+
- Type: `number`
342+
- Default: `25`
343+
344+
The maximum batch size of usage reports before sending the batch.
345+
346+
###### `sendInterval`
347+
348+
- Type: `number`
349+
- Default: `10_000`
350+
351+
The amount of time after which a pending usage reporting batch should be sent in case before the
352+
`maxSize` amount is reached.
353+
354+
###### `fetch`
355+
356+
- Type: [`Fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch)
357+
- Default: `fetch`
358+
359+
Provide a custom WHATWG `fetch` implementation
360+
361+
###### `circuitBreaker`
362+
363+
- Type: `AgentCircuitBreakerConfiguration`
364+
- Default:
365+
```js
366+
{
367+
/**
368+
* Percentage after what the circuit breaker should kick in.
369+
* Default: 50
370+
*/
371+
errorThresholdPercentage: 50,
372+
/**
373+
* Count of requests before starting evaluating.
374+
* Default: 10
375+
*/
376+
volumeThreshold: 10,
377+
/**
378+
* After what time the circuit breaker is attempting to retry sending requests in milliseconds
379+
* Default: 30_000
380+
*/
381+
resetTimeout: 30_000,
382+
}
383+
```
384+
385+
Configure the curcuit breaker for temporarily suspending sending usage reports in case of network
386+
issues or outages to avoid exhausting the service from being overwhelmed with failing HTTP requests.
387+
324388
#### Persisted Documents
325389

326390
Hive client supports resolving persisted documents. For getting started please refer to our
@@ -397,6 +461,34 @@ useHive({
397461
})
398462
```
399463

464+
#### Logging
465+
466+
You can customize the logging level or provide your own (JSON) logger implementation.
467+
468+
##### `logger`
469+
470+
- Type: [`Logger`](/docs/logger) or log level string
471+
- Default: `info`
472+
473+
It is possible to provide the following options:
474+
475+
- `'trace'`
476+
- `'debug'`
477+
- `'info'` default
478+
- `'warn'`
479+
- `'error'`
480+
481+
```ts filename="Example: Set debug level based on environment variable"
482+
import { createHive } from '@graphql-hive/core'
483+
484+
const client = createHive({
485+
logger: process.env.DEBUG === '1' ? 'debug' : 'info'
486+
})
487+
```
488+
489+
Alternatively, you can also provide your own [`Logger`](/docs/logger) (or any API-compatible
490+
implementation) to integrate Hive logs with your web server or logging solution.
491+
400492
#### Custom Integration
401493

402494
If your GraphQL server is not listed above, you can implement a custom integration. Start by

0 commit comments

Comments
 (0)