Skip to content

Commit cc1cfa7

Browse files
committed
Clean dependencies, change readme and real_world example
1 parent c226cc5 commit cc1cfa7

File tree

6 files changed

+123
-367
lines changed

6 files changed

+123
-367
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,21 @@ trace.set_tracer_provider(tracer)
125125
tracer.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint="http://asgi-monitor.tempo:4317")))
126126
config = TracingConfig(tracer_provider=tracer)
127127

128-
setup_tracing(app=app, config=config)
128+
setup_tracing(app=app, config=config) # Must be configured last
129129
```
130130

131-
Create your **TracerProvider** with the necessary settings and add it to the **TracingConfig**,
132-
also include tracing in others setup functions.
131+
1. Install the necessary exporter, for example [opentelemetry-exporter-jaeger](https://pypi.org/project/opentelemetry-exporter-jaeger/) or the standard [opentelemetry-exporter-otlp](https://pypi.org/project/opentelemetry-exporter-otlp/)
132+
2. Create your `TracerProvider` with the necessary settings and add it to the `TracingConfig`,
133+
also include tracing in others setup functions
134+
3. Install `service.name` in the resource attributes
135+
4. Use `setup_tracing` _after installing all middleware_ to complete the setup
133136

134137
After that, you can profile the payload of the application.
135138

136139
```python
137-
with trace.get_tracer("asgi-monitor").start_as_current_span("sleep 0.1"):
140+
tracer = trace.get_tracer(__name__)
141+
142+
with tracer.start_as_current_span("sleep 0.1"):
138143
await asyncio.sleep(0.1)
139144
```
140145

examples/real_world/app/routes/slow.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
include_in_schema=True,
1111
)
1212
logger = logging.getLogger(__name__)
13+
tracer = trace.get_tracer(__name__)
1314

1415

1516
@slow_router.get("/1000ms", status_code=status.HTTP_200_OK)
1617
async def get_1000ms() -> dict:
17-
with trace.get_tracer("asgi-monitor").start_as_current_span("sleep 0.1"):
18+
with tracer.start_as_current_span("sleep 0.1"):
1819
await asyncio.sleep(0.1)
1920
logger.error("sick")
20-
with trace.get_tracer("asgi-monitor").start_as_current_span("sleep 0.2"):
21+
with tracer.start_as_current_span("sleep 0.2"):
2122
await asyncio.sleep(0.2)
2223
logger.error("still sick")
23-
with trace.get_tracer("asgi-monitor").start_as_current_span("sleep 0.3"):
24+
with tracer.start_as_current_span("sleep 0.3"):
2425
await asyncio.sleep(0.3)
2526
logger.warning("normal")
26-
with trace.get_tracer("asgi-monitor").start_as_current_span("sleep 0.4"):
27+
with tracer.start_as_current_span("sleep 0.4"):
2728
await asyncio.sleep(0.4)
2829
logger.info("full energy")
2930
return {"message": "ok", "status": "success"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
uvicorn
22
fastapi
33
asgi-monitor
4+
opentelemetry-exporter-otlp

0 commit comments

Comments
 (0)