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

api docs and API simplifications [WIP] #112

Closed

Conversation

beniwohli
Copy link
Contributor

@beniwohli beniwohli commented Dec 4, 2017

This changes the API of exception tracking. It gets rid of the somewhat opaque data argument and instead uses explicit keyword arguments for context, custom etc.

It also removes Django-template-specific code in the exception tracking. It only worked when TEMPLATE_DEBUG was set to true (which shouldn't be the case in production code), and was never exposed in the UI.

@beniwohli beniwohli force-pushed the feature/api-docs-and-fixes branch 5 times, most recently from dab17f5 to cdbb607 Compare December 8, 2017 13:37

[break]
[[client-api-capture-exception]]
==== `Client.capture_exception()`
Copy link
Contributor

Choose a reason for hiding this comment

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

This Client.capture_exception() looks like a class method, but then you actually call client.capture_exception()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used a capital C in all the titles that of methods on Client, I thought it would be clear that it means "method on the Client class", didn't really think of the issue that it could be mistaken as a class method.

Class methods (or static methods) are used relatively seldom in Python, so I don't think most readers would be confused.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, maybe it is just me then, coming from a ruby background.

@@ -0,0 +1,159 @@
[[api]]
== Public API
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you split it into Client, Error and Transaction API when you actually need a client instance for all of them?

How about calling it a Client API and then only use Error and Transaction later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of the things I struggled with when structuring the docs. I though by putting the "Client API" first, the reader will know further down how to get a client.

Copy link
Contributor

Choose a reason for hiding this comment

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

One definitly should find his way around by the explanations you provide. I just think it is somehow confusing to describe it as three seperate APIs. I would only distinguish between the elasticapm and the elasticapm.Client API. And the split up elasticapm.Client into

  • getting an instance
  • error capturing
  • transaction capturing

* `message`: The message as a string.
* `param_message`: Alternatively, a parametrized message as a dictionary.
The dictionary contains two values: `message`, and `params`.
This allows the APM server to group messages together that have share the same
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence is a bit malformed: This allows the APM server to group messages together that have share the same parametrized message.

===== Arguments

* `message`: The message as a string.
* `param_message`: Alternatively, a parametrized message as a dictionary.
Copy link
Contributor

Choose a reason for hiding this comment

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

What if one doesn't provide message nor param_message? Maybe a sentence like Either message or param_message need to be provided... Or is it ok to not provide any of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent point, one of the two is needed

[[transaction-api]]
=== Transaction API

[break]
Copy link
Contributor

Choose a reason for hiding this comment

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

Although the usage is straightforward, it would be nice to also have an example in for the transaction cmds, as you also have examples for client and error related usage.


[break]
[[api-elasticapm-instrument]]
==== `elasticapm.instrument()`
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to be related to transaction specific cmds, so maybe you want to move it to its own section like Auto-Instrumentation.

===== Arguments

* `data`: A dictionary with the data to be attached. This should be a flat key/value `dict` object.
* `_key`: The key to use for this `dict` object. Defaults to `custom`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the underscore in _key indicate it is private? The documented possibility of modifying the variable looks somehow weird.

* `data`: A dictionary with the data to be attached. This should be a flat key/value `dict` object.
* `_key`: The key to use for this `dict` object. Defaults to `custom`.
+
NOTE: This should only be overridden by framework integrations.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to add optional or mandatory to every parameter you describe. Sometimes you mention it is optional, sometimes you mention a default, sometimes none of both.

Copy link
Contributor

Choose a reason for hiding this comment

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

For begin_transaction and end_transaction it is not very clear to me if the params are required or not.


[break]
[[api-set-transaction-name]]
==== `elasticapm.set_transaction_name()`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is begin_transaction and end_transaction a method of client byt set_transaction_name and set_transaction_data are not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in most places you'd use set_transaction_name & Co, you don't have a client instance or the current transaction. With this, we can put the difficulty of getting the current transaction into our code, instead of leaving it to the user to acquire the current transaction somehow.

At the moment, the current transaction is stored on a thread local. But that only works for singlethreaded code, so we probably need to change that in the future. The way it is now, that change would be nicely encapsulated.

Copy link
Contributor

Choose a reason for hiding this comment

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

How can you not have a current transaction when you want to override the name of the current transaction?
I ofc don't have the insights into the agent, but from a pure user perspective I'd somwhow expect that set_transaction_name and begin/stop_transaction is within the same context.
But this might be somehow out of scope for this PR anyways, just realized that when looking at the docs.

@beniwohli beniwohli force-pushed the feature/api-docs-and-fixes branch 3 times, most recently from 7957f28 to 711543a Compare December 11, 2017 11:11
Copy link
Contributor

@simitt simitt left a comment

Choose a reason for hiding this comment

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

The documentation looks great @beniwohli!
I only left some minor comments.


Returns the id of the message as a string.

NOTE: either the `message` or the `param_message` argument is required.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you start with a capital letter here?

== Public API

The Elastic APM Python agent has several public APIs.
Most of these APIs are not needed when using one of our supported frameworks (Django and Flask),
Copy link
Contributor

Choose a reason for hiding this comment

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

How about changing this to something like Most of the public API functionality is not needed when..

* `data`: A dictionary with the data to be attached. This should be a flat key/value `dict` object.
* `_key`: The key to use for this `dict` object. Defaults to `custom`.
+
NOTE: This should only be overridden by framework integrations.
Copy link
Contributor

Choose a reason for hiding this comment

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

For begin_transaction and end_transaction it is not very clear to me if the params are required or not.

This includes a wide range of standard library and 3rd party modules.
A list of instrumented modules can be found in `elasticapm.intrumentation.register`.
This function should be called as early as possibly in the startup of your application.
For supported frameworks, this is called automatically. Example:
Copy link
Contributor

Choose a reason for hiding this comment

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

A link to the docs listing the supported framework would be a nice to have here.

 * documents large parts of the public API
 * changed API of `capture_exception`, `capture_message`. Instead of an
   opaque `data` argument, they now have keyword arguments for
   `context`, `custom`, etc.
 * removed special handling of template errors in Django. This only
   ever worked with `TEMPLATE_DEBUG` enabled, and the data was never
   shown.
beniwohli added a commit that referenced this pull request Dec 11, 2017
Forward-port from #112

 * documents large parts of the public API
 * changed API of `capture_exception`, `capture_message`. Instead of an
   opaque `data` argument, they now have keyword arguments for
   `context`, `custom`, etc.
 * removed special handling of template errors in Django. This only
   ever worked with `TEMPLATE_DEBUG` enabled, and the data was never
   shown.
@beniwohli beniwohli closed this in eb657ee Dec 11, 2017
beniwohli added a commit that referenced this pull request Dec 11, 2017
 * documents large parts of the public API
 * changed API of `capture_exception`, `capture_message`. Instead of an
   opaque `data` argument, they now have keyword arguments for
   `context`, `custom`, etc.
 * removed special handling of template errors in Django. This only
   ever worked with `TEMPLATE_DEBUG` enabled, and the data was never
   shown.

closes #112
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.

None yet

2 participants