Merge pull request #2513 from jakedt/marketo
Add error logging to Marketo calls
This commit is contained in:
commit
75303677f4
4 changed files with 36 additions and 7 deletions
|
@ -35,6 +35,7 @@ from oauth.oidc import DiscoveryFailureException
|
|||
from util.useremails import (send_confirmation_email, send_recovery_email, send_change_email,
|
||||
send_password_changed, send_org_recovery_email)
|
||||
from util.names import parse_single_urn
|
||||
from util.saas.useranalytics import build_error_callback
|
||||
|
||||
|
||||
REPOS_PER_PAGE = 100
|
||||
|
@ -345,14 +346,20 @@ class User(ApiResource):
|
|||
code = model.user.create_confirm_email_code(user, new_email=new_email)
|
||||
send_change_email(user.username, user_data['email'], code.code)
|
||||
else:
|
||||
user_analytics.change_email(user.email, new_email)
|
||||
ua_future = user_analytics.change_email(user.email, new_email)
|
||||
ua_future.add_done_callback(build_error_callback('Change email failed'))
|
||||
model.user.update_email(user, new_email, auto_verify=not features.MAILING)
|
||||
|
||||
if 'given_name' in user_data or 'family_name' in user_data or 'company' in user_data:
|
||||
model.user.update_user_metadata(user, user_data.get('given_name'),
|
||||
user_data.get('family_name'), user_data.get('company'))
|
||||
user_analytics.change_metadata(user.email, user_data.get('given_name'),
|
||||
user_data.get('family_name'), user_data.get('company'))
|
||||
ua_mdata_future = user_analytics.change_metadata(
|
||||
user.email,
|
||||
user_data.get('given_name'),
|
||||
user_data.get('family_name'),
|
||||
user_data.get('company'),
|
||||
)
|
||||
ua_mdata_future.add_done_callback(build_error_callback('Change metadata failed'))
|
||||
|
||||
# Check for username rename. A username can be renamed if the feature is enabled OR the user
|
||||
# currently has a confirm_username prompt.
|
||||
|
@ -370,7 +377,9 @@ class User(ApiResource):
|
|||
raise request_error(message='Username is already in use')
|
||||
|
||||
user = model.user.change_username(user.id, new_username)
|
||||
user_analytics.change_username(user.email, new_username)
|
||||
username_future = user_analytics.change_username(user.email, new_username)
|
||||
username_future.add_done_callback(build_error_callback('Change username failed'))
|
||||
|
||||
elif confirm_username:
|
||||
model.user.remove_user_prompt(user, 'confirm_username')
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ from config import frontend_visible_config
|
|||
from external_libraries import get_external_javascript, get_external_css
|
||||
from util.names import parse_namespace_repository
|
||||
from util.secscan import PRIORITY_LEVELS
|
||||
from util.saas.useranalytics import build_error_callback
|
||||
from util.timedeltastring import convert_to_timedelta
|
||||
|
||||
|
||||
|
@ -122,8 +123,15 @@ def common_login(db_user, permanent_session=True):
|
|||
session.permanent_session_lifetime = convert_to_timedelta(session_timeout_str)
|
||||
|
||||
# Inform our user analytics that we have a new "lead"
|
||||
user_analytics.create_lead(db_user.email, db_user.username, db_user.given_name,
|
||||
db_user.family_name, db_user.company)
|
||||
create_lead_future = user_analytics.create_lead(
|
||||
db_user.email,
|
||||
db_user.username,
|
||||
db_user.given_name,
|
||||
db_user.family_name,
|
||||
db_user.company,
|
||||
)
|
||||
create_lead_future.add_done_callback(build_error_callback('Create lead failed'))
|
||||
|
||||
return True
|
||||
else:
|
||||
logger.debug('User could not be logged in, inactive?.')
|
||||
|
|
|
@ -34,6 +34,7 @@ from health.healthcheck import get_healthchecker
|
|||
from util.cache import no_cache
|
||||
from util.headers import parse_basic_auth
|
||||
from util.invoice import renderInvoiceToPdf
|
||||
from util.saas.useranalytics import build_error_callback
|
||||
from util.systemlogs import build_logs_archive
|
||||
from util.useremails import send_email_changed
|
||||
|
||||
|
@ -407,7 +408,8 @@ def confirm_email():
|
|||
|
||||
if new_email:
|
||||
send_email_changed(user.username, old_email, new_email)
|
||||
user_analytics.change_email(old_email, new_email)
|
||||
change_email_future = user_analytics.change_email(old_email, new_email)
|
||||
change_email_future.add_done_callback(build_error_callback('Change email failed'))
|
||||
|
||||
common_login(user)
|
||||
if model.user.has_user_prompts(user):
|
||||
|
|
|
@ -14,6 +14,16 @@ class LeadNotFoundException(Exception):
|
|||
pass
|
||||
|
||||
|
||||
def build_error_callback(message_when_exception):
|
||||
def maybe_log_error(response_future):
|
||||
try:
|
||||
response_future.result()
|
||||
except Exception:
|
||||
logger.exception('User analytics: %s', message_when_exception)
|
||||
|
||||
return maybe_log_error
|
||||
|
||||
|
||||
class _MarketoAnalyticsClient(object):
|
||||
""" User analytics implementation which will report user changes to the
|
||||
Marketo API.
|
||||
|
|
Reference in a new issue