blob: f512f4d64462264cc6184e9ad83ff0f3c4540def [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
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020021
22# TODO: convert to FlaskJsonFeed while convert to Flask
Copybara854996b2021-09-07 19:36:02 +000023class ClientMonitor(jsonfeed.JsonFeed):
24 """JSON feed to track client side js errors in ts_mon."""
25
26 js_errors = ts_mon.CounterMetric('frontend/js_errors',
27 'Number of uncaught client-side JS errors.',
28 None)
29
30 def HandleRequest(self, mr):
31 """Build up a dictionary of data values to use when rendering the page.
32
33 Args:
34 mr: commonly used info parsed from the request.
35
36 Returns:
37 Dict of values used by EZT for rendering the page.
38 """
39
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020040 # TODO: uncomment while convert to flask
41 # post_data = mr.request.values
Copybara854996b2021-09-07 19:36:02 +000042 post_data = mr.request.POST
43 errors = post_data.get('errors')
44 try:
45 errors = json.loads(errors)
46
47 total_errors = 0
48 for error_key in errors:
49 total_errors += errors[error_key]
50 logging.error('client monitor report (%d): %s', total_errors,
51 post_data.get('errors'))
52 self.js_errors.increment_by(total_errors)
53 except Exception as e:
54 logging.error('Problem processing client monitor report: %r', e)
55
56 return {}
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020057
58 # def GetClientMonitor(self, **kwargs):
59 # return self.handler(**kwargs)
60
61 # def PostClientMonitor(self, **kwargs):
62 # return self.handler(**kwargs)