Skip to content

Commit a907cc7

Browse files
committed
log tags
1 parent 7505a9c commit a907cc7

4 files changed

Lines changed: 367 additions & 0 deletions

File tree

test-logs-tags/main.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import asyncio
2+
import os
3+
4+
import sentry_sdk
5+
6+
import logging
7+
logger = logging.getLogger(__name__)
8+
logging.basicConfig(
9+
level=logging.INFO,
10+
format='%(asctime)s %(levelname)s %(message)s',
11+
)
12+
13+
14+
async def main():
15+
sentry_sdk.init(
16+
dsn=os.getenv("SENTRY_DSN", None),
17+
environment=os.getenv("ENV", "local"),
18+
traces_sample_rate=1.0,
19+
send_default_pii=True,
20+
enable_logs=True,
21+
debug=True,
22+
)
23+
24+
with sentry_sdk.start_transaction(op="function", name="logs-tags-transaction"):
25+
outcome = ValueError("test error")
26+
27+
extra = {
28+
"one": "1",
29+
}
30+
tags = {
31+
"interaction_type": "proxy_request",
32+
}
33+
sentry_sdk.set_tags(tags)
34+
35+
extra.update(tags)
36+
log_params = {
37+
"extra": extra,
38+
}
39+
event_id = sentry_sdk.capture_exception(outcome) # error event sent
40+
log_params["extra"]["slo_event_id"] = event_id
41+
42+
logger.warning("something", **log_params) # log event sent`
43+
44+
45+
if __name__ == "__main__":
46+
asyncio.run(main())

test-logs-tags/pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "test-logging"
3+
version = "0"
4+
requires-python = ">=3.12"
5+
6+
dependencies = [
7+
"ipdb>=0.13.13",
8+
"sentry-sdk",
9+
]
10+
11+
[tool.uv.sources]
12+
sentry-sdk = { path = "../../sentry-python", editable = true }

test-logs-tags/run.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
# exit on first error
4+
set -xe
5+
6+
# Install uv if it's not installed
7+
if ! command -v uv &> /dev/null; then
8+
curl -LsSf https://astral.sh/uv/install.sh | sh
9+
fi
10+
11+
# Run the script
12+
uv run python main.py

test-logs-tags/uv.lock

Lines changed: 297 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)