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

Telemetry/enable app insights [Finished #114911063] #33

Merged
merged 10 commits into from
Mar 11, 2016
Prev Previous commit
Next Next commit
update where telemetry calls are made
  • Loading branch information
BurtBiel committed Mar 10, 2016
commit f7bcd3067fd9a4acc25f85d4bda10aaaca814762
3 changes: 0 additions & 3 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
<Compile Include="azure\cli\tests\test_profile.py" />
<Compile Include="azure\cli\_argparse.py" />
<Compile Include="azure\cli\_logging.py" />
<Compile Include="azure\cli\_performance.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\cli\_profile.py" />
<Compile Include="azure\cli\_session.py">
<SubType>Code</SubType>
Expand Down
13 changes: 12 additions & 1 deletion src/azure/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@

import azure.cli.main

sys.exit(azure.cli.main.main(sys.argv[1:]))
from ._telemetry import init_telemetry, user_agrees_to_telemetry, telemetry_flush

try:
try:
if user_agrees_to_telemetry():
init_telemetry()
except Exception: #pylint: disable=broad-except
pass

sys.exit(azure.cli.main.main(sys.argv[1:]))
finally:
telemetry_flush()
4 changes: 1 addition & 3 deletions src/azure/cli/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from ._locale import L, get_file as locale_get_file
from ._logging import logger
from ._output import OutputProducer
from ._telemetry import telemetry_log_event

# Named arguments are prefixed with one of these strings
ARG_PREFIXES = sorted(('-', '--', '/'), key=len, reverse=True)
Expand Down Expand Up @@ -125,7 +124,7 @@ def add_command(self,
else:
v = aliases.pop().strip('<> ')
if not target:
target, _ = _read_arg(aliases[0])
target, _ = _read_arg(aliases[0])
kw.update({_read_arg(a)[0]: (target, v, req, aliases) for a in aliases})
ad.append(('/'.join(aliases), desc, req))

Expand Down Expand Up @@ -240,7 +239,6 @@ def not_global(a):
sys.stdout = out
return ArgumentParserResult(handler(parsed, others), output_format)
except IncorrectUsageError as ex:
telemetry_log_event("Incorrect Usage", {"CommandName": " ".join(nouns)})
print(str(ex), file=out)
return ArgumentParserResult(self._display_usage(nouns, m, out))
finally:
Expand Down
16 changes: 0 additions & 16 deletions src/azure/cli/_performance.py

This file was deleted.

37 changes: 16 additions & 21 deletions src/azure/cli/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,32 @@
from applicationinsights.exceptions import enable
import azure.cli as cli

# event, exception, Trace, metric, message
client = {}

class Telemetry(object): # pylint:disable=too-few-public-methods
client = None

@staticmethod
def init_telemetry():
def init_telemetry():
try:
instrumentation_key = 'eb6e9d3a-b6ee-41a6-804f-70e152fdfc36'

Telemetry.client = TelemetryClient(instrumentation_key)
global client #pylint: disable=global-statement
client = TelemetryClient(instrumentation_key)

Telemetry.client.context.application.id = 'Azure CLI'
Telemetry.client.context.application.ver = cli.__version__
Telemetry.client.context.user.id = hash(getpass.getuser())
client.context.application.id = 'Azure CLI'
client.context.application.ver = cli.__version__
client.context.user.id = hash(getpass.getuser())

enable(instrumentation_key)
except Exception: #pylint: disable=broad-except
# Never fail the command because of telemetry
pass

def user_agrees_to_telemetry():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do a pivotal bug for this so that we can discuss and decide where this information should be persisted for the session. Perhaps a config.json like we have for Node CLI.

# TODO: agreement, needs to take Y/N from the command line
# and needs a "skip" param to not show (for scripts)
return True

def telemetry_log_event(name, properties=None, measurements=None):
def telemetry_flush():
try:
if Telemetry.client is None:
return
Telemetry.client.track_event(name, properties, measurements)
Telemetry.client.flush()
except Exception as e:
#pass
raise e

def telemetry_log_performance(name, properties=None):
telemetry_log_event("Perf: "+name, properties)
client.flush()
except Exception: #pylint: disable=broad-except
# Never fail the command because of telemetry
pass
4 changes: 0 additions & 4 deletions src/azure/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ._logging import configure_logging, logger
from ._session import Session
from ._output import OutputProducer
from ._telemetry import Telemetry, user_agrees_to_telemetry

# CONFIG provides external configuration options
CONFIG = Session()
Expand All @@ -19,9 +18,6 @@ def main(args, file=sys.stdout): #pylint: disable=redefined-builtin

configure_logging(args, CONFIG)

if user_agrees_to_telemetry():
Telemetry.init_telemetry()

from ._locale import install as locale_install
locale_install(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'locale',
Expand Down