LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmithrun_helperstracing_context
Function●Since v0.5

tracing_context

Copy
tracing_context(
  *,
  project_name: Optional[str] = None,
  address: Optional

Used in Docs

  • BYOC usage
  • Log traces to a specific project
  • Log traces to an agent
  • Set a sampling rate for traces
  • Trace without setting environment variables
View source on GitHub
[
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
[
Union
[
WriteReplica
,
str
]
]
]
=
None
,
distributed_parent_id
:
Optional
[
str
]
=
None
,
**
kwargs
:
Any
=
{
}
)
->
Generator
[
None
,
None
,
None
]

Parameters

NameTypeDescription
project_nameOptional[str]
Default:None

The name of the project to log the run to.

addressOptional[str]
Default:None

(beta) An address string, e.g. from langsmith.address.agent, to log the run to instead of a project. Cannot be combined with a project in the same call. Defaults to the LANGSMITH_AGENT_* env vars.

tagsOptional[list[str]]
Default:None
metadataOptional[dict[str, Any]]
Default:None
parentOptional[Union[run_trees.RunTree, Mapping, str, Literal[False]]]
Default:None
clientOptional[ls_client.Client]
Default:None
enabledOptional[Union[bool, Literal['local']]]
Default:None
replicasOptional[Sequence[Union[WriteReplica, str]]]
Default:None
distributed_parent_idOptional[str]
Default:None

Set the tracing context for a block of code.

Experimental

address is in beta. It is enabled per workspace; a workspace without it rejects the runs, so tracing is lost rather than falling back to a project. It may change without notice.

The tags to add to the run.

The metadata to add to the run.

The parent run to use for the context.

Can be a Run/RunTree object, request headers (for distributed tracing), or the dotted order string.

The client to use for logging the run to LangSmith.

Whether tracing is enabled.

Defaults to None, meaning it will use the current context value or environment variables.

A sequence of WriteReplica dictionaries or address strings 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}}]

The distributed parent ID for distributed tracing. Defaults to None.