Skip to main content

Set variables for one service

To set environment variables for a single service, list them in the service’s env block:

Set variables for every service

To share environment variables across the project, list them in the top-level env block. A service’s own env overrides them:
Values are passed as the text in the file. See env for how numbers, booleans and empty values are read.

What a service receives

A service’s environment is built from four sources. Each one overrides the ones before it:
  1. The environment you started ldev in (PATH, HOME, …)
  2. The variables Localdev sets (below)
  3. The top-level env
  4. The service’s own env
So a variable set both in your shell and in the Projectfile takes the Projectfile’s value. A variable set in both the top-level env and a service’s env takes the service’s value.

Variables Localdev sets

Localdev sets these for every service, so that OpenTelemetry SDKs send their telemetry to the collector without any configuration:
  • You can override any of them in the Projectfile. They’re never written to it.
  • If you override OTEL_RESOURCE_ATTRIBUTES, include service.name yourself, for example service.name=api,team=core. Without it, the service’s telemetry isn’t labelled with its name.
  • To send over OTLP HTTP instead of gRPC, override both the protocol and the endpoint:

Variables Localdev refuses

Some variables change which code a service runs: they point it at other programs or libraries, or make a runtime load extra code at start-up. Localdev doesn’t let you set them in the Projectfile or in the environment editor.
  • If the Projectfile sets one, Localdev doesn’t start. The error names the variable, for example: services.api.env: invalid environment variable: PATH can't be set in localdev because it changes which code a service runs; set it in the shell that starts ldev instead
  • If you add one in the environment editor, the change is refused.
  • Names are case-sensitive: path and MY_PATH are ordinary variables.

What to do instead

  • Set the variable in the shell that starts Localdev. Every service inherits it:
  • Move the option into the command. For example, instead of NODE_OPTIONS: --require ./tracing.js, use command: node --require ./tracing.js app.js.
  • For a value that only one service needs, make a small wrapper script the service’s command.

What this protects

The list is fixed, so other variables can still change what a program does (GOFLAGS, or an application’s own plugin setting, for example). Anyone who can edit the Projectfile can already run any program through command. The list mainly stops the environment editor, which can’t change commands, from being used to run other code.

Change variables while Localdev runs

The UI has an environment editor: Project → Environment for the shared variables, and Project → Services for each service’s own. It edits the same env blocks as the Projectfile.

Three separate steps

A change goes through three steps, and each one is separate: Editing doesn’t write the file or touch running processes. Saving doesn’t restart anything. Restarting doesn’t save. While something is pending, a bar at the top of the Project page lists the unsaved changes and the services that need a restart.

Saving

  • Only the lines of the variables you changed are rewritten. Comments, key order, blank lines and formatting stay as they were.
  • The variables Localdev sets (OTEL_*) are never written to the file.
  • Discard drops your edits and reads the variables from the Projectfile again.
If something else changed the Projectfile since Localdev read it, saving is refused and nothing is written: “The Projectfile changed on disk, so nothing was written.” Your edits stay in the editor. Either Discard them to load the file as it is now, or make the same changes in the file by hand.

What can’t be saved

Localdev can’t rewrite an env that uses YAML anchors, aliases, merge keys or inline syntax (api: {command: ./api}). Saving a change to one fails with:
This applies only to an env you changed. Changes to other services in the same file are saved normally.

Hidden values

The editor hides a value until you click the eye icon when:
  • the name ends in _KEY or _TOKEN
  • the name contains PASSWORD, PASSWD, SECRET, CREDENTIAL or PRIVATE_KEY
  • the value is a URL with a password, like postgres://app:secret@db/app
This only hides the value on screen. Changes are accepted only from the machine Localdev runs on, even if other machines can open the UI (-server 0.0.0.0:2345).

Variables that configure Localdev

LDEV_STORE_LOGS, LDEV_STORE_METRIC_POINTS and LDEV_STORE_TRACE_SPANS set how much telemetry Localdev keeps in memory. See the CLI reference.