Skip to content

Instantly share code, notes, and snippets.

@rchardptrsn
Last active November 27, 2020 21:23
Show Gist options
  • Save rchardptrsn/8d16166744f2e17e08fa44845068ad51 to your computer and use it in GitHub Desktop.
Save rchardptrsn/8d16166744f2e17e08fa44845068ad51 to your computer and use it in GitHub Desktop.
# 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