feat: add phase 1 Datadog instrumentation for thread creation#236
Conversation
There was a problem hiding this comment.
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_typevalues. - Emit
forum.entity_idafter successful thread persistence increate_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.
| 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) |
| set_custom_attribute("forum.result", "error") | ||
| set_custom_attribute("forum.http_status", str(status.HTTP_400_BAD_REQUEST)) |
There was a problem hiding this comment.
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_idafter successful thread creation in the internalcreate_threadhelper.
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.
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
POST /api/discussion/v1/threadsforum.operationforum.course_idforum.entity_typeforum.actor_idforum.resultforum.http_statusforum.thread_typeforum.commentable_idforum.group_idforum.entity_idafter thread creation succeedsWhy
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:
Validation
This change is expected to be validated in stage together with the paired
forumandedx-internalupdates.Expected Datadog outcomes:
@forum.operation:thread.createforum.resulton success and error pathsforum.entity_idon successful thread creationRelated
COSMO2-853