Last active
November 27, 2020 21:23
-
-
Save rchardptrsn/8d16166744f2e17e08fa44845068ad51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Write connection attempts to App Insights | |
| # https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python | |
| def writeAppInsights(logger,address,data): | |
| # create the custom_dimensions dictionary | |
| logData = {'custom_dimensions': { | |
| 'Time': time.ctime(), | |
| 'IP': address[0], | |
| 'Port': address[1], | |
| 'City': data.city, | |
| 'Country': data.country, | |
| 'CountryName': data.country_name, | |
| 'Location': data.loc, | |
| 'Region': data.region, | |
| 'Timezone': data.timezone, | |
| 'Details': json.dumps(data.all) | |
| } | |
| } | |
| # pass your custom dimensions to extra | |
| # send data to app insights as an action | |
| logger.warning('action',extra=logData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment