feat: Change the logging config for edx-platform. - #206
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the generated docker-production.py Django settings inside the edx-platform image to bring k8s logging behavior closer to the prior EC2 configuration, including adding Datadog trace correlation data to console logs.
Changes:
- Adds an extended console log formatter with hostname/process/user/IP/file/line context.
- Includes Datadog
dd.trace_idin the console log format. - Leaves the tracking log handler behavior intact while adding formatting overrides.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d9d3648 to
d476b7d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
dockerfiles/edx-platform.Dockerfile:292
- The new console formatter references custom LogRecord keys (e.g.
dd.trace_id,userid,remoteip). If any log record doesn’t provide these fields, Python logging will raise a formatting error and drop the log message. To make this robust for third-party / early-startup logs, adddefaultsto the formatter config so missing keys have safe fallbacks.
syslog_format = ("[%(name)s] %(levelname)s [trace_id %(dd.trace_id)s]"
"[{hostname} %(process)d] [user %(userid)s] [ip %(remoteip)s] [%(filename)s:%(lineno)d] "
"- %(message)s").format(hostname=platform.node().split(".")[0])
LOGGING["formatters"]["syslog_format"] = {"format": syslog_format}
d476b7d to
c61a73b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
dockerfiles/edx-platform.Dockerfile:292
- The console formatter includes
%(dd.trace_id)swheneverddtraceis importable, but log records won’t necessarily containdd.trace_idunless ddtrace log injection is enabled (and even then it may be absent in some contexts). Python’s logging formatter will raise aKeyErrorfor missing format fields, which can break logging at runtime. Consider (a) gating inclusion of the trace id onddtrace.config.logs_injectionand (b) providingdefaultsfor non-standard fields (includingdd.trace_id,userid, andremoteip) to prevent formatter errors. This also makes the ddtrace/non-ddtrace formats consistent for the hostname/process portion.
try:
# This should check to see if ddtrace is available in the context for setting up the loggers.
# If it is available, include the trace_id in the log string. If it is not, exclude it.
import ddtrace
syslog_format = ("[%(name)s] %(levelname)s [trace_id %(dd.trace_id)s] "
c61a73b to
0111bb9
Compare
0111bb9 to
c9533a9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
dockerfiles/edx-platform.Dockerfile:292
- The presence of the
ddtracepackage alone doesn’t guarantee thatdd.*fields are injected into every LogRecord. Ifddtraceis installed but logs injection is disabled, this formatter can raiseKeyErrorat runtime when it tries to render%(dd.trace_id)s, etc. Consider guarding on ddtrace’s logs-injection setting (or an explicit env flag) and falling back to the non-DD format when injection isn’t enabled.
try:
# This should check to see if ddtrace is available in the context for setting up the loggers.
# If it is available, include Datadog information in the log string. If it is not, exclude it.
import ddtrace
syslog_format = ("[%(name)s] %(levelname)s "
c9533a9 to
d918f58
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
dockerfiles/edx-platform.Dockerfile:296
- The new
syslog_formatreferences non-standardLogRecordkeys (e.g.,userid,remoteip, and thedd.*fields). With the defaultlogging.Formatter, any log record missing these keys will raise a formattingKeyErrorand can cause log lines to be dropped; additionally, importingddtracejust to check availability can add import-time overhead/side effects.
Consider (1) checking for ddtrace without importing it, and (2) configuring formatter defaults so missing fields don’t break logging.
syslog_format = ("[%(name)s] %(levelname)s "
"[dd.service=%(dd.service)s dd.env=%(dd.env)s dd.version=%(dd.version)s dd.trace_id=%(dd.trace_id)s"
" dd.span_id=%(dd.span_id)s] "
"[{hostname}] [process %(process)d] [user %(userid)s] [ip %(remoteip)s] [%(filename)s:%(lineno)d] "
"- %(message)s").format(hostname=platform.node().split(".")[0])
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
dockerfiles/edx-platform.Dockerfile:292
- The new syslog formatter references non-standard LogRecord fields (e.g.,
userid,remoteip, and in the ddtrace branchdd.trace_id/dd.span_id). Python logging raisesKeyErrorduring formatting if any referenced field is missing, which can cause log lines to be dropped and emit noisy "Logging error" traces. Consider adding a small logging Filter to supply safe defaults for these fields (and avoid importingddtracejust to check availability).
try:
# This should check to see if ddtrace is available in the context for setting up the loggers.
# If it is available, include Datadog information in the log string. If it is not, exclude it.
import ddtrace
syslog_format = ("[%(name)s] %(levelname)s "
This adds back in user id, ip address, hostname to the console output. It also adds in Datadog information if the code is being run within ddtrace. https://2u-internal.atlassian.net/browse/BOMS-661
c632817 to
c3de773
Compare
The logs changed between ec2 and k8s because the config between the two is different. This tries to re-introduce some of the extra logging parameters and adds in the DD trace id for good measure.
https://2u-internal.atlassian.net/browse/BOMS-661