Skip to content

Commit c34af00

Browse files
authored
Improve sample logging (#2692)
1 parent cfcb713 commit c34af00

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

python/samples/getting_started/middleware/runtime_context_delegation.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ async def inject_context_middleware(
6969
# Log what we captured (for demonstration)
7070
if self.api_token or self.user_id:
7171
print("[Middleware] Captured runtime context:")
72-
print(f" - API Token: {'***' + self.api_token[-4:] if self.api_token else 'None'}")
73-
print(f" - User ID: {self.user_id}")
74-
print(f" - Session Metadata: {self.session_metadata}")
72+
print(f" - API Token: {'[PRESENT]' if self.api_token else '[NOT PROVIDED]'}")
73+
print(f" - User ID: {'[PRESENT]' if self.user_id else '[NOT PROVIDED]'}")
74+
print(f" - Session Metadata Keys: {list(self.session_metadata.keys())}")
7575

7676
# Continue to tool execution
7777
await next(context)
@@ -98,11 +98,11 @@ async def send_email(
9898
tenant = runtime_context.session_metadata.get("tenant", "unknown")
9999

100100
print("\n[send_email] Executing with runtime context:")
101-
print(f" - Token: {'***' + token[-4:] if token else 'NOT PROVIDED'}")
102-
print(f" - User ID: {user_id or 'NOT PROVIDED'}")
103-
print(f" - Tenant: {tenant}")
104-
print(f" - To: {to}")
105-
print(f" - Subject: {subject}")
101+
print(f" - Token: {'[PRESENT]' if token else '[NOT PROVIDED]'}")
102+
print(f" - User ID: {'[PRESENT]' if user_id else '[NOT PROVIDED]'}")
103+
print(f" - Tenant: {'[PRESENT]' if tenant and tenant != 'unknown' else '[NOT PROVIDED]'}")
104+
print(" - Recipient count: 1")
105+
print(f" - Subject length: {len(subject)} chars")
106106

107107
# Simulate API call with authentication
108108
if not token:
@@ -125,9 +125,9 @@ async def send_notification(
125125
user_id = runtime_context.user_id
126126

127127
print("\n[send_notification] Executing with runtime context:")
128-
print(f" - Token: {'***' + token[-4:] if token else 'NOT PROVIDED'}")
129-
print(f" - User ID: {user_id or 'NOT PROVIDED'}")
130-
print(f" - Message: {message}")
128+
print(f" - Token: {'[PRESENT]' if token else '[NOT PROVIDED]'}")
129+
print(f" - User ID: {'[PRESENT]' if user_id else '[NOT PROVIDED]'}")
130+
print(f" - Message length: {len(message)} chars")
131131
print(f" - Priority: {priority}")
132132

133133
if not token:
@@ -339,10 +339,10 @@ async def sms_kwargs_tracker(
339339
tenant_id="tenant-acme",
340340
)
341341

342-
print(f"\n[Verification] EmailAgent received: {email_agent_kwargs}")
343-
print(f" - api_token: {email_agent_kwargs.get('api_token')}")
344-
print(f" - user_id: {email_agent_kwargs.get('user_id')}")
345-
print(f" - tenant_id: {email_agent_kwargs.get('tenant_id')}")
342+
print(f"\n[Verification] EmailAgent received kwargs keys: {list(email_agent_kwargs.keys())}")
343+
print(f" - api_token: {'[PRESENT]' if email_agent_kwargs.get('api_token') else '[NOT PROVIDED]'}")
344+
print(f" - user_id: {'[PRESENT]' if email_agent_kwargs.get('user_id') else '[NOT PROVIDED]'}")
345+
print(f" - tenant_id: {'[PRESENT]' if email_agent_kwargs.get('tenant_id') else '[NOT PROVIDED]'}")
346346

347347
print("\n✓ Pattern 2 complete - kwargs automatically propagate through as_tool()")
348348

@@ -366,13 +366,13 @@ async def validate_and_track(
366366
if api_token:
367367
# Simulate token validation
368368
if api_token.startswith("valid-"):
369-
print(f"[AuthMiddleware] Token validated: ***{api_token[-4:]}")
369+
print("[AuthMiddleware] Token validated successfully")
370370
self.validated_tokens.append(api_token)
371371
else:
372-
print(f"[AuthMiddleware] ✗ Invalid token: {api_token}")
372+
print("[AuthMiddleware] Token validation failed")
373373
# Could set context.terminate = True to block execution
374374
else:
375-
print("[AuthMiddleware] No API token provided")
375+
print("[AuthMiddleware] No API token provided")
376376

377377
await next(context)
378378

0 commit comments

Comments
 (0)