Skip to content

Commit 3c60b62

Browse files
authored
Improve falcon instrumentation examples (#3370)
1 parent 8d14f0b commit 3c60b62

File tree

2 files changed

+29
-7
lines changed
  • instrumentation/opentelemetry-instrumentation-falcon

2 files changed

+29
-7
lines changed

instrumentation/opentelemetry-instrumentation-falcon/README.rst

+22-2
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,41 @@ will extract path_info and content_type attributes from every traced request and
4747

4848
Falcon Request object reference: https://falcon.readthedocs.io/en/stable/api/request_and_response.html#id1
4949

50+
Usage
51+
-----
52+
53+
.. code-block:: python
54+
55+
import falcon
56+
from opentelemetry.instrumentation.falcon import FalconInstrumentor
57+
58+
FalconInstrumentor().instrument()
59+
60+
app = falcon.App()
61+
62+
class HelloWorldResource(object):
63+
def on_get(self, req, resp):
64+
resp.text = 'Hello World'
65+
66+
app.add_route('/hello', HelloWorldResource())
67+
5068
5169
Request/Response hooks
5270
**********************
5371
The instrumentation supports specifying request and response hooks. These are functions that get called back by the instrumentation right after a Span is created for a request
5472
and right before the span is finished while processing a response. The hooks can be configured as follows:
5573

56-
::
74+
.. code-block:: python
75+
76+
from opentelemetry.instrumentation.falcon import FalconInstrumentor
5777
5878
def request_hook(span, req):
5979
pass
6080
6181
def response_hook(span, req, resp):
6282
pass
6383
64-
FalconInstrumentation().instrument(request_hook=request_hook, response_hook=response_hook)
84+
FalconInstrumentor().instrument(request_hook=request_hook, response_hook=response_hook)
6585
6686
References
6787
----------

instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@
5858
5959
.. code-block:: python
6060
61-
from falcon import API
61+
import falcon
6262
from opentelemetry.instrumentation.falcon import FalconInstrumentor
6363
6464
FalconInstrumentor().instrument()
6565
66-
app = falcon.API()
66+
app = falcon.App()
6767
6868
class HelloWorldResource(object):
6969
def on_get(self, req, resp):
70-
resp.body = 'Hello World'
70+
resp.text = 'Hello World'
7171
7272
app.add_route('/hello', HelloWorldResource())
7373
@@ -78,15 +78,17 @@ def on_get(self, req, resp):
7878
right after a span is created for a request and right before the span is finished for the response.
7979
The hooks can be configured as follows:
8080
81-
::
81+
.. code-block:: python
82+
83+
from opentelemetry.instrumentation.falcon import FalconInstrumentor
8284
8385
def request_hook(span, req):
8486
pass
8587
8688
def response_hook(span, req, resp):
8789
pass
8890
89-
FalconInstrumentation().instrument(request_hook=request_hook, response_hook=response_hook)
91+
FalconInstrumentor().instrument(request_hook=request_hook, response_hook=response_hook)
9092
9193
Capture HTTP request and response headers
9294
*****************************************

0 commit comments

Comments
 (0)