Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def send_telemetry():
"""
Send telemetry to the provided instrumentation key. This does not includes a check to
previously unsent telemetry for offline work.
We don't want to keep retrying if this keeps failing.
Increment the telemetry send retry counter in the state file before each attempt.
Successful telemetry send will reset the counter.
After the TELEMETRY_RETRY_MAX count, only try sending telemetry every TELEMETRY_RETRY_INTERVAL
:return: None
"""
# Mark the start of a telemetry send attempt
attempt_number = increment_telemetry_send_retry_count()
# Do not try sending telemetry if we exceed the retry count, and if we are not at the send
# interval
if attempt_number > TELEMETRY_RETRY_MAX:
if ((attempt_number - TELEMETRY_RETRY_MAX) % TELEMETRY_RETRY_INTERVAL) != 0:
# Don't bother sending telemetry
logger.info('Not sending telemetry due to too many failed attempts.')
return
logger.info('Sending telemetry because retry interval is met.')
# Get the path of where this file (telemetry.py) is.
current_file_location = \
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
# This is the absolute path.
send_telemetry_background_path = \