Skip to content

Commit

Permalink
Merge pull request #33 from BurtBiel/telemetry/EnableAppInsights
Browse files Browse the repository at this point in the history
Telemetry/enable app insights [Finished #114911063]
  • Loading branch information
mayurid committed Mar 11, 2016
2 parents 6ec0c20 + fb0549c commit 766e150
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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
@@ -1,3 +1,4 @@
applicationinsights==0.10.0
azure==2.0.0rc1
mock==1.3.0
pylint==1.5.4
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()
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():
# 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

0 comments on commit 766e150

Please sign in to comment.