keep track of missing live events context

why:
* to see if this is a problem, since events sent out without a context
will pose a problem to live events consumers

refs INTEROP-7187
flag=none

test plan:
* follow the instructions in doc/live_events.md to set up live events
and print them to stdout logs
* follow the instructions in doc/lti_manual/11_testing.md under
`Stubbing Statsd Calls` to monkey-patch Statsd for easy metric viewing
* (a good place to put that is in the ApplicationController)
* comment out the call to `LiveEvents.set_context` in the
ApplicationController
* trigger any live event - navigating through course pages should be
enough, though creating an assignment is always a good one
* for every event triggered there should be a Statsd call for
`missing_context`
* add back the call to `set_context`
* trigger more live events
* the Statsd calls should not continue

Change-Id: Ib87952e208885ef15b00561731769f808cdcd066
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/284053
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Tucker Mcknight <tmcknight@instructure.com>
Reviewed-by: Evan Battaglia <ebattaglia@instructure.com>
QA-Review: Evan Battaglia <ebattaglia@instructure.com>
Product-Review: Xander Moffatt <xmoffatt@instructure.com>
This commit is contained in:
Xander Moffatt 2022-02-01 08:09:46 -07:00
parent 23d5f3593b
commit a09aab728a
2 changed files with 31 additions and 1 deletions

View File

@ -53,4 +53,31 @@ For testing new features that may not have been added to the test tool, or for m
5. Include a request body, which could look like something like this:
- [Line Item API docs](https://canvas.instructure.com/doc/api/line_items.html)
- [Score API docs](https://canvas.instructure.com/doc/api/score.html)
- [Result API docs](https://canvas.instructure.com/doc/api/result.html)
- [Result API docs](https://canvas.instructure.com/doc/api/result.html)
## Miscellaneous
### Stubbing Statsd Calls
This isn't exactly LTI-specific, but can come in handy. There isn't a great way to get
visibility into the calls made to `InstStatsd::Statsd`, which is the way to get metrics
sent to Datadog. It's possible to monkey-patch that class and stub the methods you care
about and just log them to stdout. If you're working entirely in the Rails console, you
can paste this patch directly into the console. If you're working with Canvas requests
at all, you can paste this patch into any Ruby file in Canvas and save it (I prefer the
one I'm currently working in, for consistency).
Replace `increment` with any Statsd method you need, or add more methods if needed.
```
class << InstStatsd::Statsd
def increment(*args)
puts "DEBUG STATSD increment: #{args.to_json}"
end
end
```
Then, look in the logs for your method calls. If you are working entirely in the Rails
console, they will appear there. If you are working with Canvas requests, tail the web
container's logs with `docker-compose logs -f --tail=100 web` and then search for
`DEBUG STATSD`.

View File

@ -108,6 +108,9 @@ module LiveEvents
if context.is_a?(Proc)
context = Thread.current[:live_events_ctx] = context.call
end
if context.blank?
LiveEvents&.statsd&.increment("live_events.missing_context")
end
context
end