blob: cc4917c35a4b77efa2d09687b65732cf6efa7cef [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""A class to log client-side javascript error reports.
7
8Updates frontend/js_errors ts_mon metric.
9"""
10from __future__ import print_function
11from __future__ import division
12from __future__ import absolute_import
13
14import json
15import logging
16
17from framework import jsonfeed
18
19from infra_libs import ts_mon
20
21class ClientMonitor(jsonfeed.JsonFeed):
22 """JSON feed to track client side js errors in ts_mon."""
23
24 js_errors = ts_mon.CounterMetric('frontend/js_errors',
25 'Number of uncaught client-side JS errors.',
26 None)
27
28 def HandleRequest(self, mr):
29 """Build up a dictionary of data values to use when rendering the page.
30
31 Args:
32 mr: commonly used info parsed from the request.
33
34 Returns:
35 Dict of values used by EZT for rendering the page.
36 """
37
38 post_data = mr.request.POST
39 errors = post_data.get('errors')
40 try:
41 errors = json.loads(errors)
42
43 total_errors = 0
44 for error_key in errors:
45 total_errors += errors[error_key]
46 logging.error('client monitor report (%d): %s', total_errors,
47 post_data.get('errors'))
48 self.js_errors.increment_by(total_errors)
49 except Exception as e:
50 logging.error('Problem processing client monitor report: %r', e)
51
52 return {}