LangfuseLangfuse Python SDK 4.15.4 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson

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.

Exampleenv.py
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")
Exampleenv.py, continued
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"])
Example
python env.py

Every 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

Exampleenv_name.py
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"))
Example
python env_name.py

The 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.

Try it yourself
  • Set LANGFUSE_TRACING_ENVIRONMENT=production in the shell and remove environment from the constructor.
  • Remove both and print the environment attribute.
  • Pass version="2" to the @observe on ask_model in desk.py.

Little by little, you're building something great.