Skip to content

Commit 3661ff1

Browse files
committed
added support to application insights
1 parent 29e53e0 commit 3661ff1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

app.py

+11
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@
66
import pyodbc
77
import socket
88
from threading import Lock
9+
from opencensus.ext.azure.trace_exporter import AzureExporter
10+
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
11+
from opencensus.trace.samplers import ProbabilitySampler
912

1013
# Initialize Flask
1114
app = Flask(__name__)
1215

16+
# Setup Azure Monitor
17+
middleware = FlaskMiddleware(
18+
app,
19+
exporter=AzureExporter(connection_string="InstrumentationKey={0}".format(os.environ['APPINSIGHTS_KEY'])),
20+
sampler=ProbabilitySampler(rate=1.0),
21+
)
22+
1323
# Setup Flask Restful framework
1424
api = Api(app)
1525
parser = reqparse.RequestParser()
1626
parser.add_argument('customer')
1727

28+
# Implement manual connection pooling
1829
class ConnectionManager(object):
1930
__instance = None
2031
__conn_index = 0

azure-deploy.sh

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ az appservice plan create \
3030
--sku B1 \
3131
--is-linux
3232

33+
echo "Creating Application Insight..."
34+
az resource create \
35+
-g $resourceGroup \
36+
-n $appName-ai \
37+
--resource-type "Microsoft.Insights/components" \
38+
--properties '{"Application_Type":"web"}'
39+
40+
echo "Reading Application Insight Key..."
41+
aikey=`az resource show -g $resourceGroup -n $appName-ai --resource-type "Microsoft.Insights/components" --query properties.InstrumentationKey -o tsv`
42+
3343
echo "Creating Web Application...";
3444
az webapp create \
3545
-g $resourceGroup \
@@ -45,3 +55,11 @@ az webapp config connection-string set \
4555
-n $appName \
4656
--settings WWIF="$SQLAZURECONNSTR_WWIF" \
4757
--connection-string-type=SQLAzure
58+
59+
echo "Configuring Application Insights...";
60+
az webapp config appsettings set \
61+
-g $resourceGroup \
62+
-n $appName \
63+
--settings APPINSIGHTS_KEY="$aikey"
64+
65+
echo "Done."

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pyodbc
22
flask
33
flask-restful
4-
applicationinsights
4+
opencensus-ext-azure

0 commit comments

Comments
 (0)