Skip to content

Commit c7b54be

Browse files
committed
chore(converter): add version in logs
1 parent 258d80a commit c7b54be

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ jobs:
7979
platforms: linux/amd64
8080
tags: ghcr.io/${{ github.repository_owner }}/hub-converter:${{ steps.extract_info.outputs.version }}
8181
context: ./converter
82+
build-args: CONVERTER_VERSION=${{ steps.extract_info.outputs.version }}

converter/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Use Python 3.11 slim as base image
22
FROM python:3.11-slim
33

4+
ARG CONVERTER_VERSION=0.0.0
5+
46
# Set environment variables
57
ENV PYTHONDONTWRITEBYTECODE=1 \
68
PYTHONUNBUFFERED=1 \
@@ -47,5 +49,7 @@ EXPOSE 8080
4749
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
4850
CMD curl -f http://localhost:8080/health || exit 1
4951

52+
ENV CONVERTER_VERSION=${CONVERTER_VERSION}
53+
5054
# Use Gunicorn for production deployment
5155
CMD ["uv", "run", "--no-dev", "gunicorn", "-w", "4", "-b", "0.0.0.0:8080", "converter.converter:app"]

converter/converter/logging_config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from flask import has_request_context, g
55
from enum import Enum
66

7+
CONVERTER_VERSION = os.getenv("CONVERTER_VERSION", "0.0.0")
8+
79

810
class LoggingKeys(Enum):
911
DISTRIBUTION_ID = "distributionId"
@@ -14,13 +16,19 @@ class LoggingKeys(Enum):
1416

1517
# Using filter to add context variable: https://docs.python.org/3/howto/logging-cookbook.html#using-filters-to-impart-contextual-information
1618
class DistributionContextFilter(logging.Filter):
17-
def filter(self, record):
19+
def filter(self, record: logging.LogRecord) -> bool:
1820
if has_request_context():
1921
for key in LoggingKeys:
2022
setattr(record, key.value, getattr(g, key.value, None))
2123
return True
2224

2325

26+
class VersionFilter(logging.Filter):
27+
def filter(self, record: logging.LogRecord) -> bool:
28+
record.converter_version = CONVERTER_VERSION
29+
return True
30+
31+
2432
def configure_logging():
2533
root = logging.getLogger()
2634
for h in root.handlers[:]:
@@ -37,6 +45,7 @@ def configure_logging():
3745
)
3846
handler.setFormatter(formatter)
3947
handler.addFilter(DistributionContextFilter())
48+
handler.addFilter(VersionFilter())
4049

4150
root.addHandler(handler)
4251

0 commit comments

Comments
 (0)