File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,15 @@ This makes it possible to map the trace to the log and switch between them in yo
122122 # 2024-03-30 18:01:40.275193 [info] execution step one [__main__] filename=example.py func_name=<module> module=example parent_span_id=6b15400b6764f747 pathname=/example.py process=16602 process_name=MainProcess service.name=fastapi span_id=a3586e6f36d675e1 thread=8385919680 thread_name=MainThread trace_id=d1dc4e05da452f29c56cf4f3c3963794
123123 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124124
125+ .. tip ::
126+
127+ You can embed a processor in the **structlog ** processor chain to export the trace context to the log.
128+
129+ .. code-block :: python
130+ :caption: Import processor for extract trace meta
131+
132+ from asgi_monitor.logging.trace_processor import extract_opentelemetry_trace_meta
133+
125134Uvicorn
126135~~~~~~~~~~~~~~~~~~
127136
Original file line number Diff line number Diff line change @@ -101,6 +101,27 @@ See the cookbook_ for more information.
101101 logger.info(" full energy" )
102102 return {" message" : " ok" , " status" : " success" }
103103
104+ .. tip ::
105+
106+ You can also use the ``@span `` decorator to cover a **function ** or **method ** and not interfere with the code.
107+
108+ .. code-block :: python
109+ :caption: Using the @ span decorator
110+
111+ import asyncio
112+ from asgi_monitor.tracing import span
113+
114+ @span (name = " sleep" , attributes = {" duration" : " 1000ms" })
115+ async def get_1000ms () -> dict :
116+ await asyncio.sleep(1 )
117+ logger.error(" sleep" )
118+ return {" message" : " ok" , " status" : " success" }
119+
120+ @span # name: get_100ms, attributes: {}
121+ async def get_100ms () -> dict :
122+ await asyncio.sleep(0.1 )
123+ logger.error(" sleep" )
124+ return {" message" : " ok" , " status" : " success" }
104125
105126 Exporting
106127~~~~~~~~~~~~~~~~~~
You can’t perform that action at this time.
0 commit comments