GitLab Shell Context Passing and Correlation ID improvements
Spun out of !400 (comment 388822674)
At present, GitLab Shell does not yet pass context through the application.
This means that correlationIds are generated down the call stack, since we don't pass the context around from the start execution.
This has several potential downsides:
- Its easier for programming mistakes to be made in future which lead to multiple correlationIDs being generated for a single request.
- CorrelationIds cannot be passed in from upstream requests
- Other advantages of context passing, such as distributed tracing is not possible.
Proposal
Update the Execute()
method on the Command
interface to pass a ctx
in, as follows:
type Command interface {
Execute(ctx context.Context) error
}
ctx
should be generated from a labkit call to tracing.ExtractFromEnv(context.Background())
:
ctx, finished := tracing.ExtractFromEnv(context.Background())
defer finished()
Note that at present tracing.ExtractFromEnv
will only include a correlationId if one exists. I think we should change this behaviour in labkit to generate a correlationId if one does not exist.
This change will have the following advantages:
- Less likelihood of future changes leading to multiple correlation ids being generated in a single gitlab-shell execution
- Distributed Tracing support in GitLab Shell
- Passing correlationIds from upstream application calls (when applicable), provided the upstream application invokes GitLab Shell with the appropriate environment variables