Skip to content

Commit

Permalink
more logging tweaks for tasks
Browse files Browse the repository at this point in the history
only log task creations and runs if traceparent header isn't set

for #1149
  • Loading branch information
snarfed committed Dec 3, 2024
1 parent 778e1c7 commit 65feae0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def create_task(queue, delay=None, **params):
# return app.view_functions[endpoint](**args)

body = urllib.parse.urlencode(sorted(params.items())).encode()
traceparent = request.headers.get('traceparent', '')
task = {
'app_engine_http_request': {
'http_method': 'POST',
Expand All @@ -359,7 +360,7 @@ def create_task(queue, delay=None, **params):
# propagate trace id
# https://cloud.google.com/trace/docs/trace-context#http-requests
# https://stackoverflow.com/a/71343735/186123
'traceparent': request.headers.get('traceparent', ''),
'traceparent': traceparent,
},
},
}
Expand All @@ -369,7 +370,8 @@ def create_task(queue, delay=None, **params):

parent = tasks_client.queue_path(appengine_info.APP_ID, TASKS_LOCATION, queue)
task = tasks_client.create_task(parent=parent, task=task)
msg = f'Added {queue} {task.name.split("/")[-1]}'
if not traceparent:
msg = f'Added {queue} {task.name.split("/")[-1]}'
logger.info(msg)
return msg, 202

Expand Down
4 changes: 2 additions & 2 deletions protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ def check_supported(cls, obj):
error(f"Bridgy Fed doesn't support DMs", status=204)


@cloud_tasks_only()
@cloud_tasks_only(log=None)
def receive_task():
"""Task handler for a newly received :class:`models.Object`.
Expand Down Expand Up @@ -1717,7 +1717,7 @@ def receive_task():
error(e, status=304)


@cloud_tasks_only()
@cloud_tasks_only(log=None)
def send_task():
"""Task handler for sending an activity to a single specific destination.
Expand Down
4 changes: 2 additions & 2 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def poll_feed(user, feed_url, rel_type):


@app.post(f'/queue/poll-feed')
@cloud_tasks_only(log=False)
@cloud_tasks_only(log=None)
def poll_feed_task():
"""Task handler for polling a :class:`Web` user's feed.
Expand Down Expand Up @@ -935,7 +935,7 @@ def clamp(delay):


@app.post('/queue/webmention')
@cloud_tasks_only()
@cloud_tasks_only(log=None)
def webmention_task():
"""Handles inbound webmention task.
Expand Down

0 comments on commit 65feae0

Please sign in to comment.