mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 19:47:17 +08:00
Improve falcon instrumentation examples (#3370)
This commit is contained in:

committed by
GitHub

parent
8d14f0bb2a
commit
3c60b62ad1
@ -47,13 +47,33 @@ will extract path_info and content_type attributes from every traced request and
|
||||
|
||||
Falcon Request object reference: https://falcon.readthedocs.io/en/stable/api/request_and_response.html#id1
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import falcon
|
||||
from opentelemetry.instrumentation.falcon import FalconInstrumentor
|
||||
|
||||
FalconInstrumentor().instrument()
|
||||
|
||||
app = falcon.App()
|
||||
|
||||
class HelloWorldResource(object):
|
||||
def on_get(self, req, resp):
|
||||
resp.text = 'Hello World'
|
||||
|
||||
app.add_route('/hello', HelloWorldResource())
|
||||
|
||||
|
||||
Request/Response hooks
|
||||
**********************
|
||||
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
|
||||
and right before the span is finished while processing a response. The hooks can be configured as follows:
|
||||
|
||||
::
|
||||
.. code-block:: python
|
||||
|
||||
from opentelemetry.instrumentation.falcon import FalconInstrumentor
|
||||
|
||||
def request_hook(span, req):
|
||||
pass
|
||||
@ -61,7 +81,7 @@ and right before the span is finished while processing a response. The hooks can
|
||||
def response_hook(span, req, resp):
|
||||
pass
|
||||
|
||||
FalconInstrumentation().instrument(request_hook=request_hook, response_hook=response_hook)
|
||||
FalconInstrumentor().instrument(request_hook=request_hook, response_hook=response_hook)
|
||||
|
||||
References
|
||||
----------
|
||||
|
@ -58,16 +58,16 @@ Usage
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from falcon import API
|
||||
import falcon
|
||||
from opentelemetry.instrumentation.falcon import FalconInstrumentor
|
||||
|
||||
FalconInstrumentor().instrument()
|
||||
|
||||
app = falcon.API()
|
||||
app = falcon.App()
|
||||
|
||||
class HelloWorldResource(object):
|
||||
def on_get(self, req, resp):
|
||||
resp.body = 'Hello World'
|
||||
resp.text = 'Hello World'
|
||||
|
||||
app.add_route('/hello', HelloWorldResource())
|
||||
|
||||
@ -78,7 +78,9 @@ This instrumentation supports request and response hooks. These are functions th
|
||||
right after a span is created for a request and right before the span is finished for the response.
|
||||
The hooks can be configured as follows:
|
||||
|
||||
::
|
||||
.. code-block:: python
|
||||
|
||||
from opentelemetry.instrumentation.falcon import FalconInstrumentor
|
||||
|
||||
def request_hook(span, req):
|
||||
pass
|
||||
@ -86,7 +88,7 @@ The hooks can be configured as follows:
|
||||
def response_hook(span, req, resp):
|
||||
pass
|
||||
|
||||
FalconInstrumentation().instrument(request_hook=request_hook, response_hook=response_hook)
|
||||
FalconInstrumentor().instrument(request_hook=request_hook, response_hook=response_hook)
|
||||
|
||||
Capture HTTP request and response headers
|
||||
*****************************************
|
||||
|
Reference in New Issue
Block a user