You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-11Lines changed: 18 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,22 +128,29 @@ We need to improve this:
128
128
129
129
Within your resource group create a new Application Insights resource.
130
130
131
-
Find the connection string (containing a sensitive "instrumentation key") on the overview page of your Application Insights resource. Rather than hardcoding the connection string in the Python code, configure it securely by using an environment variable called `APPLICATIONINSIGHTS_CONNECTION_STRING`. Set this on the 'Configuration' page of the App Service.
131
+
Find the connection string (containing a sensitive "instrumentation key") on the overview page of your Application Insights resource. Rather than hardcoding the connection string in the Python code, configure it securely by using an environment variable called `APPLICATIONINSIGHTS_CONNECTION_STRING`. Set this on the 'Environment Variables' page of the App Service.
132
132
133
-
> Don't forget to click the `Save` button at the top of the Configuration page after making changes!
133
+
> Don't forget to click the `Apply` button at the bottom of the Environment Variables page after making changes!
134
134
135
-
To actually send logs to Application Insights you'll need to add the Python packages `opencensus-ext-azure` and `opencensus-ext-flask` to requirements.txt.
136
-
It's a good habit to specify a version when adding these: you can find the latest version specified on the Python Package Index page for [the Azure extension](https://pypi.org/project/opencensus-ext-azure/) and [the Flask extension](https://pypi.org/project/opencensus-ext-flask/) respectively.
135
+
To actually send logs to Application Insights you'll need to add the Python packages `azure-monitor-opentelemetry` to requirements.txt.
136
+
It's a good habit to specify a version when adding these: you can find the latest version specified on the Python Package Index page for [the Azure extension](https://pypi.org/project/azure-monitor-opentelemetry/).
137
137
138
-
Next, add the middleware to`app.py` by adapting this sample code: <https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python-request#tracking-flask-applications>. That middleware will log all requests to your Flask app (like every time you view the webpage) and the `AzureExporter` will send those logs to Application Insights.
138
+
Next, we configure the logging in`app.py` by adapting this sample code: <https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/http_flask.py>. This will log all requests to your Flask app (like every time you view the webpage) and the in-built exporter will send those logs to Application Insights.
139
139
140
-
> The environment variable gets picked up automatically so your code doesn't need to pass anything into `AzureExporter()`. Just make sure the application setting in Azure is the whole connection string, including `InstrumentationKey=`!
140
+
> The environment variable gets picked up automatically so your code doesn't need to pass anything into `configure_azure_monitor()` call. Just make sure the application setting in Azure is the whole connection string, including `InstrumentationKey=`!
141
141
142
-
Finally, to send `logger.info` messages there too, register a "log handler". Import `AzureLogHandler` from `opencensus.ext.azure.log_exporter`, then add it as a handler for our Flask app logs:
143
-
144
-
```python
145
-
app.logger.addHandler(AzureLogHandler())
146
-
```
142
+
> Note that the auto-configuration relies on a strict ordering and flask needs to be _imported_ after we have run the configuration - so you may have code like:
0 commit comments