Skip to content

Rewrite as a proper sentry_sdk ZopeIntegration (2.0) - #42

Merged
jensens merged 13 commits into
masterfrom
zope-integration
Sep 22, 2026
Merged

jensens merged 13 commits into
masterfrom
zope-integration

Conversation

@jensens

@jensens jensens commented Sep 21, 2026

Copy link
Copy Markdown
Member

Rewrite of collective.sentry as a proper sentry_sdk integration, as proposed in the RFC.

Addresses #40

What changed

  • ZopeIntegration (integration.py): setup_once() wraps ZPublisher.WSGIPublisher.publish_module with a per-request isolation scope, attaches a lazy request-data event processor, sets the transaction name from the request path, and registers the IPubFailure capture handler programmatically — no ZCML required, so plain sentry_sdk.init(..., integrations=[ZopeIntegration()]) works on plain Zope.
  • before_send belongs to the deployer again. Request enrichment moved from the client-global before_send hook to scope event processors, so user-side filtering is a plain sentry_sdk.init option now.
  • Zero-config preserved (bootstrap.py): env-var bootstrap (SENTRY_DSN, SENTRY_ENVIRONMENT, SENTRY_PROJECT, SENTRY_DISABLE, SENTRY_INTEGRATIONS, SENTRY_MAX_LENGTH) that steps aside when the SDK is already initialized by the deployer.
  • plone.api dependency dropped — plain Zope 5 is supported; Plone specifics (PAS user email, portal error_log) are detected at runtime. The error_log ignored-exceptions check is preserved for both the Zope root and Plone portals (resolved by acquisition).
  • error_handler.py is a deprecated BBB shim: before_send and errorRaisedSubscriber stay importable (with DeprecationWarning); the ZCML is intentionally empty.
  • Defects from RFC: Rewrite as a proper sentry_sdk ZopeIntegration #40 fixed: the duplicated sentry_sdk.init() block from the 2022 merge is gone; SENTRY_INTEGRATIONS works again; SENTRY_MAX_LENGTH maps to max_value_length (only when explicitly set — sdk-2.x's utils.MAX_STRING_LENGTH no longer exists); SENTRY_OPTIONAL is deprecated (a missing DSN just disables reporting, codifying the de-facto behavior since 2022); a broken extraction can no longer drop an event (each section is isolated, failures leave an {"error": ...} marker).
  • Security improvement over 1.x: sensitive request headers (Authorization, Cookie, …) are masked as [Filtered] unless send_default_pii is enabled — 1.x shipped the entire WSGI environ into every event.

Compatibility notes (2.0.0)

  • Existing env-var deployments keep working unchanged.
  • Transaction names are now the request path — Sentry alert rules filtering on transaction may need review.
  • extra["request"]["headers"] now carries proper header names instead of the raw environ.
  • Code importing collective.sentry.error_handler keeps working for one major cycle (deprecated).
  • Version targets 2.0.0; the README has a "Migrating from 1.x" section.

Tests

Previously the package had no tests; the init path being untested is how the 2022 merge duplication went unnoticed.

  • 38 tests in the Plone 6.2 env: 34 unit + 4 functional (plone.app.testing layer publishing through the real WSGI pipeline into a capturing transport — asserts enrichment, error_log ignores, logging-path dedup, and scope isolation between requests).
  • New Plone-free tox -e zope env + CI workflow proving the package installs, imports and initializes without Plone.
  • Coverage 99% overall: integration.py, extraction.py, capture.py, error_handler.py at 100%, bootstrap.py at 98%.
  • tox -e lint (plone/meta pre-commit) green; towncrier news snippets included.

Draft for now — happy to split, squash or adjust to maintainer preference.

🤖 Generated with Claude Code

@jensens
jensens marked this pull request as ready for review September 21, 2026 13:18
@jensens
jensens requested a review from gforcada September 21, 2026 13:18

@gforcada gforcada left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Quite a lenghty work!

I refactored the commits a bit to merge fix commits with their original commit but code is 100% the same 😄

@jensens
jensens merged commit 8f4e39c into master Sep 22, 2026
7 checks passed
@jensens
jensens deleted the zope-integration branch September 22, 2026 15:13
@gforcada

Copy link
Copy Markdown
Member

I did release it as 2.0.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants