bfocus-monitor
Monitoramento de erros do bFocus para Python: os erros não tratados do seu sistema chegam ao bFocus, são agrupados entre todos os clientes e viram demanda para a equipe.
Zero dependências (só biblioteca padrão) · Python 3.9+ · envio em segundo plano · nunca derruba o app.
Instalar
pip install bfocus-monitor
Ligar (uma linha)
import os
import bfocus_monitor
bfocus_monitor.init(key="bf_mon_…", release="1.4.2", environment="production",
signing_secret=os.environ.get("BFOCUS_SIGNING_SECRET"))
A chave do agente está no bFocus em Monitoramento → Agentes. O init não espera a rede: o sinal
de vida (o painel mostra o agente vivo mesmo sem erro) sai numa thread em segundo plano, no init e
a cada 5 min. Ele liga a captura de:
- exceção não tratada no topo (
sys.excepthook, nívelfatal) — o Python continua quebrando e imprimindo o traceback como sempre; - exceção que mata uma thread (
threading.excepthook); - exceção que o loop do asyncio só registraria (quando o
initroda dentro do loop; fora dele usebfocus_monitor.install_asyncio_handler(loop)); - no encerramento do processo, envia o que ficou na fila (até 2 s).
Opções: base_url, sample_rate (0..1), ignore (textos ou re.Pattern), before_send
(recebe o evento e devolve o evento alterado ou None para descartar), auto_capture=False (sem
ganchos globais) e in_app_prefixes (módulos seus mesmo instalados em site-packages).
Framework
FastAPI / Starlette (qualquer app ASGI):
from bfocus_monitor.asgi import BfocusMiddleware
app.add_middleware(BfocusMiddleware)
Django:
MIDDLEWARE = [..., "bfocus_monitor.django.BfocusMiddleware"]
Flask:
from bfocus_monitor.flask import init_app
init_app(app)
As integrações abrem um escopo por requisição (dois usuários simultâneos nunca trocam de identidade),
registram a rota (transaction) e a URL sem query string, capturam a exceção e deixam o
framework responder como sempre.
Quem foi afetado (identidade)
bfocus_monitor.set_user(external_id=user.id, customer_external_id=user.company_id)
Com signing_secret no init (o segredo da chave de assinatura do sistema, o mesmo do userHash
do widget) o pacote assina a identidade sozinho. Sem ele, passe o user_hash que o seu servidor já
gera: set_user(user.id, user.company_id, user_hash=...). Sem assinatura válida o erro conta como
"não identificado". bfocus_monitor.sign_user(secret, user_id, customer_id) gera o mesmo hash para
entregar ao front.
Manual
try:
emitir_nota()
except Exception as exc:
bfocus_monitor.capture_exception(exc, tags={"modulo": "fiscal"})
# ou, dentro do except: bfocus_monitor.capture_exception()
bfocus_monitor.capture_message("estoque negativo", level="warning")
bfocus_monitor.set_tag("filial", "POA")
bfocus_monitor.add_breadcrumb("fiscal", "XML assinado", "info")
bfocus_monitor.flush(timeout=2.0) # CLI, serverless, fim de job
O que é enviado
Tipo e mensagem da exceção (encadeadas: vai a causa raiz, com (dentro de: …)), os frames (de fora
para dentro, caminho relativo ao diretório atual, inApp falso para biblioteca), release, ambiente,
rota, URL sem query, identidade, tags, passos e versão do Python/SO. Nunca: corpo de requisição,
cookies, headers. O mesmo erro sai no máximo 1 vez a cada 30 s, e no máximo 100 eventos por minuto.
Testes
python -m unittest discover -s tests -t tests
Licença MIT — Berni Software.
Metadata
Release files for bfocus-monitor 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bfocus_monitor-0.1.2.tar.gz | 27.8 kB | With provenance | Details for bfocus_monitor-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bfocus_monitor-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for bfocus_monitor-0.1.2-py3-none-any.whl |
Total release size: 47.2 kB
Release files / bfocus_monitor-0.1.2.tar.gz
| Download URL | bfocus_monitor-0.1.2.tar.gz |
|---|---|
| Size | 27.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01e52dd0b32aa8eb6593604d7770a33ea20fd21f0a9e5b0ab748d39470f3f872
|
|
BLAKE2b-256 checksum How to use checksums |
15ed23bdbe26638f7a0b1aad3c885b6c2448fd2532c213fbd78c4b8b9408eac6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 7, 2026.
Transparency logRelease files / bfocus_monitor-0.1.2-py3-none-any.whl
| Download URL | bfocus_monitor-0.1.2-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e339dded6ea58a889d43b7a6c9e10063f46595ebb784d75bea835d1968fed4e4
|
|
BLAKE2b-256 checksum How to use checksums |
3d9feb8573b2d737456580a6f8ac3253ca4d2a9662aa2cf4046d23bb87de151d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 7, 2026.
Transparency logSecurity for bfocus-monitor 0.1.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.
Attestation for bfocus_monitor-0.1.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 Oct 7, 2026.
Transparency logA 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.