Environments and releases
environment keeps staging and production traces apart in one project, and release records which build of your application produced them. Both usually go on the client.
User and tags from lesson 9 describe a request. Two more attributes describe the program that handled it: where it runs, and which version of it.
from langfuse import Langfuse
import local_langfuse
from desk import answer
url = local_langfuse.start()
langfuse = Langfuse(public_key="pk-lf-local", secret_key="sk-lf-local", base_url=url,
environment="staging", release="2026.03.1")answer("Where is my order A17?")
langfuse.flush()
for span in local_langfuse.SPANS:
attributes = span["attributes"]
print(span["name"], attributes["langfuse.environment"], attributes["langfuse.release"])python env.pyEvery observation carries both. environment can also come from LANGFUSE_TRACING_ENVIRONMENT, and the constructor wins if both are set; without either, the environment is default. release can come from LANGFUSE_RELEASE, usually a version number or a git commit set by your deployment. An environment is created the first time data arrives with it, and cannot currently be renamed or deleted in Langfuse's interface. When the environment belongs to a request rather than the whole program, as in one proxy serving several stages, propagate_attributes(environment=...) sets it for that request only.
A name Langfuse will not accept
from langfuse import Langfuse
import local_langfuse
url = local_langfuse.start()
langfuse = Langfuse(public_key="pk-lf-local", secret_key="sk-lf-local", base_url=url, environment="Staging")
with langfuse.start_as_current_observation(name="support-ticket"):
pass
langfuse.flush()
print(local_langfuse.SPANS[0]["attributes"].get("langfuse.environment"))python env_name.pyThe SDK sent Staging as it was, without checking it. The documentation allows only lowercase letters, digits, hyphens and underscores, at most 40 characters, not starting with langfuse. The SDK will not catch a capital letter for you, so keep to lowercase names from the start.
Versions of one step
A release versions the whole application. A version versions one step: pass version="2" to an observation, or to propagate_attributes as lesson 9's tryit did, when you change one prompt or one tool and want to compare its metrics before and after.
- Set
LANGFUSE_TRACING_ENVIRONMENT=productionin the shell and removeenvironmentfrom the constructor. - Remove both and print the environment attribute.
- Pass
version="2"to the@observeonask_modelindesk.py.
Little by little, you're building something great.