Kent - Fake Sentry server for local development, debugging, and integration testing

Related tags

Testing kent
Overview

Kent

Kent is a service for debugging and integration testing Sentry.

Code: https://github.com/willkg/kent/
Issues: https://github.com/willkg/kent/issues
License: MPL v2

Goals

Goals of Kent:

  1. make it possible to debug before_send and before_breadcrumb sanitization code when using sentry-sdk
  2. make it possible to debug other sentry error submission payload issues
  3. make it possible to write integration tests against a fake sentry instance

Quick start

Installing and running on your local machine

  1. Install Kent.

    You can install Kent from PyPI with pipx or pip or whatever:

    pipx install kent
    

    You can install a REVISH ("main", branch name, commit, whatever) from GitHub:

    pipx install https://github.com/willkg/kent/archive/refs/heads/
        .zip
    
       

    You can install from a checked out version of this repository:

    pipx install .
    
  2. Run Kent:

    kent-server run [-h HOST] [-p PORT]
    

Running in a Docker container

I'm using something like this:

FROM python:3.10.1-alpine3.15

WORKDIR /app/

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1

RUN pip install -U 'pip>=8' && \
    pip install --no-cache-dir 'kent==VERSION'

USER guest

ENTRYPOINT ["/usr/local/bin/kent-server"]
CMD ["run"]

Replace VERSION with the version of Kent you want to use. See https://pypi.org/project/kent for releases.

Then:

$ docker build -t faksentry:latest .
$ docker run --rm --publish 8000:8000 fakesentry:latest run --host 0.0.0.0 --port 8000

Things to know about Kent

Kent is the fakest of fake Sentry servers. It supports a single Sentry project with id 1. You can set up a Sentry DSN to point to Kent and have your application send errors.

Kent is a refined fake Sentry service and doesn't like fast food.

Kent will keep track of the last 100 it received in memory. Nothing is persisted to disk.

You can access the list of errors and error data with your web browser by going to Kent's index page.

You can also access it with the API. This is most useful for integration tests that want to assert things about errors.

/api/errorlist/
List of all errors in memory with a unique error id.
/api/error/ERRORID
Retrieve the payload for a specific error by id.
/api/flush/
Flushes the error manager of all errors.

Kent definitely works with:

  • Python sentry-sdk client

I don't know about anything else. If you use Kent with another Sentry client, add an issue with details or a pull request to update the README.

