Skip to content

Commit

Permalink
Update example (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Apr 15, 2024
2 parents f253278 + 28879ea commit e374583
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docs/tracing/faq/logging_and_viewing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ Then the server (or other service) can continue the trace by passing the headers
```python
# server.py
from langsmith import traceable
from langsmith.run_helpers import tracing_context
from fastapi import FastAPI, Request


Expand All @@ -302,10 +303,29 @@ async def fake_route(request: Request):
# request.headers: {"langsmith-trace": "..."}
# as well as optional metadata/tags in `baggage`
# highlight-next-line
return await my_application(langsmith_extra={"parent": request.headers})
with tracing_context(parent=request.headers):
return await my_application()

```

The example above uses the `tracing_context` context manager. You can also directly specify the parent run context in the `trace` context manager or `traceable` decorator.

```python
from langsmith.run_helpers import traceable, trace
# ... same as above
@app.post("/my-route")
async def fake_route(request: Request):
# request.headers: {"langsmith-trace": "..."}
# as well as optional metadata/tags in `baggage`
# highlight-next-line
my_application(langsmith_extra={"parent": request.headers})
# Or using the `trace` context manager
with trace(parent=request.headers) as run_tree:
...
run_tree.end(outputs={"answer": "42"})
...
```

### Turning off tracing

If you've decided you no longer want to trace your runs, you can remove the environment variables configured to start tracing in the first place.
Expand Down

0 comments on commit e374583

Please sign in to comment.