Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement heartbeats for Python #203

Merged
merged 5 commits into from
Apr 22, 2024
Merged

Implement heartbeats for Python #203

merged 5 commits into from
Apr 22, 2024

Conversation

unflxw
Copy link
Contributor

@unflxw unflxw commented Apr 9, 2024

Store global client and expose its config

Store the last (hopefully only) initialised client in a global
variable, and expose its config as a class method on the Client
class.

Implement AppSignal transmitter

Implement a transmitter module similar to the ones in other
integrations, which handles the sending of requests with the usual
AppSignal identifying params.

Remove empty TYPE_CHECKING block

Probably a leftover from some typing refactor.

Implement heartbeats for Python

Implement the heartbeats functionality for Python, similarly to how
it was implemented for Ruby, Elixir and Node.js.

Due to limitations on how with blocks are implemented, which make
it impossible for a function to behave in different ways when called
"by itself" and when called by a with block, it is possible to call
it in the following ways:

  • heartbeat(name), which sends a finish heartbeat event
  • heartbeat(name, function), which sends:
    • a start heartbeat event
    • a finish heartbeat event, if the function does not raise
  • as a with Heartbeat(name): block (note: H not h!) which sends:
    • a start heartbeat event
    • a finish heartbeat event, if the with block does not raise

Add a LOGGING_ENDPOINT configuration variable to configure the
logging endpoint, which is also the endpoint to which heartbeats are
sent. This is a bit bizarre, as Python does not support the logging
feature yet, but it is consistent with our other integrations.

unflxw added 3 commits April 9, 2024 16:15
Store the last (hopefully only) initialised client in a global
variable, and expose its config as a class method on the `Client`
class.
Implement a transmitter module similar to the ones in other
integrations, which handles the sending of requests with the usual
AppSignal identifying params.
Probably a leftover from some typing refactor.
@unflxw unflxw added the feature label Apr 9, 2024
@unflxw unflxw self-assigned this Apr 9, 2024
@unflxw unflxw marked this pull request as draft April 9, 2024 19:57
Copy link
Member

@tombruijn tombruijn left a comment

Choose a reason for hiding this comment

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

The build is failing because of some import error.

src/appsignal/heartbeat.py Outdated Show resolved Hide resolved
@unflxw
Copy link
Contributor Author

unflxw commented Apr 12, 2024

Ended up changing the design significantly, please re-review. I feel that heartbeat_with_context was not a good name -- it was borrowed from send_error_with_context, but "with context" in that function means "with this context for the error", not "by using a with context block".

I feel that the current design, where the Heartbeat class implements the with context manager protocol, and heartbeat can optionally be called with a function (in a way, doing both the Ruby API design and the Elixir/Node.js API design) is a lot clearer, and likely to be a better fit to most use-cases.

Also fixed some major issues with the implementation.

@unflxw unflxw requested a review from tombruijn April 12, 2024 16:04
@unflxw unflxw marked this pull request as ready for review April 12, 2024 16:04
@backlog-helper
Copy link


This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

Implement the heartbeats functionality for Python, similarly to how
it was implemented for Ruby, Elixir and Node.js.

Due to limitations on how `with` blocks are implemented, which make
it impossible for a function to behave in different ways when called
"by itself" and when called by a `with` block, it is possible to call
it in the following ways:

- `heartbeat(name)`, which sends a finish heartbeat event
- `heartbeat(name, function)`, which sends:
  - a start heartbeat event
  - a finish heartbeat event, if the function does not raise
- as a `with Heartbeat(name):` block (note: `H` not `h`!) which sends:
  - a start heartbeat event
  - a finish heartbeat event, if the `with` block does not raise

The latter is intentionally un-documented for now, to avoid potential
confusion between `heartbeat` and `Heartbeat`.

Add a `LOGGING_ENDPOINT` configuration variable to configure the
logging endpoint, which is also the endpoint to which heartbeats are
sent. This is a bit bizarre, as Python does not support the logging
feature yet, but it is consistent with our other integrations.
Bump the changeset to a minor version and mention that the feature
is only available to beta testers.
@unflxw unflxw merged commit 6815c44 into main Apr 22, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants