# tracing_context

> **Function** in `langsmith`

📖 [View in docs](https://reference.langchain.com/python/langsmith/run_helpers/tracing_context)

Set the tracing context for a block of code.

## Signature

```python
tracing_context(
    *,
    project_name: Optional[str] = None,
    tags: Optional[list[str]] = None,
    metadata: Optional[dict[str, Any]] = None,
    parent: Optional[Union[run_trees.RunTree, Mapping, str, Literal[False]]] = None,
    enabled: Optional[Union[bool, Literal['local']]] = None,
    client: Optional[ls_client.Client] = None,
    replicas: Optional[Sequence[WriteReplica]] = None,
    distributed_parent_id: Optional[str] = None,
    **kwargs: Any = {},
) -> Generator[None, None, None]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `project_name` | `Optional[str]` | No | The name of the project to log the run to. (default: `None`) |
| `tags` | `Optional[list[str]]` | No | The tags to add to the run. (default: `None`) |
| `metadata` | `Optional[dict[str, Any]]` | No | The metadata to add to the run. (default: `None`) |
| `parent` | `Optional[Union[run_trees.RunTree, Mapping, str, Literal[False]]]` | No | The parent run to use for the context.  Can be a Run/`RunTree` object, request headers (for distributed tracing), or the dotted order string. (default: `None`) |
| `client` | `Optional[ls_client.Client]` | No | The client to use for logging the run to LangSmith. (default: `None`) |
| `enabled` | `Optional[Union[bool, Literal['local']]]` | No | Whether tracing is enabled.  Defaults to `None`, meaning it will use the current context value or environment variables. (default: `None`) |
| `replicas` | `Optional[Sequence[WriteReplica]]` | No | A sequence of `WriteReplica` dictionaries to send runs to.  Example: `[{"api_url": "https://api.example.com", "auth": {"api_key": "key"}, "project_name": "proj"}]` or `[{"project_name": "my_experiment", "updates": {"reference_example_id": None}}]` (default: `None`) |
| `distributed_parent_id` | `Optional[str]` | No | The distributed parent ID for distributed tracing. Defaults to None. (default: `None`) |

---

[View source on GitHub](https://github.com/langchain-ai/langsmith-sdk/blob/fcda9320ff067c3d3857e9e3d088fc1eb0643fc4/python/langsmith/run_helpers.py#L139)