Skip to content

Commit 56164b8

Browse files
committed
Added docker check.
1 parent 6861956 commit 56164b8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/backend/backend_ga4.py

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from copy import copy
99
from urllib import request
10+
import os
1011

1112
from .backend import TelemetryBackend
1213
from ..utils.cid import get_or_generate_cid, remove_cid_file
@@ -21,6 +22,18 @@ def _send_func(request_data):
2122
pass # nosec
2223

2324

25+
def is_docker():
26+
def text_in_file(text, filename):
27+
try:
28+
with open(filename, encoding='utf-8') as lines:
29+
return any(text in line for line in lines)
30+
except OSError:
31+
return False
32+
33+
cgroup = os.path.join('proc', 'self', 'cgroup')
34+
return os.path.exists(os.sep + '.dockerenv') or text_in_file('docker', cgroup)
35+
36+
2437
class GA4Backend(TelemetryBackend):
2538
id = 'ga4'
2639
cid_filename = 'openvino_ga_cid'
@@ -74,10 +87,13 @@ def build_event_message(self, event_category: str, event_action: str, event_labe
7487
self.generate_new_session_id()
7588

7689
default_args = copy(self.default_message_attrs)
90+
default_args['docker'] = 'False'
7791
if app_name is not None:
7892
default_args['app_name'] = app_name
7993
if app_version is not None:
8094
default_args['app_version'] = app_version
95+
if is_docker():
96+
default_args['docker'] = 'True'
8197

8298
payload = {
8399
"client_id": client_id,

0 commit comments

Comments
 (0)