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

Improve falcon instrumentation examples #3370

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions instrumentation/opentelemetry-instrumentation-falcon/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,41 @@ 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

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
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@

.. 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())

Expand All @@ -78,15 +78,17 @@ def on_get(self, req, resp):
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

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
*****************************************
Expand Down