Skip to content

ref(gitlab): Namespace webhook log attributes and add malformed-token context#117959

Merged
billyvg merged 4 commits into
masterfrom
billyvg/ref/gitlab-webhook-log-attributes
Jun 17, 2026
Merged

ref(gitlab): Namespace webhook log attributes and add malformed-token context#117959
billyvg merged 4 commits into
masterfrom
billyvg/ref/gitlab-webhook-log-attributes

Conversation

@billyvg

@billyvg billyvg commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

GitLab webhook failure logs were hard to debug in the Logs explorer. Two concrete problems:

  1. org_ids wasn't queryable. It was logged as a list[int], which the SDK serializes as an EAP array-typed attribute. The logs attribute-discovery endpoint only enumerates string/number/boolean types (POSSIBLE_ATTRIBUTE_TYPES), so array attributes never surface as a selectable/filterable column.
  2. The malformed-token path had no source identifier. org_ids is only added after the integration is resolved — but a malformed HTTP_X_GITLAB_TOKEN can't be parsed to resolve the integration/org in the first place, so those logs carried nothing identifying the sender.

Changes

  • org_ids → comma-joined string so it's a filterable Logs column.
  • Namespace every dispatch-path log attribute under webhook.user_agent, event_type, reason, integration.{metadata,id,status}, org_ids, repo.*, user.username. Dotted keys render as one grouped tree in the explorer (the UI splits attribute keys on .), cleanly separated from the SDK's code.*/thread.* attributes, while each leaf stays individually queryable (e.g. webhook.repo.path:"group/repo").
  • Malformed-token context: best-effort parse the request body — which is independent of the token — to attach the source repo/owner (webhook.repo.path/namespace/web_url/project_id), webhook.object_kind, and webhook.user.username. Fully defensive: bad/non-JSON body → no extra keys, never breaks the response.

No behavior change to webhook responses (status codes and reason phrases are byte-identical).

Test Plan

  • Extended test_invalid_token to assert the malformed-token log carries the body-derived webhook.repo.* / webhook.object_kind attributes.
  • pytest tests/sentry/integrations/gitlab/test_webhook.py — 31 passed.
  • ruff + pre-commit hooks pass.

Note: the new webhook.* attributes apply to freshly-ingested logs going forward, not retroactively.

… context

GitLab webhook failure logs were hard to debug in the Logs explorer: org_ids
was logged as a list, which serializes as an EAP "array" attribute that the
explorer won't surface as a queryable column (the attribute discovery endpoint
only enumerates string/number/boolean types). The malformed-token path also had
no way to identify the source, since a malformed token can't resolve the
integration or org.

Join org_ids into a comma-separated string so it's a filterable column, and
namespace every dispatch-path log attribute under a single "webhook." prefix
(user_agent, event_type, reason, integration.*, org_ids, repo.*) so they render
as one grouped tree alongside the SDK's code.*/thread.* attributes.

For the malformed-token case, best-effort parse the request body — which is
independent of the token — to attach the source repo/owner (path_with_namespace,
namespace, web_url, project_id) plus object_kind and user. No behavior change to
webhook responses.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 17, 2026
Comment thread src/sentry/integrations/gitlab/webhooks.py Outdated
"id": integration.id, # This is useful to query via Redash
"status": integration.status, # 0 seems to be active
},
"org_ids": [install.organization_id for install in installs],

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not supported

Comment on lines -671 to -678
"integration": {
# The metadata could be useful to debug
# domain_name -> gitlab.com/getsentry-ecosystem/foo'
# scopes -> ['api']
"metadata": integration.metadata,
"id": integration.id, # This is useful to query via Redash
"status": integration.status, # 0 seems to be active
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to flatten this

@billyvg billyvg marked this pull request as ready for review June 17, 2026 22:32
@billyvg billyvg requested a review from a team as a code owner June 17, 2026 22:32
@billyvg billyvg merged commit 8307e1c into master Jun 17, 2026
64 checks passed
@billyvg billyvg deleted the billyvg/ref/gitlab-webhook-log-attributes branch June 17, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants