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

Update example #171

Merged
merged 1 commit into from
Apr 15, 2024
Merged
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
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
Loading