Skip to content

Commit e934822

Browse files
docs(router): usage reporting (#7171)
Co-authored-by: Kamil Kisiela <[email protected]>
1 parent b07f3e4 commit e934822

File tree

5 files changed

+239
-0
lines changed

5 files changed

+239
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Usage Reporting in Hive Router
3+
description:
4+
Hive Router (Rust) now supports Usage Reporting, allowing you to send operation metrics to Hive
5+
Console
6+
date: 2025-11-28
7+
authors: [kamil]
8+
---
9+
10+
[Hive Router (Rust)](/docs/router) now supports
11+
[Usage Reporting](/docs/schema-registry/usage-reporting), enabling you to send metrics about your
12+
GraphQL operations directly to Hive Console. This integration allows you to monitor performance,
13+
track schema usage, and analyze client activity for traffic handled by Router.
14+
15+
## Configuration
16+
17+
We've added a `usage_reporting` configuration object that gives you full control over how usage data
18+
is reported. You can configure sampling rates, buffer sizes, timeouts, and more to ensure reporting
19+
doesn't impact your router's performance.
20+
21+
Here is an example configuration:
22+
23+
```yaml filename="router.config.yaml"
24+
usage_reporting:
25+
# Enable reporting by providing your access token
26+
access_token: 'your-secret-token' # or set HIVE_ACCESS_TOKEN env var
27+
target_id: 'your-target-id' # or set HIVE_TARGET env var
28+
29+
# Report 50% of requests
30+
sample_rate: 50%
31+
32+
# Buffer settings
33+
flush_interval: 10s
34+
buffer_size: 500
35+
36+
# Exclude specific operations
37+
exclude:
38+
- IntrospectionQuery
39+
40+
# Custom client identification headers
41+
client_name_header: 'x-client-name'
42+
client_version_header: 'x-client-version'
43+
```
44+
45+
## Key Options
46+
47+
- **`sample_rate`**: Control the percentage of requests to report (e.g., `100%` for all traffic, or
48+
`10%` for sampling).
49+
- **`buffer_size` and `flush_interval`**: Optimize network usage by batching reports.
50+
- **`exclude`**: Filter out specific operations (like introspection) from being reported.
51+
- **`client_name_header` and `client_version_header`**: Customize how clients are identified in your
52+
metrics.
53+
54+
For a complete reference of all available options, please see the
55+
[Usage Reporting documentation](/docs/router/configuration/usage_reporting).

packages/web/docs/src/content/router/configuration/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ that explains how to use that feature.
3030
- [`supergraph`](./configuration/supergraph): Tell the router where to find your supergraph schema.
3131
- [`traffic_shaping`](./configuration/traffic_shaping): Manage connection pooling and request
3232
handling to subgraphs.
33+
- [`usage_reporting`](./configuration/usage_reporting): Configure usage reporting to Hive Console.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
title: 'usage_reporting'
3+
---
4+
5+
# usage_reporting
6+
7+
The `usage_reporting` configuration object allows you to control over how the Hive Router does
8+
[usage reporting](../../schema-registry/usage-reporting) to Hive Console.
9+
10+
## Options
11+
12+
### `access_token`
13+
14+
- **Type:** `string`
15+
16+
Your
17+
[Registry Access Token](https://the-guild.dev/graphql/hive/docs/management/targets#registry-access-tokens)
18+
with write permission.
19+
20+
Alternatively, you can set the `HIVE_ACCESS_TOKEN` environment variable to provide the token.
21+
22+
### `target_id`
23+
24+
- **Type:** `string`
25+
26+
A target ID, this can either be a slug following the format
27+
`$organizationSlug/$projectSlug/$targetSlug` (e.g `the-guild/graphql-hive/staging`) or an UUID (e.g.
28+
`a0f4c605-6541-4350-8cfe-b31f21a4bf80`). To be used when the token is configured with an
29+
organization access token.
30+
31+
Alternatively, you can set the `HIVE_TARGET` environment variable to provide the target ID.
32+
33+
### `endpoint`
34+
35+
- **Type:** `string`
36+
- **Default:** `https://app.graphql-hive.com/usage`
37+
38+
For self-hosting, you can override `/usage` endpoint of your Hive instance.
39+
40+
### `sample_rate`
41+
42+
- **Type:** `string`
43+
- **Default:** `100%`
44+
45+
A percentage value between `0%` and `100%` that indicates the percentage of requests to be reported.
46+
For example, a value of `10%` means that approximately 10% of requests will be reported, while a
47+
value of `100%` means that all requests will be reported.
48+
49+
### `exclude`
50+
51+
- **Type:** `string[]`
52+
- **Default:** `[]`
53+
54+
A list of operations (by name) to be ignored by Hive. For example, if you want to exclude
55+
introspection queries, you can add `IntrospectionQuery` to this list.
56+
57+
### `client_name_header`
58+
59+
- **Type:** `string`
60+
- **Default:** `graphql-client-name`
61+
62+
The name of the HTTP header from which to read the client name for usage reporting. This is useful
63+
if you want to identify different clients consuming your GraphQL API.
64+
65+
### `client_version_header`
66+
67+
- **Type:** `string`
68+
- **Default:** `graphql-client-version`
69+
70+
The name of the HTTP header from which to read the client version for usage reporting. This is
71+
useful if you want to identify different versions of clients consuming your GraphQL API.
72+
73+
### `buffer_size`
74+
75+
- **Type:** `integer`
76+
- **Default:** `1000`
77+
78+
A maximum number of operations to hold in a buffer before sending to Hive Console. When the buffer
79+
reaches this size, it will be flushed and sent to Hive Console.
80+
81+
### `accept_invalid_certs`
82+
83+
- **Type:** `boolean`
84+
- **Default:** `false`
85+
86+
If set to `true`, the Hive Router will accept invalid SSL certificates when sending usage reports.
87+
This can be useful for self-hosted Hive instances using self-signed certificates.
88+
89+
### `connect_timeout`
90+
91+
- **Type:** `string`
92+
- **Default:** `5s`
93+
94+
A timeout for only the connect phase of a request to Hive Console, in duration format (e.g., `5s`
95+
for 5 seconds).
96+
97+
### `request_timeout`
98+
99+
- **Type:** `string`
100+
- **Default:** `15s`
101+
102+
A timeout for the entire request to Hive Console, in duration format (e.g., `15s` for 15 seconds).
103+
104+
### `flush_interval`
105+
106+
- **Type:** `string`
107+
- **Default:** `5s`
108+
109+
The interval in seconds at which the usage report buffer is flushed and sent to Hive Console. In
110+
duration format (e.g., `5s` for 5 seconds).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export default {
22
probes: 'Probes',
3+
usage_reporting: 'Usage Reporting',
34
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Callout, Cards, Tabs } from '@theguild/components'
2+
3+
# Usage Reporting
4+
5+
Hive Router can send usage reports to Hive Console to provide insights into the operations being
6+
executed against your GraphQL API. This includes details such as operation names, client
7+
information, and field-level usage statistics.
8+
9+
The Hive Router can report usage metrics to the Hive schema registry, giving you
10+
[insights for executed GraphQL operations](/docs/dashboard/insights), and
11+
[field level usage information](/docs/dashboard/explorer), but also enabling
12+
[conditional breaking changes](/docs/management/targets#conditional-breaking-changes).
13+
14+
> For additional information about the usage reporting process in Hive Router, see
15+
> [Usage Reporting page](../observability/usage_reporting).
16+
17+
Before proceeding, make sure you have
18+
[created a registry token with write permissions on the Hive dashboard](/docs/management/targets#registry-access-tokens).
19+
20+
You can either provide the usage reporting configuration via environment variables or the
21+
`router.config.yaml` file.
22+
23+
<Tabs items={["Environment Variables", "Configuration File"]}>
24+
25+
{/* Environment Variables */}
26+
27+
<Tabs.Tab>
28+
29+
- `HIVE_TARGET`: The target ID, this can either be a slug following the format
30+
`$organizationSlug/$projectSlug/$targetSlug` (e.g `the-guild/graphql-hive/staging`) or an UUID
31+
(e.g. `a0f4c605-6541-4350-8cfe-b31f21a4bf80`). To be used when the token is configured with an
32+
organization access token.
33+
34+
- `HIVE_ACCESS_TOKEN`: Your
35+
[Registry Access Token](https://the-guild.dev/graphql/hive/docs/management/targets#registry-access-tokens)
36+
with write permission.
37+
38+
```sh filename="Run Hive Router with Usage Reporting enabled."
39+
HIVE_ACCESS_TOKEN="<hive_usage_access_token>" \
40+
HIVE_TARGET="<hive_usage_target>" \
41+
hive-router
42+
```
43+
44+
</Tabs.Tab>
45+
46+
{/* Configuration File */}
47+
48+
<Tabs.Tab>
49+
50+
Alternatively, you can provide the usage reporting configuration via the `router.config.yaml` file.
51+
52+
```yaml filename="router.config.yaml"
53+
usage_reporting:
54+
# The registry token provided by Hive Registry
55+
token: '<hive_usage_access_token>'
56+
# The registry target which the usage data should be reported to defaulting to process.env.HIVE_USAGE_TARGET
57+
# This can either be a slug following the format `$organizationSlug/$projectSlug/$targetSlug` (e.g `the-guild/graphql-hive/staging`)
58+
# or an UUID (e.g. `a0f4c605-6541-4350-8cfe-b31f21a4bf80`).
59+
target_id: '<hive_usage_target>'
60+
61+
# Endpoint override for self-hosting
62+
# endpoint: 'https://my-hive-instance.com/usage'
63+
```
64+
65+
</Tabs.Tab>
66+
67+
</Tabs>
68+
69+
If you want to control the usage reporting to the Hive Console like `client_name_header`,
70+
`client_version_header` or `sample_rate` etc, please look at the configuration documentation to
71+
learn more about other options.
72+
[See more in the configuration reference](/docs/router/configuration/usage_reporting).

0 commit comments

Comments
 (0)