Skip to content

Commit 47381fc

Browse files
authored
Merge pull request #63 from QWED-AI/feat/sentry-monitoring
feat(monitoring): Integrate Sentry SDK + docker security fix
2 parents 194d851 + f0c5fd0 commit 47381fc

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ RUN useradd -m -u 1000 appuser
1919
# Fix permissions for GitHub Actions workspace
2020
RUN mkdir -p /github/workspace && chown -R appuser:appuser /github
2121

22-
# Install gosu and dos2unix for entrypoint management
23-
RUN apt-get update && apt-get install -y --no-install-recommends gosu dos2unix && rm -rf /var/lib/apt/lists/*
22+
# Install dos2unix for entrypoint management (runuser is native in base image)
23+
RUN apt-get update && apt-get install -y --no-install-recommends dos2unix && rm -rf /var/lib/apt/lists/*
2424

2525
# Copy requirements file first to leverage cache
2626
COPY requirements.txt /app/requirements.txt
@@ -56,7 +56,7 @@ if [ -d "/github/file_commands" ]; then\n\
5656
fi\n\
5757
\n\
5858
# Switch to appuser and run the main entrypoint\n\
59-
exec gosu appuser python /action_entrypoint.py "$@"\n\
59+
exec runuser -u appuser -- python /action_entrypoint.py "$@"\n\
6060
' > /entrypoint.sh && chmod +x /entrypoint.sh
6161

6262
# Set Python path to use local SDK
@@ -65,5 +65,5 @@ ENV PYTHONPATH=/app
6565
WORKDIR /github/workspace
6666

6767
# NOTE: We do NOT switch USER here. We start as root to fix permissions on mounted volumes
68-
# in entrypoint.sh, then drop privileges to appuser using gosu.
68+
# in entrypoint.sh, then drop privileges to appuser using runuser.
6969
ENTRYPOINT ["/entrypoint.sh"]

action_entrypoint.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
import glob
1414
from pathlib import Path
1515

16+
try:
17+
import sentry_sdk
18+
except ImportError:
19+
sentry_sdk = None
20+
1621
# QWED SDK imports - only guards (no heavy dependencies)
1722
sys.path.insert(0, "/app")
1823
from qwed_sdk.guards.system_guard import SystemGuard
@@ -415,4 +420,30 @@ def main():
415420

416421

417422
if __name__ == "__main__":
418-
main()
423+
# Initialize Sentry if DSN is provided
424+
sentry_dsn = get_env("SENTRY_DSN") or os.environ.get("SENTRY_DSN")
425+
if sentry_dsn and sentry_sdk:
426+
print("🔭 Initializing Sentry SDK...")
427+
sentry_sdk.init(
428+
dsn=sentry_dsn,
429+
traces_sample_rate=1.0, # Capture 100% of transactions for performance monitoring
430+
environment="production",
431+
release=os.environ.get("GITHUB_SHA", "unknown"),
432+
)
433+
sentry_sdk.set_tag("repository", os.environ.get("GITHUB_REPOSITORY", "unknown"))
434+
sentry_sdk.set_tag("actor", os.environ.get("GITHUB_ACTOR", "unknown"))
435+
sentry_sdk.set_tag("run_id", os.environ.get("GITHUB_RUN_ID", "unknown"))
436+
437+
# Capture strictly necessary context, avoid PII unless explicitly enabled
438+
sentry_sdk.set_context("github", {
439+
"ref": os.environ.get("GITHUB_REF"),
440+
"workflow": os.environ.get("GITHUB_WORKFLOW"),
441+
"action": os.environ.get("GITHUB_ACTION"),
442+
})
443+
444+
try:
445+
main()
446+
except Exception as e:
447+
if sentry_dsn and sentry_sdk:
448+
sentry_sdk.capture_exception(e)
449+
raise

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ httpx>=0.28.1
33
httpcore>=1.0.9
44
h11>=0.16.0
55
colorama==0.4.6
6+
sentry-sdk

requirements.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is autogenerated by pip-compile with Python 3.11
33
# by the following command:
44
#
5-
# pip-compile --generate-hashes --output-file=requirements.txt requirements.in
5+
# pip-compile --generate-hashes requirements.in
66
#
77
anyio==4.12.1 \
88
--hash=sha256:41cfcc3a4c85d3f05c932da7c26d0201ac36f72abd4435ba90d0464a3ffed703 \
@@ -14,6 +14,7 @@ certifi==2026.1.4 \
1414
# via
1515
# httpcore
1616
# httpx
17+
# sentry-sdk
1718
colorama==0.4.6 \
1819
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
1920
--hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
@@ -44,6 +45,10 @@ mpmath==1.3.0 \
4445
--hash=sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f \
4546
--hash=sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c
4647
# via sympy
48+
sentry-sdk==2.52.0 \
49+
--hash=sha256:931c8f86169fc6f2752cb5c4e6480f0d516112e78750c312e081ababecbaf2ed \
50+
--hash=sha256:fa0bec872cfec0302970b2996825723d67390cdd5f0229fb9efed93bd5384899
51+
# via -r requirements.in
4752
sympy==1.12 \
4853
--hash=sha256:3e2e0e09210c4d8f8d660e574c88f728c050228497d51921356a9829352e8253 \
4954
--hash=sha256:c3588cd4295d0c0f603d0f2ae780587e64e2efeedb3521e46b9bb1d08d184fa5 \
@@ -53,3 +58,7 @@ typing-extensions==4.15.0 \
5358
--hash=sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466 \
5459
--hash=sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548
5560
# via anyio
61+
urllib3==2.6.3 \
62+
--hash=sha256:1b62b6884944a57dbe321509ab94fd4d3b307075e0c2eae991ac71ee15ad38ed \
63+
--hash=sha256:bf272323e553dfb2e87d9bfd225ca7b0f467b919d7bbd355436d3fd37cb0acd4
64+
# via sentry-sdk

0 commit comments

Comments
 (0)