diff --git a/ai_web_common/flask_sso/ext.py b/ai_web_common/flask_sso/ext.py index db3d16ecd1cc97b890d20c68e320f65d4e6a464c..2071ac229761ff881556a1a281a6d75113553083 100644 --- a/ai_web_common/flask_sso/ext.py +++ b/ai_web_common/flask_sso/ext.py @@ -13,6 +13,8 @@ from flask import request, session, redirect, make_response, g, \ render_template, abort, current_app from flask_talisman import ALLOW_FROM +from opentelemetry import trace + def init_sso(app, talisman): if 'SSO_LOGIN_SERVER' not in app.config: @@ -142,6 +144,12 @@ def auth_required(unauth_action=_redirect_to_login_server): else: current_app.logger.error('authentication failed: %s', e) return unauth_action() + + # Add authentication info to the current trace, if any. + current_span = trace.get_current_span() + if current_span: + current_span.set_attribute('auth.user', g.current_user) + return func(*args, **kwargs) return _auth_wrapper return _auth_required_decorator