Skip to content

Commit 7beff52

Browse files
authored
docs: OpenTelemetry (#7103)
1 parent 1ee08b3 commit 7beff52

File tree

2 files changed

+161
-20
lines changed

2 files changed

+161
-20
lines changed
Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
---
2-
title: "Environment Variables"
3-
description: "A reference page listing all environment variables for the API and Frontend."
2+
title: 'Environment Variables'
3+
description: 'A reference page listing all environment variables for the API and Frontend.'
44
sidebar_position: 20
55
---
66

7-
This page provides a comprehensive reference for all the environment variables you can use to configure your self-hosted Flagsmith instance. You'll find variables for both the API and the frontend, along with a brief description of what each one does. Use this as a handy guide when setting up or tweaking your deployment, whether you're running locally, in the cloud, or on Kubernetes. If you're not sure what a particular variable does, or whether you need to set it, check the relevant section below for more details.
7+
This page provides a comprehensive reference for all the environment variables you can use to configure your self-hosted
8+
Flagsmith instance. You'll find variables for both the API and the frontend, along with a brief description of what each
9+
one does. Use this as a handy guide when setting up or tweaking your deployment, whether you're running locally, in the
10+
cloud, or on Kubernetes. If you're not sure what a particular variable does, or whether you need to set it, check the
11+
relevant section below for more details.
812

913
## API Environment Variables
1014

@@ -13,41 +17,66 @@ This page provides a comprehensive reference for all the environment variables y
1317
- `REDIS_URL`: The URL of your Redis instance.
1418
- `ENV`: The environment the application is running in, e.g. "prod".
1519
- `SENTRY_DSN`: If you want to send errors to Sentry, specify the DSN here.
16-
- `SENTRY_TRACE_SAMPLE_RATE`: The percentage of transactions to trace in Sentry. See [Sentry's documentation](https://docs.sentry.io/platforms/python/performance/instrumentation/django/#configure) for more info.
20+
- `SENTRY_TRACE_SAMPLE_RATE`: The percentage of transactions to trace in Sentry. See
21+
[Sentry's documentation](https://docs.sentry.io/platforms/python/performance/instrumentation/django/#configure) for
22+
more info.
1723
- `LOG_LEVEL`: The log level to output at. One of `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`.
1824
- `LOG_FORMAT`: The format to use for logging. One of `generic` or `json`.
1925
- `DJANGO_SECRET_KEY`: A long, random and unique string used for cryptographic signing.
20-
- `ACCESS_LOG_LOCATION`: The location to store web logs generated by Gunicorn if running as a Docker container. If not set, no logs will be stored. If set to `-`, the logs will be sent to `stdout`.
26+
- `ACCESS_LOG_LOCATION`: The location to store web logs generated by Gunicorn if running as a Docker container. If not
27+
set, no logs will be stored. If set to `-`, the logs will be sent to `stdout`.
2128
- `DJANGO_SETTINGS_MODULE`: Python path to settings file for the given environment, e.g. "app.settings.develop"
22-
- `ALLOW_ADMIN_INITIATION_VIA_CLI`: Enables the `bootstrap` management command which creates default admin user, organisation, and project.
29+
- `ALLOW_ADMIN_INITIATION_VIA_CLI`: Enables the `bootstrap` management command which creates default admin user,
30+
organisation, and project.
2331
- `ADMIN_EMAIL`: Email to use for the default superuser creation.
2432
- `ORGANISATION_NAME`: Organisation name to use for the default organisation.
2533
- `PROJECT_NAME`: Project name to use for the default project.
2634
- `ENABLE_GZIP_COMPRESSION`: If Django should gzip compress HTTP responses. Defaults to `False`.
2735
- `GOOGLE_ANALYTICS_KEY`: If Google Analytics is required, add your tracking code.
28-
- `GOOGLE_SERVICE_ACCOUNT`: Service account JSON for accessing the Google API, used for getting usage of an organisation - needs access to analytics.readonly scope.
36+
- `GOOGLE_SERVICE_ACCOUNT`: Service account JSON for accessing the Google API, used for getting usage of an
37+
organisation - needs access to analytics.readonly scope.
2938
- `INFLUXDB_TOKEN`: If you want to send API events to InfluxDB, specify this write token.
3039
- `INFLUXDB_URL`: The URL for your InfluxDB database.
3140
- `INFLUXDB_ORG`: The organisation string for your InfluxDB API call.
3241
- `GA_TABLE_ID`: GA table ID (view) to query when looking for organisation usage.
33-
- `USER_CREATE_PERMISSIONS`: Set the permissions for creating new users, using a comma-separated list of djoser or rest_framework permissions. Use this to turn off public user creation for self-hosting. e.g. `'djoser.permissions.CurrentUserOrAdmin'`. Defaults to `'rest_framework.permissions.AllowAny'`.
34-
- `ALLOW_REGISTRATION_WITHOUT_INVITE`: Determines whether users can register without an invite. Defaults to True. Set to False or 0 to disable. Note that if disabled, new users must be invited via email.
42+
- `USER_CREATE_PERMISSIONS`: Set the permissions for creating new users, using a comma-separated list of djoser or
43+
rest_framework permissions. Use this to turn off public user creation for self-hosting. e.g.
44+
`'djoser.permissions.CurrentUserOrAdmin'`. Defaults to `'rest_framework.permissions.AllowAny'`.
45+
- `ALLOW_REGISTRATION_WITHOUT_INVITE`: Determines whether users can register without an invite. Defaults to True. Set to
46+
False or 0 to disable. Note that if disabled, new users must be invited via email.
3547
- `PREVENT_SIGNUP`: Determines whether to prevent new signups.
3648
- `ENABLE_EMAIL_ACTIVATION`: New user registration will go via email activation flow, default False.
49+
- `OTEL_EXPORTER_OTLP_ENDPOINT`: Base OTLP/HTTP endpoint (e.g. `http://collector:4318`). If unset, OTel is disabled. See
50+
[OpenTelemetry](/deployment-self-hosting/scaling-and-performance/opentelemetry).
51+
- `OTEL_SERVICE_NAME`: The `service.name` resource attribute attached to all OTel telemetry. Defaults to
52+
`flagsmith-api`.
53+
- `OTEL_TRACING_EXCLUDED_URL_PATHS`: Comma-separated URL paths to exclude from OTel tracing (e.g.
54+
`health/liveness,health/readiness`).
3755

3856
## Frontend Environment Variables
3957

4058
- `FLAGSMITH_API_URL`: The API to hit for requests. E.g. `https://edge.api.flagsmith.com/api/v1/`
41-
- `FLAGSMITH_ON_FLAGSMITH_API_KEY`: The Flagsmith environment key we use to manage features - [Flagsmith runs on Flagsmith](/deployment-self-hosting/core-configuration/running-flagsmith-on-flagsmith).
42-
- `FLAGSMITH_ON_FLAGSMITH_API_URL`: The API URL which the Flagsmith client should communicate with. Flagsmith runs on Flagsmith. E.g. `https://edge.api.flagsmith.com/api/v1/`. If you are self-hosting and using your own Flagsmith instance to manage its own features, you would generally point this to the same domain name as your own Flagsmith instance.
43-
- `DISABLE_ANALYTICS_FEATURES`: Disables any in-app analytics-related features: API Usage charts, flag analytics. E.g. `DISABLE_ANALYTICS_FEATURES=1`.
44-
- `ENABLE_FLAG_EVALUATION_ANALYTICS`: Determines if the Flagsmith SDK should send usage analytics. If you want to enable Flag Analytics, set this. E.g. `ENABLE_FLAG_EVALUATION_ANALYTICS=1`.
45-
- `PROXY_API_URL`: Proxies the API via this application. Set this to the hostname of the API being proxied. Proxies `/api/v1/` through to `PROXY_API_URL`. If you are using this, any setting to `FLAGSMITH_API_URL` will be ignored and the browser will use the frontend node server to send API requests. Do not prepend `api/v1/` - it will be added automatically.
59+
- `FLAGSMITH_ON_FLAGSMITH_API_KEY`: The Flagsmith environment key we use to manage features -
60+
[Flagsmith runs on Flagsmith](/deployment-self-hosting/core-configuration/running-flagsmith-on-flagsmith).
61+
- `FLAGSMITH_ON_FLAGSMITH_API_URL`: The API URL which the Flagsmith client should communicate with. Flagsmith runs on
62+
Flagsmith. E.g. `https://edge.api.flagsmith.com/api/v1/`. If you are self-hosting and using your own Flagsmith
63+
instance to manage its own features, you would generally point this to the same domain name as your own Flagsmith
64+
instance.
65+
- `DISABLE_ANALYTICS_FEATURES`: Disables any in-app analytics-related features: API Usage charts, flag analytics. E.g.
66+
`DISABLE_ANALYTICS_FEATURES=1`.
67+
- `ENABLE_FLAG_EVALUATION_ANALYTICS`: Determines if the Flagsmith SDK should send usage analytics. If you want to enable
68+
Flag Analytics, set this. E.g. `ENABLE_FLAG_EVALUATION_ANALYTICS=1`.
69+
- `PROXY_API_URL`: Proxies the API via this application. Set this to the hostname of the API being proxied. Proxies
70+
`/api/v1/` through to `PROXY_API_URL`. If you are using this, any setting to `FLAGSMITH_API_URL` will be ignored and
71+
the browser will use the frontend node server to send API requests. Do not prepend `api/v1/` - it will be added
72+
automatically.
4673
- `GOOGLE_ANALYTICS_API_KEY`: Google Analytics key to track API usage.
4774
- `CRISP_WEBSITE_ID`: Crisp Chat widget Website key.
4875
- `FIRST_PROMOTER_ID`: First Promoter ID for checkout affiliates.
49-
- `ALLOW_SIGNUPS`: **DEPRECATED** in favour of `PREVENT_SIGNUP` in the API. Determines whether to prevent manual signups without invites. Set it to any value to allow signups.
50-
- `PREVENT_FORGOT_PASSWORD`: Determines whether to prevent forgot password functionality, useful for LDAP/SAML. Set it to any value to prevent forgot password functionality.
76+
- `ALLOW_SIGNUPS`: **DEPRECATED** in favour of `PREVENT_SIGNUP` in the API. Determines whether to prevent manual signups
77+
without invites. Set it to any value to allow signups.
78+
- `PREVENT_FORGOT_PASSWORD`: Determines whether to prevent forgot password functionality, useful for LDAP/SAML. Set it
79+
to any value to prevent forgot password functionality.
5180
- `PREVENT_EMAIL_PASSWORD`: Disables email address signup, login and change email functionality.
5281
- `ENABLE_MAINTENANCE_MODE`: Puts the site into maintenance mode. Set it to any value to enable maintenance.
5382
- `AMPLITUDE_API_KEY`: The Amplitude key to use for behaviour tracking.
@@ -56,15 +85,23 @@ This page provides a comprehensive reference for all the environment variables y
5685
- `SENTRY_API_KEY`: Sentry key for error reporting.
5786
- `ALBACROSS_CLIENT_ID`: Albacross client ID key for behaviour tracking.
5887
- `BASE_URL`: Used for specifying a base URL path that's ignored during routing if serving from a subdirectory.
59-
- `USE_SECURE_COOKIES`: Enable/disable the use of secure cookies. If deploying the frontend in a private network without a domain/SSL cert, disable secure cookies to ensure that session token is persisted. Default: true.
60-
- `COOKIE_SAME_SITE`: Define the value of the SameSite attribute for the session token cookie set by the frontend. Further reading on this value is available [here](https://web.dev/articles/samesite-cookies-explained). Default: 'none'.
88+
- `USE_SECURE_COOKIES`: Enable/disable the use of secure cookies. If deploying the frontend in a private network without
89+
a domain/SSL cert, disable secure cookies to ensure that session token is persisted. Default: true.
90+
- `COOKIE_SAME_SITE`: Define the value of the SameSite attribute for the session token cookie set by the frontend.
91+
Further reading on this value is available [here](https://web.dev/articles/samesite-cookies-explained). Default:
92+
'none'.
6193

6294
## OAuth configuration
6395

6496
### Google OAuth {#oauth-google}
6597

66-
To configure Google OAuth, ensure you have set the relevant OAuth client credentials in your deployment platform, and created the **Flagsmith on Flagsmith** flag as described in the [OAuth guide](/administration-and-security/access-control/oauth). This flag controls whether Google SSO is available in your instance.
98+
To configure Google OAuth, ensure you have set the relevant OAuth client credentials in your deployment platform, and
99+
created the **Flagsmith on Flagsmith** flag as described in the
100+
[OAuth guide](/administration-and-security/access-control/oauth). This flag controls whether Google SSO is available in
101+
your instance.
67102

68103
### GitHub OAuth {#oauth-github}
69104

70-
To configure GitHub OAuth, ensure you have set `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` in your environment, and created the **Flagsmith on Flagsmith** flag as described in the [OAuth guide](/administration-and-security/access-control/oauth). This enables the GitHub SSO option in your instance.
105+
To configure GitHub OAuth, ensure you have set `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` in your environment, and
106+
created the **Flagsmith on Flagsmith** flag as described in the
107+
[OAuth guide](/administration-and-security/access-control/oauth). This enables the GitHub SSO option in your instance.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: OpenTelemetry
3+
description: Exporting traces and structured logs from Flagsmith using OpenTelemetry.
4+
---
5+
6+
Flagsmith supports exporting distributed traces and structured logs over
7+
[OTLP](https://opentelemetry.io/docs/specs/otel/protocol/), the OpenTelemetry Protocol. This lets you send observability
8+
data to any OTLP-compatible backend (e.g. SigNoz, Grafana Tempo, Jaeger, Datadog) without vendor lock-in.
9+
10+
OTel instrumentation is opt-in and has no runtime overhead when disabled.
11+
12+
## Configuration
13+
14+
Set `OTEL_EXPORTER_OTLP_ENDPOINT` to the base OTLP/HTTP URL of your collector (e.g. `http://collector:4318`) to enable
15+
OTel export. When unset, no OTel code is loaded and there is no runtime overhead.
16+
17+
Standard `OTEL_*` environment variables are also respected by the underlying OTel SDK. For example:
18+
19+
- `OTEL_SERVICE_NAME` — overrides the `service.name` resource attribute (defaults to `flagsmith-api` or
20+
`flagsmith-task-processor`).
21+
- `OTEL_RESOURCE_ATTRIBUTES` — adds custom resource attributes.
22+
- `OTEL_EXPORTER_OTLP_HEADERS` — sets authentication headers for the OTLP exporter.
23+
24+
### Example: Docker Compose
25+
26+
```yaml
27+
api:
28+
environment:
29+
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
30+
```
31+
32+
## Traces
33+
34+
When enabled, Flagsmith produces distributed traces for every HTTP request.
35+
36+
### What gets instrumented
37+
38+
| Layer | Instrumentation | Span example |
39+
| ---------------- | ----------------------------- | ------------------------------------------ |
40+
| HTTP requests | Django auto-instrumentation | `GET /api/v1/organisations/{pk}/` |
41+
| Database queries | psycopg2 auto-instrumentation | `SELECT` (with full SQL in `db.statement`) |
42+
| Redis commands | Redis auto-instrumentation | `GET` / `SET` / `EVAL` |
43+
44+
Each HTTP request creates a root server span with child client spans for every database query and Redis command
45+
executed during the request.
46+
47+
### Span naming
48+
49+
HTTP spans are named `{METHOD} {route_template}`, where the route template matches the path format used in the OpenAPI
50+
spec:
51+
52+
- `POST /api/v1/environments/{environment_api_key}/featurestates/`
53+
- `GET /api/v1/projects/{project_pk}/features/`
54+
55+
The `http.route` attribute is set to the same normalised template.
56+
57+
### Trace context propagation
58+
59+
Flagsmith propagates [W3C TraceContext](https://www.w3.org/TR/trace-context/) and
60+
[W3C Baggage](https://www.w3.org/TR/baggage/) headers. If an upstream service sends a `traceparent` header, Flagsmith's
61+
spans join the existing trace. Baggage entries are forwarded into structlog attributes (see below).
62+
63+
### SQL commenter
64+
65+
The psycopg2 instrumentor has [SQL commenter](https://google.github.io/sqlcommenter/) enabled. This appends trace
66+
context as a SQL comment to every query sent to PostgreSQL:
67+
68+
```sql
69+
SELECT "organisations_organisation"."id" FROM "organisations_organisation"
70+
/*traceparent='00-abc123...-def456...-01'*/
71+
```
72+
73+
This allows correlating slow queries in PostgreSQL logs or `pg_stat_statements` back to the originating trace, without
74+
any changes to PostgreSQL configuration.
75+
76+
### Excluding paths
77+
78+
Health check endpoints and other high-frequency, low-value paths can be excluded from tracing:
79+
80+
```
81+
OTEL_TRACING_EXCLUDED_URL_PATHS=health/liveness,health/readiness
82+
```
83+
84+
Excluded paths produce no spans at all.
85+
86+
## Structured logs
87+
88+
Flagsmith uses [structlog](https://www.structlog.org/) for application logging. When OTel is enabled, structlog events
89+
are exported as OTLP log records. The `flagsmith.event` attribute duplicates the event name for backends that don't surface OTel's `EventName` field.
90+
91+
### Span events
92+
93+
When a structlog event is emitted inside an active span (e.g. during an HTTP request), it is also attached as a
94+
[span event](https://opentelemetry.io/docs/concepts/signals/traces/#span-events) with the same name and attributes. This
95+
makes application log events visible in trace detail views without requiring separate log correlation.
96+
97+
### Console output
98+
99+
When OTel is enabled, structlog events also include `trace_id` and `span_id` fields in their console/JSON output when an
100+
active span exists:
101+
102+
```
103+
2025-03-31T15:34:32Z [info] list_organisations [organisations] trace_id=aabb... span_id=ccdd... user_id=1
104+
```

0 commit comments

Comments
 (0)