feat: inject logger and tracer into worker context#98
Open
marnickvda wants to merge 2 commits into
Open
Conversation
Workers received the bare server context, so fctx.Logger and fctx.Tracer fell back to their no-op implementations and background process logs and spans were silently dropped. Mirror the HTTP path (fctx.Middleware) by attaching the server's logger and tracer to the worker context before running each worker.
AdrianCio
reviewed
Jun 22, 2026
| // that one worker cannot crash the process or affect the others. | ||
| func (s *server) runWorker(ctx context.Context, w Worker) { | ||
| ctx = fctx.WithLogger(ctx, s.Logger) | ||
| if s.Tracer != nil { |
Collaborator
There was a problem hiding this comment.
I'd remove the if, and just overwrite whatever's there, just to avoid cases where it might get initialized with something blank (non-nil) and you don't get your own trace injected correctly.
I don't think there's a case where we don't want our tracer to be injected 🤔
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
inject logger and tracer into worker context
Description
Background workers were started with the bare server context, while HTTP handlers get the server's logger and tracer attached per-request via
fctx.Middleware. As a result, any worker callingfctx.Logger(ctx)orfctx.Tracer(ctx)silently fell back to the no-op logger/tracer, so worker logs and spans were dropped.runWorkernow mirrors the HTTP path: it attaches the server's logger (and tracer, when configured) to the worker context before invoking the worker, so background processes get the same observability as request handlers.Types of Changes
Tasks
s.Loggerinto the worker context inrunWorkers.Tracerinto the worker context when configuredReview
TestRunWorkerInjectsLogger(observer-backed, asserts the worker log is captured rather than dropped) andTestRunWorkerInjectsTracer(asserts the worker sees the configured tracer, not the no-op fallback);go test ./...passesDeployment Notes
None.