Skip to content

Commit 0116b88

Browse files
lucabelluccinibeniwohli
authored andcommitted
[DOC] Provide an example when no framework is used (#680)
* [DOC] Provide an example when no framework is used Provide an example when no framework is used. Feel free to edit or enrich with additional references to other documentation pages.
1 parent 5122c99 commit 0116b88

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

docs/how-the-agent-works.asciidoc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,41 @@ Examples of this are
2626
Framework integrations require some limited code changes in your app.
2727
E.g. for Django, you need to add `elasticapm.contrib.django` to `INSTALLED_APPS`.
2828

29+
[float]
30+
[[how-it-works-no-framework]]
31+
==== What if you are not using a framework
32+
33+
If you're not using a supported framework, for example, a simple Python script, you can still
34+
leverage the agent's <<automatic-instrumentation,automatic instrumentation>>.
35+
36+
In order to collect the Spans generated by the supported libraries, you need to invoke `elasticapm.instrument()`
37+
(just once, at the initalization stage of your application) and create at least one Transaction.
38+
It is up to you to determine what you consider a Transaction within your application -- it can be the whole execution of the
39+
script or a part of it.
40+
41+
The example below will consider the whole execution as a single transaction with two HTTP request Spans in it.
42+
The `elasticapm.Client` can be setup programmatically or using the environment variables.
43+
44+
[source,python]
45+
----
46+
import requests
47+
import time
48+
import elasticapm
49+
50+
def main():
51+
sess = requests.Session()
52+
for url in [ 'https://www.elastic.co', 'https://benchmarks.elastic.co' ]:
53+
resp = sess.get(url)
54+
time.sleep(1)
55+
56+
if __name__ == '__main__':
57+
client = elasticapm.Client()
58+
elasticapm.instrument()
59+
client.begin_transaction('main')
60+
main()
61+
client.end_transaction('main')
62+
----
63+
2964
[float]
3065
[[how-it-works-instrumentation]]
3166
==== Instrumentation
@@ -61,4 +96,4 @@ the agent starts two additional threads per process:
6196

6297
Note that every process that instantiates the agent will have these three threads.
6398
This means that when you e.g. use gunicorn or uwsgi workers,
64-
each worker will have three threads started by the Python agent.
99+
each worker will have three threads started by the Python agent.

0 commit comments

Comments
 (0)