blob: 06e0266fc299e3d0a13ba653f476d9d8d82d7a68 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""A class to log client-side javascript error reports.
6
7Updates frontend/js_errors ts_mon metric.
8"""
9from __future__ import print_function
10from __future__ import division
11from __future__ import absolute_import
12
13import json
14import logging
15
16from framework import jsonfeed
17
18from infra_libs import ts_mon
19
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020020
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010021class ClientMonitor(jsonfeed.JsonFeed):
Copybara854996b2021-09-07 19:36:02 +000022 """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
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020038 post_data = mr.request.values
Copybara854996b2021-09-07 19:36:02 +000039 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 {}
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020053
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020054 def PostClientMonitor(self, **kwargs):
55 return self.handler(**kwargs)