Skip to content

feat: Change the logging config for edx-platform. - #206

Merged
dianakhuang merged 1 commit into
mainfrom
diana/logging-updates
Jul 22, 2026
Merged

feat: Change the logging config for edx-platform.#206
dianakhuang merged 1 commit into
mainfrom
diana/logging-updates

Conversation

@dianakhuang

Copy link
Copy Markdown
Member

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

Copilot AI review requested due to automatic review settings July 17, 2026 16:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id in 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.

Comment thread dockerfiles/edx-platform.Dockerfile
@dianakhuang
dianakhuang force-pushed the diana/logging-updates branch from d9d3648 to d476b7d Compare July 20, 2026 18:53
Copilot AI review requested due to automatic review settings July 20, 2026 18:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, add defaults to 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}

@dianakhuang
dianakhuang force-pushed the diana/logging-updates branch from d476b7d to c61a73b Compare July 21, 2026 15:11
Copilot AI review requested due to automatic review settings July 21, 2026 15:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)s whenever ddtrace is importable, but log records won’t necessarily contain dd.trace_id unless ddtrace log injection is enabled (and even then it may be absent in some contexts). Python’s logging formatter will raise a KeyError for missing format fields, which can break logging at runtime. Consider (a) gating inclusion of the trace id on ddtrace.config.logs_injection and (b) providing defaults for non-standard fields (including dd.trace_id, userid, and remoteip) 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] "

@dianakhuang
dianakhuang force-pushed the diana/logging-updates branch from c61a73b to 0111bb9 Compare July 21, 2026 16:12
Copilot AI review requested due to automatic review settings July 21, 2026 16:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread dockerfiles/edx-platform.Dockerfile Outdated
@dianakhuang
dianakhuang force-pushed the diana/logging-updates branch from 0111bb9 to c9533a9 Compare July 21, 2026 16:37
Copilot AI review requested due to automatic review settings July 21, 2026 16:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ddtrace package alone doesn’t guarantee that dd.* fields are injected into every LogRecord. If ddtrace is installed but logs injection is disabled, this formatter can raise KeyError at 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 "

Comment thread dockerfiles/edx-platform.Dockerfile Outdated
@dianakhuang
dianakhuang force-pushed the diana/logging-updates branch from c9533a9 to d918f58 Compare July 21, 2026 17:09
Copilot AI review requested due to automatic review settings July 21, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_format references non-standard LogRecord keys (e.g., userid, remoteip, and the dd.* fields). With the default logging.Formatter, any log record missing these keys will raise a formatting KeyError and can cause log lines to be dropped; additionally, importing ddtrace just 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])

Comment thread dockerfiles/edx-platform.Dockerfile Outdated
Copilot AI review requested due to automatic review settings July 21, 2026 22:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 branch dd.trace_id / dd.span_id). Python logging raises KeyError during 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 importing ddtrace just 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
@dianakhuang
dianakhuang force-pushed the diana/logging-updates branch from c632817 to c3de773 Compare July 22, 2026 16:03
@dianakhuang
dianakhuang merged commit 3f6149f into main Jul 22, 2026
3 checks passed
@dianakhuang
dianakhuang deleted the diana/logging-updates branch July 22, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants