Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYD-1399: Add environments documentation #591

Merged
merged 22 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/guides/advanced/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* **[Backfill](backfill.md):** Recover lost data and bulk load historical data into Logfire with the `logfire backfill` command, ensuring data continuity.
* **[Creating Write Tokens](creating-write-tokens.md):** Generate and manage multiple write tokens for different services.
* **[Using Read Tokens](query-api.md):** Generate and manage read tokens for programmatic querying of your Logfire data.
* **[Using Environments](using-environments.md):** Group data between environments (e.g. dev, staging, prod) within a project.
48 changes: 48 additions & 0 deletions docs/guides/advanced/using-environments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
If you set up Logfire according to the [getting started guide](../../index.md), you already have instrumented logfire in your applications
via the `logfire.configure()` function. If you find yourself wanting to distinguish between data sent in one environment (e.g. `dev` vs. `production`), it may be overkill to create a new project for each (more on how to decide this below).

Instead you can use the environments feature, which is a special kind of resource attribute applied to the whole payload received by Logfire.
This attribute says which environment the payload comes from.

You can set a Logfire environment via the SDK `logfire.configure` function:
ChristopherGS marked this conversation as resolved.
Show resolved Hide resolved

```py title="main.py"
import logfire

logfire.configure(environment='dev')

from app.main import main

main()
ChristopherGS marked this conversation as resolved.
Show resolved Hide resolved
```

Under the hood, this sets the OTel [`deployment.environment.name`](https://opentelemetry.io/docs/specs/semconv/resource/deployment-environment/).
Note that you can also set this via the `LOGFIRE_ENVIRONMENT` environment variable.
ChristopherGS marked this conversation as resolved.
Show resolved Hide resolved

Once set, you will see your environment in the Logfire UI `all envs` dropdown, which appears
on the [Live View](../web-ui/live.md), [Dashboards](../web-ui/dashboards.md) and [Explore](../web-ui/explore.md) pages:

![Environments](../../images/guide/environments.png)

Note that by default there are system generated environments:

- `all envs`: Searches will include all spans with any environment set
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kludex is this description of all_envs vs. not specified correct, I wasn't sure. Could it be that not specified just returns everything?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know... I was not involved in this decision. 🤷‍♂️

It makes sense for all envs to include not specified, but I don't know how it was implemented.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All envs has no limitations,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not specified returns logs with empty env value

- `not specified`: Searches will include all spans with no environment specified

Any environments you create via the SDK will appear below the system generated envs. When you select an environment,
ChristopherGS marked this conversation as resolved.
Show resolved Hide resolved
all subsequent queries (e.g. on live view, dashboards or explore) will filter by that environment.

## Can I Create an Environment in the UI?
No, you cannot create or delete set environments via the UI, instead use the SDK.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't include unnecessary information. 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disagree, I think it's worth being explicit about this so people don't try and find it. There is very little downside to clarifying it.


## How do I delete an environment?
Once an environment has been configured and received by logfire, technically it’s available for
the length of the data retention period while that environment exists in the data.
You can however add new ones, and change the configuration of which data is assigned to which
environment name.

## Should I Use Environments or Projects?

Environments are more lightweight than projects. Projects give you the ability to assign specific
user groups and permissions levels (see this [organization structure diagram](docs/reference/organization-structure/) for details).
ChristopherGS marked this conversation as resolved.
Show resolved Hide resolved
So if you need to allow different team members to view dev vs. prod traces, then projects would be a better fit.
Binary file added docs/images/guide/environments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ nav:
- Link to Code Source: guides/advanced/link-to-code-source.md
- Testing: guides/advanced/testing.md
- Backfill: guides/advanced/backfill.md
- Using Environments: guides/advanced/using-environments.md
ChristopherGS marked this conversation as resolved.
Show resolved Hide resolved
- Integrations:
- Integrations: integrations/index.md
- OpenTelemetry:
Expand Down
Loading