Set variables for one service
To set environment variables for a single service, list them in the service’senv block:
Set variables for every service
To share environment variables across the project, list them in the top-levelenv block. A service’s own env overrides them:
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:- The environment you started
ldevin (PATH,HOME, …) - The variables Localdev sets (below)
- The top-level
env - The service’s own
env
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, includeservice.nameyourself, for exampleservice.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:
pathandMY_PATHare 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, usecommand: 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 sameenv 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.
What can’t be saved
Localdev can’t rewrite anenv that uses YAML anchors, aliases, merge keys or inline syntax (api: {command: ./api}). Saving a change to one fails with:
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
_KEYor_TOKEN - the name contains
PASSWORD,PASSWD,SECRET,CREDENTIALorPRIVATE_KEY - the value is a URL with a password, like
postgres://app:secret@db/app
-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.
