Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 3 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<Compile Include="azure\cli\_util.py" />
<Compile Include="azure\cli\__init__.py" />
<Compile Include="azure\cli\__main__.py" />
<Compile Include="azure\cli\_telemetry.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\__init__.py" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mock==1.3.0
pylint==1.5.4
six==1.10.0
vcrpy==1.7.4
applicationinsights==0.10.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor nit: Move up as looks like all packages are in alphabetical order

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()
34 changes: 34 additions & 0 deletions src/azure/cli/_telemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import getpass
from applicationinsights import TelemetryClient
from applicationinsights.exceptions import enable
import azure.cli as cli

client = {}

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

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

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
Copy Markdown
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_flush():
try:
client.flush()
except Exception: #pylint: disable=broad-except
# Never fail the command because of telemetry
pass