Release process

  1. Check out main tip.

  2. Update __version__ in src/kent/__init__.py.

  3. Run:

    $ make checkrot
    $ make test
    $ make testdocker
    $ check-manifest
    

    Fix any issues from that.

  4. Update HISTORY.rst.

  5. Push any changes to GitHub.

  6. Release:

    $ git tag --sign 1.0.0
    # Use contents from HISTORY.rst for tag comment
    
    $ make clean
    $ python setup.py sdist bdist_wheel
    $ twine upload dist/*
    
Comments
  • Misleading server output wrt. bind address

    Misleading server output wrt. bind address

    The Dockerfile in this project and the hack to always listen on localhost (ipv4 or ipv6) leads to a situation where the port in the container is not reachable from other containers or host.

    Instead, kent should bind to :: or 0.0.0.0

    This cannot be worked around with:

    docker run -p 5000:5000 --entrypoint "" quay.io/dimaqq/kent flask --app kent.app run --host ::

    Or in docker-compose.yaml:

    version: "3.4"
    services:
      sentry:
        image: quay.io/dimaqq/kent:latest
        ports:
          - "5000:5000"
        entrypoint: ""
        command: "flask --app kent.app run --host ::"
    

    Because the Python code in kent specifically overrides the bind address with ::1 or 127.0.0.1 😭

    > docker compose run sentry
     * Serving Flask app 'kent.app'
     * Debug mode: off
    [2022-11-18 09:01:51,484] INFO: _internal: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
     * Running on all addresses (::)
     * Running on http://[::1]:5000
     * Running on http://[::1]:5000
    

    And thus the app is accessible from inside the container but not from outside the container.

    opened by dimaqq 9
  • Fix Kent with Flask 2.1.0+ (#23)

    Fix Kent with Flask 2.1.0+ (#23)

    This fixes Kent to work with Flask 2.1.0. Something about the way we were (ab)using Flask's cli was triggering an error in werkzeug. This fixes it.

    Fixes #23.

    opened by willkg 2
  • kent doesn't work with flask 2.1.0

    kent doesn't work with flask 2.1.0

    Flask 2.1.0 released yesterday and kent fails with that:

    > kent-server run
    Traceback (most recent call last):
      File "/home/willkg/venvs/kent/bin/kent-server", line 33, in <module>
        sys.exit(load_entry_point('kent', 'console_scripts', 'kent-server')())
      File "/home/willkg/mozilla/kent/src/kent/cli_server.py", line 30, in main
        flask_cli.main()
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/flask/cli.py", line 579, in main
        return super().main(*args, **kwargs)
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/click/core.py", line 1055, in main
        rv = self.invoke(ctx)
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/click/core.py", line 760, in invoke
        return __callback(*args, **kwargs)
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
        return ctx.invoke(f, obj, *args, **kwargs)
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/click/core.py", line 760, in invoke
        return __callback(*args, **kwargs)
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/flask/cli.py", line 851, in run_command
        run_simple(
      File "/home/willkg/venvs/kent/lib/python3.8/site-packages/werkzeug/serving.py", line 1047, in run_simple
        fd = int(os.environ["WERKZEUG_SERVER_FD"])
      File "/home/willkg/.pyenv/versions/3.8.10/lib/python3.8/os.py", line 675, in __getitem__
        raise KeyError(key) from None
    KeyError: 'WERKZEUG_SERVER_FD'
    
    opened by willkg 1
  • support envelope endpoint?

    support envelope endpoint?

    The SDK docs talk about an Envelope endpoint:

    https://develop.sentry.dev/sdk/envelopes/

    I've seen that url pop up in the Kent logs when I'm using Kent.

    Is there a compelling reason to implement this other than comprehensive sentry sdk support?

    opened by willkg 1
  • Update actions and fix workflow events

    Update actions and fix workflow events

    This updates the checkout and setup-python actions. This also fixes the push event to only run on the main branch and the pull_request event to only run on pull requests against the main branch.

    opened by willkg 0
  • Rework logging to be more helpful (#32)

    Rework logging to be more helpful (#32)

    This changes what gets logged when Kent gets a request. Previously, it would log all the HTTP headers. That's not helpful when you're debugging issues in an application. This changes it to log sentry-sdk related headers as well as the exception type/value or message from the payload.

    This also logs the url for the event if you want to look at it.

    Fixes #32.

    opened by willkg 0
  • Dev updates

    Dev updates

    This moves dev requirements out of EXTRAS and into a requirements-dev.txt file. This also updates them to current versions.

    This updates the sample Dockerfile and the example in the README to use the latest Python 3.10 alpine image. It tweaks some comments and documentation around that, too. It switches to using the --init argument for docker run.

    opened by willkg 0
  • log summary of exception

    log summary of exception

    Sometimes I'm using Kent as a fakesentry service and I'm debugging things. When Kent gets a Sentry event, it logs information about the HTTP POST. It'd be more helpful if it logged information about the event. Maybe some information about the HTTP POST (size, sentry-trace, sentry-auth) and the event (summary)?

    opened by willkg 0
  • Prep for 0.5.0 release

    Prep for 0.5.0 release

    • switch to using build
    • update version and release
    • add kent_submit.py to manifest
    • fix formatting of test_app.py
    • update HISTORY
    • remove lint environment from tox.ini -- we have a make rule and a CI item, so we don't need it in tox.ini as well
    opened by willkg 0
  • Add summary to kent error list (#27)

    Add summary to kent error list (#27)

    This adds a summary column to the error list table. It adds some helper CSS for that.

    It also adds a kent_submit.py script to make it easier to test kent in local dev environment.

    It also fixes the linting rule in tox and Makefile.

    Fixes #27.

    opened by willkg 0
  • Add flush link to index page and change flush to POST (#9)

    Add flush link to index page and change flush to POST (#9)

    This changes flush from a GET to a POST. It changes the state of the server, so it should have been a POST all along.

    This adds a "[Flush]" link to the index page for convenience. It saves you from having to curl the API directly or shutting down and restarting Kent.

    This adds a kent-testpost command for using sentry-sdk and capturing a message. This makes it easier to manually test Kent.

    Fixes #9

    opened by willkg 0
  • add support for raven-go

    add support for raven-go

    Kent server stores data from golang sentry integration as bytes, and is not able to render error list nor error details.

    User-Agent: raven-go/1.0
    Content-Length: 1872
    Content-Type: application/octet-stream
    X-Sentry-Auth: Sentry sentry_version=4, sentry_key=public
    Accept-Encoding: gzip
    
    help wanted 
    opened by acirtautas 4
  • determine if kent is useful

    determine if kent is useful

    I get zero signal for the work I do and have no idea if it's generally positive or negative in the world. I do a lot of work, so this is weird.

    I'm experimenting with ways to get some signal with the least amount of effort for you.

    If you have some positive feeling about Kent (it's useful! you think it's a cool idea! you with you named your project Kent!), add a :smile: or a +1 or something with the thing in the upper right hand corner.

    If you have some negative feeling about Kent, add a :frown: or a -1.

    opened by willkg 6
Owner
Will Kahn-Greene
he/him; crash ingestion, python tools, etc
Will Kahn-Greene
The definitive testing tool for Python. Born under the banner of Behavior Driven Development (BDD).

mamba: the definitive test runner for Python mamba is the definitive test runner for Python. Born under the banner of behavior-driven development. Ins

Néstor Salceda 502 Dec 30, 2022
pytest plugin for distributed testing and loop-on-failures testing modes.

xdist: pytest distributed testing plugin The pytest-xdist plugin extends pytest with some unique test execution modes: test run parallelization: if yo

pytest-dev 1.1k Dec 30, 2022
PENBUD is penetration testing buddy which helps you in penetration testing by making various important tools interactive.

penbud - Penetration Tester Buddy PENBUD is penetration testing buddy which helps you in penetration testing by making various important tools interac

Himanshu Shukla 15 Feb 1, 2022
PacketPy is an open-source solution for stress testing network devices using different testing methods

PacketPy About PacketPy is an open-source solution for stress testing network devices using different testing methods. Currently, there are only two c

null 4 Sep 22, 2022
A toolbar overlay for debugging Flask applications

Flask Debug-toolbar This is a port of the excellent django-debug-toolbar for Flask applications. Installation Installing is simple with pip: $ pip ins

null 863 Dec 29, 2022
A library for generating fake data and populating database tables.

Knockoff Factory A library for generating mock data and creating database fixtures that can be used for unit testing. Table of content Installation Ch

Nike Inc. 30 Sep 23, 2022
create custom test databases that are populated with fake data

About Generate fake but valid data filled databases for test purposes using most popular patterns(AFAIK). Current support is sqlite, mysql, postgresql

Emir Ozer 2.2k Jan 4, 2023
Faker is a Python package that generates fake data for you.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in yo

Daniele Faraglia 15.2k Jan 1, 2023
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages.

Mimesis - Fake Data Generator Description Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes

Isaak Uchakaev 3.8k Dec 29, 2022
Aioresponses is a helper for mock/fake web requests in python aiohttp package.

aioresponses Aioresponses is a helper to mock/fake web requests in python aiohttp package. For requests module there are a lot of packages that help u

null 402 Jan 6, 2023
FakeDataGen is a Full Valid Fake Data Generator.

FakeDataGen is a Full Valid Fake Data Generator. This tool helps you to create fake accounts (in Spanish format) with fully valid data. Within this in

Joel GM 64 Dec 12, 2022
A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax

1.0 Release See here for details about breaking changes with the upcoming 1.0 release: https://github.com/taverntesting/tavern/issues/495 Easier API t

null 909 Dec 15, 2022
Command line driven CI frontend and development task automation tool.

tox automation project Command line driven CI frontend and development task automation tool At its core tox provides a convenient way to run arbitrary

tox development team 3.1k Jan 4, 2023
pytest splinter and selenium integration for anyone interested in browser interaction in tests

Splinter plugin for the pytest runner Install pytest-splinter pip install pytest-splinter Features The plugin provides a set of fixtures to use splin

pytest-dev 238 Nov 14, 2022
Integration layer between Requests and Selenium for automation of web actions.

Requestium is a Python library that merges the power of Requests, Selenium, and Parsel into a single integrated tool for automatizing web actions. The

Tryolabs 1.7k Dec 27, 2022
🏆 A ranked list of awesome python libraries for web development. Updated weekly.

Best-of Web Development with Python ?? A ranked list of awesome python libraries for web development. Updated weekly. This curated list contains 540 a

Machine Learning Tooling 1.8k Dec 26, 2022
Hypothesis is a powerful, flexible, and easy to use library for property-based testing.

Hypothesis Hypothesis is a family of testing libraries which let you write tests parametrized by a source of examples. A Hypothesis implementation the

Hypothesis 6.4k Jan 5, 2023
Generic automation framework for acceptance testing and RPA

Robot Framework Introduction Installation Example Usage Documentation Support and contact Contributing License Introduction Robot Framework is a gener

Robot Framework 7.7k Jan 7, 2023