Skip to content

Fix API client_id logging on error

Sean McGivern requested to merge fix-api-client-id-logging-on-error into master

What does this MR do and why?

Gitlab::ApplicationContext has a bit of a sharp edge: client_id will not be correctly computed unless remote_ip and user are both set or both missing in the innermost context.

In the case here, with an API error, we'd try to set user but not remote_ip. This would give a correct client_id when the request was authenticated, but when it was anonymous we would get a client_id of 'ip/', even though the remote_ip was set in an outer context.

Examples: https://log.gprd.gitlab.net/goto/32741b4cb5f997fa2680dc42b69f935c

We can reproduce that case by sending an error tracking payload where stacktrace is an array, not an object, but I'm using a simpler reproduction case in the specs.

Merge request reports