Commit 546e8436 authored by Marcel Amirault's avatar Marcel Amirault

Merge branch 'rw/add-docs-worker-metadata' into 'master'

Adds docs for worker metadata logging

See merge request gitlab-org/gitlab!51613
parents 5cdc8c1b ceabe1e2
...@@ -299,6 +299,28 @@ through web requests. See the ...@@ -299,6 +299,28 @@ through web requests. See the
[follow-up work](https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/68) [follow-up work](https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/68)
for more information. for more information.
### Logging context metadata (through workers)
Additional metadata can be attached to a worker through the use of the [`ApplicationWorker#log_extra_metadata_on_done`](https://gitlab.com/gitlab-org/gitlab/-/blob/16ecc33341a3f6b6bebdf78d863c5bce76b040d3/app/workers/concerns/application_worker.rb#L31-34)
method. Using this method adds metadata that is later logged to Kibana with the done job payload.
```ruby
class MyExampleWorker
include ApplicationWorker
def perform(*args)
# Worker performs work
# ...
# The contents of value will appear in Kibana under `json.extra.my_example_worker.my_key`
log_extra_metadata_on_done(:my_key, value)
end
end
```
Please see [this example](https://gitlab.com/gitlab-org/gitlab/-/blob/16ecc33341a3f6b6bebdf78d863c5bce76b040d3/app/workers/ci/pipeline_artifacts/expire_artifacts_worker.rb#L20-21)
which logs a count of how many artifacts are destroyed per run of the `ExpireArtifactsWorker`.
## Exception Handling ## Exception Handling
It often happens that you catch the exception and want to track it. It often happens that you catch the exception and want to track it.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment