Skip to content

Commit e33c032

Browse files
committed
add logfire token support
1 parent 4ad2ecc commit e33c032

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LOGFIRE_TOKEN=your-logfire-write-token

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ A strava clone service for storing running, hiking and ski routes
99
Run the service using docker-compose:
1010

1111
```shell
12+
cp .env.example .env
1213
docker compose up --build
1314
```
1415

16+
The dev compose setup reads `LOGFIRE_TOKEN` from `.env` and passes it into the `service` container so Logfire can export telemetry.
17+
1518
## Local development with uv
1619

1720
Install dependencies and development tooling with [uv](https://docs.astral.sh/uv/):

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ services:
4848
- "--reload"
4949
environment:
5050
- PROJECT_NAME=strava
51+
- ENVIRONMENT=development
52+
- LOGFIRE_TOKEN=${LOGFIRE_TOKEN}
5153
- POSTGRES_SERVER=db:5432
5254
- POSTGRES_USER=postgres
5355
- POSTGRES_PASSWORD=password

strava/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Settings(BaseSettings):
1010
PROJECT_NAME: str
1111
ENVIRONMENT: str = "development"
1212
LOGFIRE_SEND_TO_LOGFIRE: bool | Literal["if-token-present"] = "if-token-present"
13+
LOGFIRE_TOKEN: str | None = None
1314

1415
POSTGRES_SERVER: str
1516
POSTGRES_USER: str = "postgres"

strava/observability.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def configure_observability(app: FastAPI, settings: Settings, engine: Engine) ->
1010
service_name=settings.PROJECT_NAME,
1111
environment=settings.ENVIRONMENT,
1212
send_to_logfire=settings.LOGFIRE_SEND_TO_LOGFIRE,
13+
token=settings.LOGFIRE_TOKEN,
1314
)
1415
logfire.instrument_fastapi(app)
1516
logfire.instrument_sqlalchemy(engine)

tests/test_config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def test_environment_default(self):
2727

2828
assert settings.ENVIRONMENT == "development"
2929

30+
def test_logfire_token_default(self):
31+
from strava.config import settings
32+
33+
assert settings.LOGFIRE_TOKEN is None
34+
3035
def test_settings_from_env(self, monkeypatch):
3136
monkeypatch.setenv("PROJECT_NAME", "my-project")
3237
monkeypatch.setenv("POSTGRES_SERVER", "db-host")
@@ -82,3 +87,15 @@ class Info:
8287
data = {}
8388

8489
assert Settings.assemble_db_connection(None, Info()) is None
90+
91+
def test_logfire_token_from_env(self, monkeypatch):
92+
monkeypatch.setenv("PROJECT_NAME", "test")
93+
monkeypatch.setenv("POSTGRES_SERVER", "localhost")
94+
monkeypatch.setenv("POSTGRES_PASSWORD", "pass")
95+
monkeypatch.setenv("POSTGRES_DB", "db")
96+
monkeypatch.setenv("LOGFIRE_TOKEN", "test-token")
97+
98+
from strava.config import Settings
99+
100+
s = Settings()
101+
assert s.LOGFIRE_TOKEN == "test-token"

tests/test_observability.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_configure_observability_wires_logfire():
1616
POSTGRES_PASSWORD="password",
1717
POSTGRES_DB="test",
1818
LOGFIRE_SEND_TO_LOGFIRE=False,
19+
LOGFIRE_TOKEN="test-token",
1920
)
2021

2122
with patch("strava.observability.logfire.configure") as configure:
@@ -29,6 +30,7 @@ def test_configure_observability_wires_logfire():
2930
service_name="strava-test",
3031
environment="test",
3132
send_to_logfire=False,
33+
token="test-token",
3234
)
3335
instrument_fastapi.assert_called_once_with(app)
3436
instrument_sqlalchemy.assert_called_once_with(engine)

0 commit comments

Comments
 (0)