Skip to content

Commit cbd9b07

Browse files
authored
feat: support observability and additional bindings (#549)
1 parent a8422f1 commit cbd9b07

File tree

8 files changed

+395
-9
lines changed

8 files changed

+395
-9
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Worker Logs & Additional Bindings
3+
description: "Support for Worker Logs and adding additional bindings for Worker projects."
4+
date: 2025-04-18
5+
image: '/images/changelog/nuxthub-workers-observability.png'
6+
category: Core
7+
authors:
8+
- name: Rihan Arfan
9+
avatar:
10+
src: https://avatars.githubusercontent.com/u/20425781?v=4
11+
to: https://bsky.app/profile/rihan.dev
12+
username: rihan.dev
13+
---
14+
15+
::tip
16+
This feature is available from [`@nuxthub/core >= v0.10.0`](https://github.com/nuxt-hub/core/releases/tag/v0.10.0)
17+
::
18+
19+
Worker projects on NuxtHub can now enable Worker Logs, and associate additional bindings to deployments all from within the NuxtHub config. This opens the possibility of adding additional [databases](https://developers.cloudflare.com/d1/worker-api/), [R2 buckets](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/), [service bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/), [rate limiting](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/), [queues](https://developers.cloudflare.com/queues/configuration/javascript-apis/) and [more](https://developers.cloudflare.com/workers/runtime-apis/bindings/) to projects.
20+
21+
## Worker Logs
22+
23+
Workers Logs lets you automatically collect, store, filter, and analyze logging data emitted from your Nuxt app. Currently, you can query it in the dashboard for each of your Workers projects within the Cloudflare Dashboard.
24+
25+
Logs include [invocation logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/#invocation-logs), [custom logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/#custom-logs), errors, and uncaught exceptions.
26+
27+
::callout{to="/docs/getting-started/server-logs#cloudflare-dashboard" icon="i-lucide-book"}
28+
Learn more about enabling Worker Logs.
29+
::
30+
31+
![Observability Overview](/images/docs/observability-overview.png)
32+
33+
Enable Worker Logs within `hub.bindings.observability.logs` in your `nuxt.config.ts`.
34+
35+
```ts [nuxt.config.ts]
36+
export default defineNuxtConfig({
37+
hub: {
38+
bindings: {
39+
observability: {
40+
// enable with default settings
41+
logs: true,
42+
43+
// customise settings
44+
logs: {
45+
head_sampling_rate: 0.5,
46+
invocation_logs: false
47+
}
48+
}
49+
}
50+
},
51+
```
52+
53+
## Additional bindings
54+
55+
Additional bindings can be configured within `hub.bindings` in your `nuxt.config.ts`. All options are suggested via IntelliSense, however, you can refer to [Cloudflare's API documentation](https://developers.cloudflare.com/api/resources/workers/subresources/scripts/subresources/versions/methods/create/#(params)%200%20%3E%20(param)%20metadata%20%3E%20(schema)%20%3E%20(property)%20bindings) too.
56+
57+
Resources for additional bindings are not provisioned automatically like they are with NuxtHub features such as `hub.database`. You will need to create the resources manually from the Cloudflare dashboard.
58+
59+
::callout{to="/docs/features/additional-bindings" icon="i-lucide-book"}
60+
Learn more about assigning additional bindings.
61+
::
62+
63+
```ts [nuxt.config.ts]
64+
export default defineNuxtConfig({
65+
hub: {
66+
bindings: {
67+
// <binding type>: {
68+
// <BINDING NAME>: {
69+
// // binding options
70+
// }
71+
// }
72+
73+
// additional cloudflare bindings
74+
analytics_engine: {
75+
ANALYTICS_TESTING: {
76+
dataset: 'testing'
77+
}
78+
},
79+
mtls_certificate: {
80+
CERT: {
81+
certificate_id: '<CERTIFICATE_ID>'
82+
}
83+
}
84+
}
85+
},
86+
```

docs/content/docs/1.getting-started/5.server-logs.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ description: Access real-time logs of your deployed Nuxt application.
55

66
## NuxtHub Admin
77

8-
When you have a successful deployment, you can access to the logs of the deployment in the [NuxtHub Admin](https://admin.hub.nuxt.com/).
8+
When you have a successful deployment, you can access to the logs of the deployment in the [NuxtHub Admin](https://admin.hub.nuxt.com/).
99

1010
Logs are available under the `Server > Logs` section of your project page. You can also access to the logs of each successful deployment in the `Deployments` section.
1111

1212
:img{src="/images/landing/nuxthub-admin-server-logs.png" alt="NuxtHub Admin Server Logs" width="915" height="515" data-zoom-src="/images/landing/nuxthub-admin-server-logs.png" class="rounded"}
1313

14-
## NuxtHub CLI
14+
## NuxtHub CLI
1515

1616
Using the [NuxtHub CLI](https://github.com/nuxt-hub/cli), you can access to the logs of both `production` and `preview` deployments.
1717

@@ -38,3 +38,53 @@ In preview environment, NuxtHub will stream the logs of the latest successful de
3838
```bash [Terminal]
3939
npx nuxthub logs --preview
4040
```
41+
42+
## Cloudflare Dashboard
43+
44+
Worker project types can enable Worker Logs and view the Workers Observability tab dashboard in Cloudflare. Learn more on the [Cloudflare documentation](https://developers.cloudflare.com/workers/observability/).
45+
46+
![Observability Overview](/images/docs/observability-overview.png)
47+
48+
::callout{to="https://dash.cloudflare.com/?to=/:account/workers/services/view/:worker/production/metrics/"}
49+
Go to the Workers Observability tab in the Cloudflare Dashboard
50+
::
51+
52+
### Enable Worker Logs
53+
54+
Enable Worker Logs within `hub.bindings.observability.logs` in your `nuxt.config.ts`.
55+
56+
::field-group
57+
::field{name="observability" type="string"}
58+
Observability settings
59+
>
60+
> ::field{name="logs" type="boolean | object"}
61+
> Enable Worker Logs with default configuration.<br><br>
62+
>
63+
> Defaults to `head_sampling_rate: 1` and `invocation_logs: true`
64+
> ::
65+
>
66+
> ::field{name="logs" type="boolean | object"}
67+
> Enable Worker Logs with custom configuration.
68+
>
69+
> ::collapsible
70+
> ::field{name="head_sampling_rate" type="number"}
71+
> Head-based sampling allows you to log a percentage of incoming requests to your Nuxt app. Especially for high-traffic
72+
> applications, this helps reduce log volume and manage costs, while still providing meaningful insights into your application's
73+
> performance. When you configure a head-based sampling rate, you can control the percentage of requests that get logged.
74+
> All logs within the context of the request are collected.<br><br>
75+
>
76+
> To enable head-based sampling, set `head_sampling_rate` within the observability configuration.
77+
> The valid range is from 0 to 1, where 0 indicates zero out of one hundred requests are logged, and 1 indicates
78+
> every request is logged. If `head_sampling_rate` is unspecified, it is configured to a default value of 1 (100%).
79+
> In the example below, `head_sampling_rate` is set to 0.01, which > means one out of every one hundred requests is logged.
80+
> ::
81+
>
82+
> ::field{name="invocation_logs" type="boolean?"}
83+
> Each Workers invocation returns a single invocation log that contains details such as the Request, Response, and related metadata. These invocation logs can be identified by the field $cloudflare.$metadata.type = "cf-worker-event". Each invocation log is enriched with information available to Cloudflare in the context of the invocation.<br><br>
84+
>
85+
> In the Workers Logs UI, logs are presented with a localized timestamp and a message. The message is dependent on the invocation handler. For example, Fetch requests will have a message describing the request method and the request URL, while cron events will be listed as cron. Below is a list of invocation handlers along with their invocation message.
86+
> ::
87+
> ::
88+
> ::
89+
::
90+
::
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Additional features
3+
navigation.title: Additional
4+
description: Add additional Cloudflare resource bindings to deployments
5+
---
6+
7+
Cloudflare offer additional resources that aren't directly supported in NuxtHub yet. You can add bindings to associate these resources to your NuxtHub project. Custom bindings can be configured within `hub.bindings` in your `nuxt.config.ts`.
8+
9+
Additional bindings are not provisioned automatically like they are with NuxtHub features such as [`hub.database`](/docs/features/database). You will need to create the resources manually from the Cloudflare dashboard or [wrangler](https://developers.cloudflare.com/workers/wrangler/commands/).
10+
11+
You can add additional bindings to:
12+
- Add additional [D1 databases](https://developers.cloudflare.com/d1/worker-api/), [R2 buckets](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/) (blob), [KV namespaces](https://developers.cloudflare.com/kv/api/) & [analytics datasets](https://developers.cloudflare.com/analytics/analytics-engine/get-started/#2-write-data-points-from-your-worker)
13+
- or use [service bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/), [rate limiting](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/), [queues](https://developers.cloudflare.com/queues/configuration/javascript-apis/), and more
14+
15+
::callout{to="https://developers.cloudflare.com/workers/runtime-apis/bindings/" icon="i-lucide-book"}
16+
View all available binding types on the Cloudflare documentation.
17+
::
18+
19+
## Configuration
20+
21+
Properties on `hub.bindings`
22+
23+
::field-group
24+
::field{name="compatibilityDate" type="string"}
25+
Set a custom compatibility date.
26+
<br>Learn more on [Cloudflare's documentation](https://developers.cloudflare.com/workers/configuration/compatibility-dates/).
27+
::
28+
29+
::field{name="compatibilityFlags" type="string" default="node_compat"}
30+
Set additional compatibility flags, separated with a `space`.
31+
<br>Learn more on [Cloudflare's documentation](https://developers.cloudflare.com/workers/configuration/compatibility-flags/).<br><br>
32+
33+
The [`nodejs_compat`](https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) flag is always enabled.
34+
::
35+
36+
::field{name="observability"}
37+
Observability configurations. View all options on the [observability docs](/docs/getting-started/server-logs#cloudflare-dashboard).
38+
::
39+
40+
::field{name="hyperdrive" type="object"}
41+
Hyperdrive configuration. Learn more about Hyperdrive on the [PostgreSQL docs](/docs/recipes/postgres#hyperdrive).
42+
43+
> ::field{name="<BINDING NAME>" type="string"}
44+
> Binding name and Hyperdrive ID.
45+
> ::
46+
::
47+
48+
::field{name="<additional binding type>" type="object"}
49+
Refer to [Cloudflare's API documentation](https://developers.cloudflare.com/api/resources/workers/subresources/scripts/subresources/versions/methods/create/#(params)%200%20%3E%20(param)%20metadata%20%3E%20(schema)%20%3E%20(property)%20bindings) to see a list of binding type names under `Body parameters` → `metadata` → `bindings`.
50+
51+
52+
> ::field{name="<BINDING NAME>" type="object"}
53+
> Binding options (excluding properties `name` and `type`)
54+
> ::
55+
::
56+
::
57+
58+
::note
59+
Additional bindings are only available within Worker project types.
60+
::
61+
62+
## Example
63+
64+
```ts [nuxt.config.ts]
65+
export default defineNuxtConfig({
66+
hub: {
67+
bindings: {
68+
// <binding type>: {
69+
// <BINDING NAME>: {
70+
// // binding options
71+
// }
72+
// }
73+
74+
// additional cloudflare bindings
75+
analytics_engine: {
76+
ANALYTICS_TESTING: {
77+
dataset: 'testing'
78+
}
79+
},
80+
mtls_certificate: {
81+
CERT: {
82+
certificate_id: '<CERTIFICATE_ID>'
83+
}
84+
}
85+
}
86+
},
87+
```
88+
89+
90+
## Disallowed bindings
91+
Some bindings types cannot be added for certain features already handled by NuxtHub that do not have additional options, or already support multiple bindings. Refer to the table below.
92+
93+
- `ai` → [`hub.ai`](/docs/features/ai)
94+
- `assets` → [`hub.workers`](/changelog/workers)
95+
- `browser_rendering` → [`hub.browser`](/docs/features/browser)
96+
- `vectorize` → [`hub.vectorize`](/docs/features/vectorize)

docs/content/docs/3.recipes/5.postgres.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ You may notice that we don't import `usePostgres()`. This is because Nuxt auto-i
8989
[Hyperdrive](https://developers.cloudflare.com/hyperdrive/) is a Cloudflare service that accelerates queries you make to existing databases, making it faster to access your data from across the globe. By maintaining a connection pool to your database within Cloudflare’s network, Hyperdrive reduces seven round-trips to your database before you can even send a query: the TCP handshake (1x), TLS negotiation (3x), and database authentication (3x).
9090

9191
::important{to="https://developers.cloudflare.com/hyperdrive/platform/pricing/" target="_blank"}
92-
Hyperdrive is only available on the Workers Paid plan ($5/month), **learn more**.
92+
Hyperdrive is limited to 100,000 queries/day on the Workers Free plan. **Learn more**.
9393
::
9494

9595
To use Hyperdrive in your Nuxt application:

docs/content/index.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ hero:
1010
light: '/images/landing/hero-light.svg'
1111
dark: '/images/landing/hero-dark.svg'
1212
headline:
13-
label: "Deploy to Cloudflare Workers"
14-
to: /changelog/workers
13+
label: "Worker Logs & Additional Bindings"
14+
to: /changelog/observability-additional-bindings
1515
icon: i-lucide-arrow-right
1616
features:
1717
- title: Cloud Hosting
Loading

playground/nuxt.config.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default defineNuxtConfig({
2121
},
2222
future: { compatibilityVersion: 4 },
2323

24-
compatibilityDate: '2025-01-22',
24+
compatibilityDate: '2025-04-22',
2525

2626
nitro: {
2727
// preset: 'cloudflare-durable',
@@ -47,12 +47,24 @@ export default defineNuxtConfig({
4747
}
4848
},
4949
bindings: {
50-
compatibilityDate: '2024-11-18'
50+
compatibilityDate: '2025-04-02',
51+
observability: {
52+
logs: true
53+
}
5154
// compatibilityFlags: ['nodejs_compat']
5255
// Used for /api/hyperdrive
5356
// hyperdrive: {
5457
// POSTGRES: '8bb2913857b84c939cd908740fa5a5d5'
5558
// }
59+
// Custom bindings example
60+
// version_metadata: {
61+
// VERSION: {}
62+
// },
63+
// analytics_engine: {
64+
// ANALYTICS2: {
65+
// dataset: 'testing'
66+
// }
67+
// }
5668
}
5769
// projectUrl: ({ branch }) => branch === 'main' ? 'https://playground.nuxt.dev' : `https://${encodeHost(branch).replace(/\//g, '-')}.playground-to39.pages.dev`
5870
},

0 commit comments

Comments
 (0)