mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-25 09:33:43 +08:00
change: replace events reporter from sentry to Google Analytics
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -16,4 +16,5 @@ site/
|
||||
reports
|
||||
.venv
|
||||
*.xml
|
||||
htmlcov/
|
||||
htmlcov/
|
||||
*.bak
|
||||
@@ -1,5 +1,9 @@
|
||||
# Release History
|
||||
|
||||
## 2.5.8 (2020-03-23)
|
||||
|
||||
- change: replace events reporter from sentry to Google Analytics
|
||||
|
||||
## 2.5.7 (2020-02-21)
|
||||
|
||||
**Changed**
|
||||
@@ -193,7 +197,7 @@
|
||||
**Added**
|
||||
|
||||
- feat: add `upload` keyword for upload test, see [doc](https://docs.httprunner.org/prepare/upload-case/)
|
||||
- test: pip install package
|
||||
- test: pip install package
|
||||
- test: hrun command
|
||||
|
||||
**Fixed**
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from sentry_sdk import capture_message
|
||||
|
||||
from httprunner import (__version__, exceptions, loader, logger, parser,
|
||||
report, runner, utils)
|
||||
from httprunner.utils import ga_client
|
||||
|
||||
|
||||
class HttpRunner(object):
|
||||
@@ -185,7 +184,7 @@ class HttpRunner(object):
|
||||
def run_tests(self, tests_mapping):
|
||||
""" run testcase/testsuite data
|
||||
"""
|
||||
capture_message("start to run tests")
|
||||
ga_client.track_event("RunAPITests", "hrun")
|
||||
project_mapping = tests_mapping.get("project_mapping", {})
|
||||
self.project_working_directory = project_mapping.get("PWD", os.getcwd())
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ def gen_locustfile(testcase_file_path):
|
||||
|
||||
|
||||
def start_locust_main():
|
||||
from httprunner.utils import ga_client
|
||||
ga_client.track_event("RunLoadTests", "locust")
|
||||
|
||||
locust_main.main()
|
||||
|
||||
|
||||
|
||||
@@ -9,10 +9,12 @@ import os.path
|
||||
import re
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Text
|
||||
|
||||
import requests
|
||||
import sentry_sdk
|
||||
|
||||
from httprunner import exceptions, logger, __version__
|
||||
from httprunner import __version__, exceptions, logger
|
||||
from httprunner.compat import basestring, bytes, is_py2
|
||||
from httprunner.exceptions import ParamsError
|
||||
|
||||
@@ -29,6 +31,48 @@ def init_sentry_sdk():
|
||||
scope.set_user({"id": uuid.getnode()})
|
||||
|
||||
|
||||
class GAClient(object):
|
||||
|
||||
version = '1' # GA API Version
|
||||
report_url = 'https://www.google-analytics.com/collect'
|
||||
report_debug_url = 'https://www.google-analytics.com/debug/collect' # used for debug
|
||||
|
||||
def __init__(self, tracking_id: Text):
|
||||
self.http_client = requests.Session()
|
||||
self.label = str(__version__)
|
||||
self.common_params = {
|
||||
'v': self.version,
|
||||
'tid': tracking_id, # Tracking ID / Property ID, XX-XXXXXXX-X
|
||||
'cid': uuid.getnode(), # Anonymous Client ID
|
||||
'ua': f'HttpRunner/{__version__}',
|
||||
}
|
||||
|
||||
def track_event(self, category: Text, action: Text, value: int = 0):
|
||||
data = {
|
||||
't': 'event', # Event hit type = event
|
||||
'ec': category, # Required. Event Category.
|
||||
'ea': action, # Required. Event Action.
|
||||
'el': self.label, # Optional. Event label, used as version.
|
||||
'ev': value, # Optional. Event value, must be non-negative integer
|
||||
}
|
||||
data.update(self.common_params)
|
||||
self.http_client.post(self.report_url, data=data)
|
||||
|
||||
def track_user_timing(self, category: Text, variable: Text, duration: int):
|
||||
data = {
|
||||
't': 'timing', # Event hit type = timing
|
||||
'utc': category, # Required. user timing category. e.g. jsonLoader
|
||||
'utv': variable, # Required. timing variable. e.g. load
|
||||
'utt': duration, # Required. time took duration.
|
||||
'utl': self.label, # Optional. user timing label, used as version.
|
||||
}
|
||||
data.update(self.common_params)
|
||||
self.http_client.post(self.report_url, data=data)
|
||||
|
||||
|
||||
ga_client = GAClient("UA-114587036-1")
|
||||
|
||||
|
||||
def set_os_environ(variables_mapping):
|
||||
""" set variables mapping to os.environ
|
||||
"""
|
||||
@@ -374,6 +418,7 @@ def create_scaffold(project_name):
|
||||
logger.log_warning(u"Folder {} exists, please specify a new folder name.".format(project_name))
|
||||
return
|
||||
|
||||
ga_client.track_event("Scaffold", "startproject")
|
||||
logger.color_print("Start to create new project: {}".format(project_name), "GREEN")
|
||||
logger.color_print("CWD: {}\n".format(os.getcwd()), "BLUE")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user