mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 08:27:35 +08:00
feat: disable GA events report by setting environment DISABLE_GA=true
This commit is contained in:
@@ -4,6 +4,9 @@ on:
|
|||||||
release:
|
release:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
|
env:
|
||||||
|
DISABLE_GA: "true"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
releases-matrix:
|
releases-matrix:
|
||||||
name: Release hrp cli binaries
|
name: Release hrp cli binaries
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ on:
|
|||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
DISABLE_GA: "true"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
scaffold-with-python-plugin:
|
scaffold-with-python-plugin:
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ on:
|
|||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
DISABLE_GA: "true"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
smoke-test:
|
smoke-test:
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ on:
|
|||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
DISABLE_GA: "true"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
py-httprunner:
|
py-httprunner:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- refactor: merge [hrp] into httprunner v4, which will include golang and python dual engine
|
- refactor: merge [hrp] into httprunner v4, which will include golang and python dual engine
|
||||||
- refactor: redesign `IStep` to make step extensible to support implementing new protocols and test types
|
- refactor: redesign `IStep` to make step extensible to support implementing new protocols and test types
|
||||||
|
- feat: disable GA events report by setting environment `DISABLE_GA=true`
|
||||||
|
|
||||||
**go version**
|
**go version**
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func TestSendEvents(t *testing.T) {
|
|||||||
Action: "SendEvents",
|
Action: "SendEvents",
|
||||||
Value: 123,
|
Value: 123,
|
||||||
}
|
}
|
||||||
err := gaClient.SendEvent(event)
|
err := SendEvent(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package sdk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/denisbrodbeck/machineid"
|
"github.com/denisbrodbeck/machineid"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
@@ -46,5 +47,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SendEvent(e IEvent) error {
|
func SendEvent(e IEvent) error {
|
||||||
|
if os.Getenv("DISABLE_GA") == "true" {
|
||||||
|
// do not send GA events in CI environment
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return gaClient.SendEvent(e)
|
return gaClient.SendEvent(e)
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-2
@@ -2,6 +2,7 @@ import collections
|
|||||||
import copy
|
import copy
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import platform
|
import platform
|
||||||
import uuid
|
import uuid
|
||||||
@@ -40,8 +41,13 @@ class GAClient(object):
|
|||||||
'cid': uuid.getnode(), # Anonymous Client ID
|
'cid': uuid.getnode(), # Anonymous Client ID
|
||||||
'ua': f'HttpRunner/{__version__}',
|
'ua': f'HttpRunner/{__version__}',
|
||||||
}
|
}
|
||||||
|
# do not send GA events in CI environment
|
||||||
|
self.__is_ci = os.getenv("DISABLE_GA") == "true"
|
||||||
|
|
||||||
def track_event(self, category: Text, action: Text, value: int = 0):
|
def track_event(self, category: Text, action: Text, value: int = 0):
|
||||||
|
if self.__is_ci:
|
||||||
|
return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
't': 'event', # Event hit type = event
|
't': 'event', # Event hit type = event
|
||||||
'ec': category, # Required. Event Category.
|
'ec': category, # Required. Event Category.
|
||||||
@@ -51,11 +57,14 @@ class GAClient(object):
|
|||||||
}
|
}
|
||||||
data.update(self.common_params)
|
data.update(self.common_params)
|
||||||
try:
|
try:
|
||||||
self.http_client.post(self.report_url, data=data)
|
self.http_client.post(self.report_url, data=data, timeout=5)
|
||||||
except Exception: # ProxyError, SSLError, ConnectionError
|
except Exception: # ProxyError, SSLError, ConnectionError
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def track_user_timing(self, category: Text, variable: Text, duration: int):
|
def track_user_timing(self, category: Text, variable: Text, duration: int):
|
||||||
|
if self.__is_ci:
|
||||||
|
return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
't': 'timing', # Event hit type = timing
|
't': 'timing', # Event hit type = timing
|
||||||
'utc': category, # Required. user timing category. e.g. jsonLoader
|
'utc': category, # Required. user timing category. e.g. jsonLoader
|
||||||
@@ -65,7 +74,7 @@ class GAClient(object):
|
|||||||
}
|
}
|
||||||
data.update(self.common_params)
|
data.update(self.common_params)
|
||||||
try:
|
try:
|
||||||
self.http_client.post(self.report_url, data=data)
|
self.http_client.post(self.report_url, data=data, timeout=5)
|
||||||
except Exception: # ProxyError, SSLError, ConnectionError
|
except Exception: # ProxyError, SSLError, ConnectionError
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user