Skip to content

feat: add phase 1 Datadog instrumentation for thread creation#236

Merged
santhosh-apphelix-2u merged 4 commits into
release-ulmofrom
COSMO2-853-forum-instrumentation
Apr 20, 2026
Merged

feat: add phase 1 Datadog instrumentation for thread creation#236
santhosh-apphelix-2u merged 4 commits into
release-ulmofrom
COSMO2-853-forum-instrumentation

Conversation

@santhosh-apphelix-2u
Copy link
Copy Markdown

Summary

This PR adds Phase 1 Datadog instrumentation for the thread creation flow in LMS discussion APIs.

The goal of this phase is to validate one clean end-to-end vertical slice before expanding instrumentation to other discussion APIs.

What Changed

  • added request-level telemetry for POST /api/discussion/v1/threads
  • emits canonical attributes for the thread creation flow:
    • forum.operation
    • forum.course_id
    • forum.entity_type
    • forum.actor_id
    • forum.result
    • forum.http_status
  • emits contextual attributes when present:
    • forum.thread_type
    • forum.commentable_id
    • forum.group_id
  • emits forum.entity_id after thread creation succeeds
  • added simple error classification for discussion request failures

Why

For the current discussion flow, the request starts in edx-platform, so request-level instrumentation needs to be emitted here.

Scope

This PR is intentionally limited to Phase 1 only.

Covered in this phase:

  • thread creation flow

Validation

This change is expected to be validated in stage together with the paired forum and edx-internal updates.

Expected Datadog outcomes:

  • @forum.operation:thread.create
  • forum.result on success and error paths
  • forum.entity_id on successful thread creation

Related

  • Ticket: COSMO2-853

Copilot AI review requested due to automatic review settings April 17, 2026 04:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Phase 1 Datadog request-level instrumentation for the LMS discussion thread-creation endpoint (POST /api/discussion/v1/threads) to emit canonical attributes, contextual attributes, and basic error classification for an end-to-end vertical slice.

Changes:

  • Add request-scoped set_custom_attribute(...) calls for thread creation (operation, actor/course/entity context, result + http status, error classification).
  • Introduce a helper to map common exceptions to stable forum.error_type values.
  • Emit forum.entity_id after successful thread persistence in create_thread.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lms/djangoapps/discussion/rest_api/views.py Adds request-level Datadog attributes for the thread creation view and introduces error-type mapping.
lms/djangoapps/discussion/rest_api/api.py Emits forum.entity_id once the thread has been created (post-serializer save).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lms/djangoapps/discussion/rest_api/views.py
Comment on lines 745 to 749
try:
if not request.data.get("course_id"):
raise ValidationError({"course_id": ["This field is required."]})
course_key_str = request.data.get("course_id")
course_key = CourseKey.from_string(course_key_str)
Comment on lines +792 to +793
set_custom_attribute("forum.result", "error")
set_custom_attribute("forum.http_status", str(status.HTTP_400_BAD_REQUEST))
Copilot AI review requested due to automatic review settings April 17, 2026 04:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds initial (“Phase 1”) Datadog request-level instrumentation for the LMS discussion thread creation endpoint (POST /api/discussion/v1/threads) to validate end-to-end telemetry before expanding coverage.

Changes:

  • Emit canonical request attributes for thread creation (operation, entity type, actor, course, and contextual IDs when provided).
  • Classify common error types for discussion request failures and tag success/error outcomes.
  • Tag forum.entity_id after successful thread creation in the internal create_thread helper.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
lms/djangoapps/discussion/rest_api/views.py Adds request-level Datadog attributes and error classification around ThreadViewSet.create.
lms/djangoapps/discussion/rest_api/api.py Sets forum.entity_id after thread creation succeeds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lms/djangoapps/discussion/rest_api/views.py
Comment thread lms/djangoapps/discussion/rest_api/views.py
Comment thread lms/djangoapps/discussion/rest_api/api.py
Comment thread lms/djangoapps/discussion/rest_api/views.py
@santhosh-apphelix-2u santhosh-apphelix-2u merged commit b8b6b4a into release-ulmo Apr 20, 2026
64 checks passed
@santhosh-apphelix-2u santhosh-apphelix-2u deleted the COSMO2-853-forum-instrumentation branch April 20, 2026 05:04
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