Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to capture more in telemetry #508

Merged
merged 4 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-devops/azext_devops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def post_parse_args(_cli_ctx, **kwargs):
# we need to set tracking data only after we know that all args are valid,
# otherwise we may log EUII data that a user inadvertently sent as an argument
# name. We already don't log argument values.
set_tracking_data(kwargs['command'].split())
set_tracking_data(**kwargs)


COMMAND_LOADER_CLS = DevCommandsLoader
39 changes: 17 additions & 22 deletions azure-devops/azext_devops/dev/common/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,26 @@ def try_send_telemetry_data(organization):
logger.debug('Azure devops telemetry sending failed.')


def set_tracking_data(argv):
def set_tracking_data(**kwargs):
try:
vsts_tracking_data.area = 'AzureDevopsCli'
vsts_tracking_data.properties = {}
if argv:
vsts_tracking_data.feature = argv[0]
else:
vsts_tracking_data.feature = None
if len(argv) > 1:
command = []
args = []
command_populated = False
for arg in argv[1:]:
if arg and argv:
if not command_populated and arg[0] != '-':
command.append(arg)
elif arg[0] == '-':
args.append(arg.lstrip('-'))
command_populated = True
if command:
vsts_tracking_data.properties['Command'] = ' '.join(command)
else:
vsts_tracking_data.properties['Command'] = ''
vsts_tracking_data.properties['Args'] = args
vsts_tracking_data.properties['ShellType'] = _get_shell_type()
command_line_args = vars(kwargs.get('args', None))
command_line_split = command_line_args['command'].split()
vsts_tracking_data.feature = command_line_split[0]
if len(command_line_split) > 1:
vsts_tracking_data.properties['Command'] = ' '.join(command_line_split[1:])

args = []
for key, value in command_line_args.items():
if value and isinstance(value, str) and not key.startswith('_') and key != 'command':
args.append(key)

vsts_tracking_data.properties['Args'] = ' '.join(args)
vsts_tracking_data.properties['ShellType'] = _get_shell_type()
import sys
vsts_tracking_data.properties['IsInteractive'] = str(sys.stdin.isatty())
vsts_tracking_data.properties['OutputType'] = command_line_args['_output_format']

except BaseException as ex:
logger.debug(ex, exc_info=True)
Expand Down
22 changes: 12 additions & 10 deletions azure-devops/azext_devops/test/common/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# Attempt to load mock (works on Python version below 3.3)
from mock import patch

from azext_devops.dev.common.telemetry import (set_tracking_data,
try_send_telemetry_data, vsts_tracking_data)
from azext_devops.dev.common.telemetry import (set_tracking_data, try_send_telemetry_data)


class TestTelemetryMethods(unittest.TestCase):
Expand All @@ -39,14 +38,17 @@ def test_send_telemetry_should_not_send_if_disabled(self):


def test_set_tracking_data_should_set_data_correctly_with_command(self):
set_tracking_data(['devops', 'project', 'list'])
assert vsts_tracking_data.area == 'AzureDevopsCli'
assert vsts_tracking_data.feature == 'devops'
assert vsts_tracking_data.properties['Command'] == 'project list'
class FakeTelemetryClass:
def __init__(self, command):
self.command = command

def __iter__():
for key, value in self.command:
yield(key, value)

def test_set_tracking_data_should_set_data_correctly_with_none(self):
set_tracking_data(None)
command_dict = FakeTelemetryClass('devops repos list')
set_tracking_data(**{'args': command_dict})
from azext_devops.dev.common.telemetry import vsts_tracking_data
assert vsts_tracking_data.area == 'AzureDevopsCli'
assert vsts_tracking_data.feature == None
assert vsts_tracking_data.properties == {}
assert vsts_tracking_data.feature == 'devops'
assert vsts_tracking_data.properties['Command'] == 'repos list'