Skip to main content

juniper-observability

PyPI Python 3.12+ License: MIT

Shared observability primitives for the Juniper platform — health models, structured logging, middleware, and crash-safe Prometheus collector registration.

juniper-observability is the single place every Juniper service gets its cross-cutting observability wiring, so each service doesn't re-implement it: Pydantic health-response models for the /v1/health/ready endpoint, structured-JSON logging with request_id propagation, the Starlette RequestIdMiddleware and PrometheusMiddleware, idempotent prometheus_client collector helpers, the matching pytest reset fixture, and Sentry initialisation.

The collector helpers are the headline. Registering a Counter / Gauge / Histogram / … twice — across a module reload or a pytest-fixture reset — normally raises Duplicated timeseries in CollectorRegistry. register_or_reuse adopts the existing collector instead, so registration is safe to repeat.

Part of the Juniper platform. juniper-observability is the shared observability layer of Juniper — a multi-package ML research platform built around constructive (Cascade-Correlation) and recurrent neural networks. It's a small infrastructure library; you don't need the rest of the platform to use it.

Install

pip install juniper-observability                 # core
pip install "juniper-observability[prometheus]"   # + Prometheus middleware/utilities
pip install "juniper-observability[sentry]"       # + Sentry init
pip install "juniper-observability[all]"          # everything

It is also pulled in by the meta-package's juniper-ml[tools] and juniper-ml[all] extras.

Quick start

from prometheus_client import CollectorRegistry, Counter
from juniper_observability import register_or_reuse

registry = CollectorRegistry()
c1 = register_or_reuse(Counter, "demo_total", "demo counter", registry=registry)
c2 = register_or_reuse(Counter, "demo_total", "demo counter", registry=registry)
assert c1 is c2   # the second call adopts the existing collector — no exception

For tests that touch collector state, use the canonical reset fixture:

from juniper_observability.testing import reset_prometheus_registry  # pytest fixture

What's in the box

Surface What it gives you
register_or_reuse / register_fresh / register_info_or_update / lazy_register_or_reuse Idempotent prometheus_client collector registration (adopt-existing is the default).
testing.reset_prometheus_registry Pytest fixture that resets collector state between tests.
RequestIdMiddleware, PrometheusMiddleware Starlette middlewares applied across the service fleet.
Health-response models Pydantic models for the /v1/health/ready endpoint.
Structured-JSON logging Logging configuration with request_id propagation.
Sentry init configure_sentry passes include_local_variables=False (no switch to turn locals back on) and the SEC-10 before_send hook always runs. The hook also deletes frame vars.

configure_sentry never captures frame locals. Sentry's EventScrubber redacts locals by name, and the local that held the configured API key during the comparison in the juniper-canopy#683 finding is not on that list. The before_send hook deletes vars as well, because the opt-in PureEvalIntegration (sentry-sdk 2.58.0) writes them without consulting include_local_variables. Releases up to and including 0.4.0 use the SDK default (True). There is no parameter to turn locals back on.

Operator notes: juniper-ml REFERENCE.

Per-service metrics stay in each repo. This package exposes only cross-cutting infrastructure; service-specific metric definitions (training-loop counters, dataset-gen histograms, websocket gauges) live in their owning repo and register via register_or_reuse against prometheus_client.REGISTRY.

Consumers

The service repos — juniper-data, juniper-cascor, juniper-canopy — import the middlewares, health models, and collector helpers (pin >=0.2.0). The client libraries (juniper-data-client, juniper-cascor-client) pull it in via their [observability] extra for X-Request-ID propagation and Prometheus counters.

Status

Live on PyPI, published independently of the meta-package on juniper-observability-v* tags. The current version is shown by the badge above; see CHANGELOG.md. Consumers should pin juniper-observability>=0.4.2, the security patch in which configure_sentry also scrubs Sentry transactions, parsed cookies and four more credential headers; 0.4.1 stopped it sending frame-local variables.

Compatibility policy — pinning, not deprecation cycles

This package ships no deprecation machinery: no DeprecationWarning, no PendingDeprecationWarning, no legacy aliases. That is deliberate, not an oversight (defect-register APD-ECO-007).

While pre-1.0, compatibility is managed by external pinning — consumers pin a floor and a ceiling, so each 0.x is a compatibility boundary and a breaking change is absorbed by a ceiling raise the consumer performs deliberately. That holds while the consumer set is a known, enumerable handful of first-party repositories.

What would change this: a third-party dependant, or 1.0 — at which point the consumer set stops being enumerable and a census stops being a sufficient substitute for a deprecation cycle. When that happens, reuse the implementations this ecosystem already has rather than writing a third: juniper_config_tools.env_with_legacy_alias for env-var renames, and the juniper-data-client alias pattern (a DeprecationWarning with a correct stacklevel and a dated removal window) for API renames. Re-derivation is exactly how the env-var lookup drifted across three services before it was consolidated.

Design

Part of the Juniper ML research platform. Rationale and history:

License

MIT — see LICENSE.

Metadata

Release files for juniper-observability 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for juniper-observability 0.4.2
File Size Uploaded Provenance Actions
juniper_observability-0.4.2.tar.gz 53.1 kB With provenance Details for juniper_observability-0.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for juniper-observability 0.4.2
File Interpreter ABI Platform Actions
juniper_observability-0.4.2-py3-none-any.whl Python 3 none any Details for juniper_observability-0.4.2-py3-none-any.whl

Total release size: 84.1 kB

Release files / juniper_observability-0.4.2.tar.gz

Download URL juniper_observability-0.4.2.tar.gz
Size 53.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6de7dc717e848b3f1d4e2a33e95d8a41804c12cfa411ac22e602358f83e10b02
BLAKE2b-256 checksum
How to use checksums
50fc97ca1649dfddf0c0b9e5644ad0f5f0e138660467eab2e384efa0b6b80a91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / juniper_observability-0.4.2-py3-none-any.whl

Download URL juniper_observability-0.4.2-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a4788a9e58b6ce30a51efa563c6a2c5db2b4915cccae768e16c9a807ff61cfa
BLAKE2b-256 checksum
How to use checksums
79296093c25408c81fd340694b5d16d4fa3371324b30784bbd00402d6d41cf95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for juniper-observability 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for juniper_observability-0.4.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page