Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs: improve self hosting analytics documentatoin

TzeYiingba7b93f07bb0
diff --git a/apps/docs/docs/ref/self-hosting-analytics/introduction.mdx b/apps/docs/docs/ref/self-hosting-analytics/introduction.mdx
index 1158463ba48..f676d762abd 100644
--- a/apps/docs/docs/ref/self-hosting-analytics/introduction.mdx
+++ b/apps/docs/docs/ref/self-hosting-analytics/introduction.mdx
@@ -20,92 +20,98 @@ When self-hosting the Analytics server, the full logging experience matching tha
However, it's important to note that certain [differences](#differences) may arise due to the platform's infrastructure.
<Admonition type="info" label="Logflare Technical Docs">
- All logflare technical docs are available at
+ All Logflare technical documentation are available at
[https://docs.logflare.app](https://docs.logflare.app)
</Admonition>
-## Getting Started
+## Backends Supported
-### Pre-requisites
+The Analytics server supports either **Postgres** or **BigQuery** as the backend. The `supabase-cli` experience uses the Postgres backend out-of-the-box. However, the Supabase Platform uses the BigQuery backend for storing all platform logs.
-Currently the Analytics service supports two backends for ingestion:
+When using the BigQuery backend, a BigQuery dataset is created in the provided Google Cloud project, and tables are created for each source. Log events are streamed into each table, and all queries generated by Studio or by the Logs Explorer are executed against the BigQuery API. This backend requires internet access to work, and cannot be run fully locally.
-- Postgres ingestion
-- Big Query ingestion
+When using the Postgres backend, tables are created for each source within the provided schema (for supabase-cli, this would be `_analytics`). Log events received by Logflare are inserted directly into the respective tables. All BigQuery-dialect SQL queries from Studio will be handled by a translation layer within the Analytics server. This translation layer translates the query to PostgreSQL dialect, and then executes it against the Postgres database.
-### Postgres Ingestion Requirements
+The Postgres backend is not yet optimized for high volume of inserts, or for heavy query usage. Furthermore, the translation layer only handles a limited subset of the BigQuery dialect such that the Studio is capable to work as per normal. As such, the [Log Explorer](https://supabase.com/docs/guides/platform/logs#logs-explorer) may have errors for more advanced queries when using the Postgres Backend.
-- Requires you to use supabase/logflare:1.3.26 or above
-- Requires the following environment variables set:
- - Required - POSTGRES_BACKEND_URL: `postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}`
- - Optional - POSTGRES_BACKEND_SCHEMA: `{SCHEMA_NAME}`
+## Getting Started
-### Big Query Ingestion Requirements
+The Postgres backend is recommended for getting familiar and experimenting with self-hosting Supabase. However, it is recommended to use the BigQuery backend for production scale. See [production recommendations](#production-recommendations) for more information
-- Google Cloud Account with billing enabled
-- Big Query enabled
+To get started with self-hosting Supabase, the [example docker-compose](https://github.com/supabase/supabase/tree/master/docker) will give you a jumpstart to setting up logging for the stack.
+Two compose services are required: Logflare, and Vector. Logflare is the HTTP Analytics server, while Vector is the logging pipeline to route all compose services' syslog to the Logflare sever.
-The remainder of the instructions are specified in the [Setup Big Query ingestion](#setup-big-query-ingestion) section.
+Regardless of backend chosen, the following environment variables **must** be set for the `supabase/logflare` docker image:
-#### Setup Big Query ingestion
+- `LOGFLARE_SINGLE_TENANT_MODE=true`: The feature flag for enabling single tenant mode for Logflare. Must be set to `true`
+- `LOGFLARE_SUPABASE_MODE=true`: The feature flag for seeding Supabase-related data. Must be set to `true`
-Logflare currently requires BigQuery usage. You will need to create a Google Cloud project with billing enabled.
+For all other configuration environment variables, please refer to the [Logflare self-hosting documentation](https://docs.logflare.app/self-hosting/#configuration).
-The requirements are as follows after creating the project:
+## Postgres Backend Setup
-- Project ID
-- Project number
-- A service account key
+The [example docker-compose](https://github.com/supabase/supabase/tree/master/docker) uses the Postgres backend out of the box.
-##### Setting up BigQuery Service Account
+```bash
+# clone the supabase/supabase repo, and run the following
+cd docker
+docker compose -f docker-compose.yml up
+```
-To ensure that you have sufficient permissions to insert into your Google Cloud BigQuery, ensure that you have created a service account with either:
+### Configuration and Requirements
-- BigQuery Admin role; or
-- The following permissions:
- - bigquery.datasets.create
- - bigquery.datasets.get
- - bigquery.datasets.getIamPolicy
- - bigquery.datasets.update
- - bigquery.jobs.create
- - bigquery.routines.create
- - bigquery.routines.update
- - bigquery.tables.create
- - bigquery.tables.delete
- - bigquery.tables.get
- - bigquery.tables.getData
- - bigquery.tables.update
- - bigquery.tables.updateData
+- `supabase/logflare:1.4.0` or above
+- Relevant environment variables:
+ - `POSTGRES_BACKEND_URL` : Required. The connection string to the Postgres database.
+ - `POSTGRES_BACKEND_SCHEMA` : Optional. Allows customization of the schema used to scope all backend operations within the database.
-You can create the service account via the web console or `gcloud`, as per the [Google Cloud documentation](https://cloud.google.com/iam/docs/keys-create-delete). In the web console, you can create the key by navigating to IAM > Service Accounts > Actions (dropdown) > Manage Keys
+## BigQuery Backend Setup
-We recommend setting the BigQuery Admin role, as it simplifies permissions setup.
+The BigQuery backend is a more robust and scalable backend option that is battle-tested and production ready. Use this backend if you intend to have heavy logging usage and require advanced querying features such as the Logs Explorer.
-##### Downloading the Service Account key
+### Configuration and Requirements
-After the service account is created, you will need to create a key for the service account. This key will sign the JWTs for API requests that the Analytics server makes with BigQuery.
+The requirements are as follows after creating the project:
-### Docker Compose
+- Google Cloud project with billing enabled
+- Project ID
+- Project number
+- A service account key.
-For analytics to work we're adding two services: Logflare and Vector.
+<Admonition>
+ You must enable billing on your Google Cloud project, as a valid billing account is required for
+ streaming inserts.
+</Admonition>
-Logflare is the analytics server that will ingest your logs into your preferred backend while Vector is the log router that will route all the docker logs using syslog unto Logflare.
+#### Setting up BigQuery Service Account
-#### Using the Postgres Backend
+The service account used must have sufficient permissions to insert into your Google Cloud BigQuery. Ensure that the service account has either:
-You can simply startup using the following command
+- BigQuery Admin role; or
+- The following permissions:
+ - `bigquery.datasets.create`
+ - `bigquery.datasets.get`
+ - `bigquery.datasets.getIamPolicy`
+ - `bigquery.datasets.update`
+ - `bigquery.jobs.create`
+ - `bigquery.routines.create`
+ - `bigquery.routines.update`
+ - `bigquery.tables.create`
+ - `bigquery.tables.delete`
+ - `bigquery.tables.get`
+ - `bigquery.tables.getData`
+ - `bigquery.tables.update`
+ - `bigquery.tables.updateData`
-```bash
-# assuming you clone the supabase/supabase repo.
-cd docker
-docker compose -f docker-compose.yml up
-```
+You can create the service account via the web console or `gcloud`, as per the [Google Cloud documentation](https://cloud.google.com/iam/docs/keys-create-delete). In the web console, you can create the key by navigating to IAM > Service Accounts > Actions (dropdown) > Manage Keys
-> ⚠️ WARNING: Please be aware of the heavy consumption of analytics. For heavy usage you might want to consider the usage of a different database for analytics only by updating the `POSTGRES_BACKEND_URL` in the `analytics` service on the `docker-compose.yml` file.
+We recommend setting the BigQuery Admin role, as it simplifies permissions setup.
+
+#### Download the Service Account Keys
-Also be aware that you won't be able to use [Log Explorer](https://supabase.com/docs/guides/platform/logs#logs-explorer) when using the Postgres Backend as some of the querying features are still not supported by our translation layer.
+After the service account is created, you will need to create a key for the service account. This key will sign the JWTs for API requests that the Analytics server makes with BigQuery. This can be done through the IAM section in Google Cloud console.
-#### Using the Big Query Backend
+#### Docker Image Configuration
Using the example [self-hosting stack based on docker-compose](https://github.com/supabase/supabase/tree/master/docker), you include the logging related services using the following command
@@ -118,7 +124,7 @@ Using the example [self-hosting stack based on docker-compose](https://github.co
3. On `docker-compose.yml`, uncomment the block section below the commentary `# Uncomment to use Big Query backend for analytics`
4. On `docker-compose.yml`, comment the block section below the commentary `# Comment variables to use Big Query backend for analytics`
-Thereafter, you can simply startup using the following command
+Thereafter, you can start the example stack using the following command:
```bash
# assuming you clone the supabase/supabase repo.
@@ -126,55 +132,25 @@ cd docker
docker compose -f docker-compose.yml
```
-<Admonition type="info" label="Self-hosting">
- Read more about [self-hosting Logflare](https://docs.logflare.app/self-hosting) as your analytics
- server.
-</Admonition>
+#### BigQuery Datset Storage Location
-#### Vector Usage
+Currently, all BigQuery datasets stored and managed by Analytics, whether via CLI or self-hosted, will default to the US region.
-In the Docker Compose example, we utilize vector to coordinate the logging pipeline between the services. However, if you peer into the [vector configuration file](https://github.com/supabase/supabase/blob/master/docker/volumes/logs/vector.yml), you will be able to see that Vector sends logs to the Analytics ingestion endpoint.
+## Vector Usage
-If you need to customize the logging pipeline for your own needs, you must ensure that the payloads matches the expected event schema structure. Without the correct structure, it would cause the Studio Logs UI features to break.
+In the Docker Compose example, Vector is used for the logging pipieline, where log events are forwarded to the Analytics API for ingestion.
-### Standalone Docker Container
+Please refer to the [Vector configuration file](https://github.com/supabase/supabase/blob/master/docker/volumes/logs/vector.yml) when customizing your own setup.
-Supplementary technical documentation on self-hosting and using the `supabase/logflare` image for a full Logflare experience is available at the [official Logflare documentation](https://docs.logflare.app/self-hosting/).
+You **must** ensure that the payloads matches the expected event schema structure. Without the correct structure, it would cause the Studio Logs UI features to break.
-## Differences
+## Differences from Platform
API logs rely on Kong instead of the Supabase Cloud API Gateway. Logs from Kong are not enriched with platform-only data.
Within the self-hosted setup, all logs are routed to Logflare via Vector. As Kong routes API requests to PostgREST, self-hosted or local deployments will result in Kong request logs instead.
This would result in differences in the log event metadata between self-hosted API requests and Supabase Platform requests.
-## Postgres
-
-Log event data is stored and queried from a Postgres database.
-
-Make sure to set the `POSTGRES_BACKEND_URL` environment variable.
-
-### Storage
-
-All data will be stored on the Postgres Database configured by setting `POSTGRES_BACKEND_URL`
-
-## BigQuery
-
-All log event data is stored in and queried from BigQuery. To use the Analytics server with Supabase you'll need a Google Cloud Platform account for access to BigQuery.
-
-Make sure to set the `GOOGLE_DATASET_ID_APPEND`, `GOOGLE_PROJECT_ID` and `GOOGLE_PROJECT_NUMBER` environment variables.
-
-Download your Google Cloud API JWT and store it under gcloud.json in your working directory.
-
-<Admonition>
- You must also enable billing on your Google Cloud project, as the streaming inserts feature is
- required.
-</Admonition>
-
-### Storage Location
-
-Currently, all BigQuery datasets stored and managed by Analytics, whether via CLI or self-hosted, will default to the US region.
-
## Production Recommendations
To self-host in a production setting, we recommend performing the following for a better experience.
@@ -194,6 +170,8 @@ The self-hosted example is only used as a minimal example on running the entire
The current Postgres Ingestion backend isn't optimized for production usage. We recommend using Big Query for more heavy use cases.
+**We advise using the BigQuery backend for production settings, for better scaling and querying/debugging experience**.
+
</RefSubLayout.Details>
<RefSubLayout.Examples>