Skip to content

oncetask: inject taskType into log records via ContextHandler - #21

Merged
anish749 merged 1 commit into
mainfrom
oncetask/log-task-type
May 17, 2026
Merged

oncetask: inject taskType into log records via ContextHandler#21
anish749 merged 1 commit into
mainfrom
oncetask/log-task-type

Conversation

@anish749

Copy link
Copy Markdown
Owner

Problem

ContextHandler (oncetask/context_logger.go) currently auto-injects taskId and resourceKey from context but not taskType. When debugging across Cloud Logging, knowing the task kind is at least as useful as the task ID — it answers "what queue is this?" at a glance, lets you filter to a single handler's logs, and disambiguates errors when many task types share a resource key.

Solution

  • Add a third context key, taskTypeContextKey, and have ContextHandler.Handle add taskType to every log record whose context carries it.
  • Extend withTaskContext to take taskType string (unexported helper — small ripple). The two batch wrappers (withSingleTaskContext, withResourceKeyTaskContext) pass string(tasks[0].Type). All tasks in a resource-batch share the same Type, so a single value is correct for the batch.
  • Update the one direct call site in once_task_firestore.go (cancellation loop).
  • Update existing tests for the new signature; add TestContextHandler_InjectsTaskType for coverage.

taskType is structurally required on every task (it routes to the registered handler and keys the consumer loop), so it is always set unconditionally in withTaskContext — no empty-check needed.

Context

Follows on from #20. With handler errors now logged from SafeExecute using the per-task context, adding taskType to the auto-injected attributes makes those error records (and any handler-emitted logs) self-describing in Cloud Logging.

@anish749
anish749 merged commit 4afec9c into main May 17, 2026
4 checks passed
@anish749
anish749 deleted the oncetask/log-task-type branch May 17, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant