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
  • RemoteGraph
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDKRemoteGraph
Language
Theme
Pythonlangsmithrun_helperstrace
Class●Since v0.0

trace

Manage a LangSmith run in context.

This class can be used as both a synchronous and asynchronous context manager.

Copy
trace(
  self,
  name: str,
  run_type: ls_client.RUN_TYPE_T = 'chain',
  *,
  inputs: Optional[dict] = None,
  extra: Optional[dict] = None,
  project_name: Optional[str] = None,
  parent: Optional[Union[run_trees.RunTree, str, Mapping, Literal['ignore']]] = None,
  tags: Optional[list[str]] = None,
  metadata: Optional[Mapping[str, Any]] = None,
  client: Optional[ls_client.Client] = None,
  run_id: Optional[ls_client.ID_TYPE] = None,
  reference_example_id: Optional[ls_client.ID_TYPE] = None,
  exceptions_to_handle: Optional[tuple[type[BaseException], ...]] = None,
  attachments: Optional[schemas.Attachments] = None,
  **kwargs: Any = {}
)

Used in Docs

  • Log user feedback using the SDK

Parameters

NameTypeDescription
name*str

Name of the run.

run_typels_client.RUN_TYPE_T
Default:'chain'

Type of run (e.g., 'chain', 'llm', 'tool').

inputsOptional[dict]
Default:None

Initial input data for the run.

project_nameOptional[str]
Default:None

Project name to associate the run with.

parentOptional[Union[run_trees.RunTree, str, Mapping, Literal['ignore']]]
Default:None

Parent run.

Can be a RunTree, dotted order string, or tracing headers.

tagsOptional[list[str]]
Default:None

List of tags for the run.

metadataOptional[Mapping[str, Any]]
Default:None

Additional metadata for the run.

clientOptional[ls_client.Client]
Default:None

LangSmith client for custom settings.

run_idOptional[ls_client.ID_TYPE]
Default:None

Preset identifier for the run.

reference_example_idOptional[ls_client.ID_TYPE]
Default:None

Associates run with a dataset example.

Only for root runs in evaluation.

exceptions_to_handleOptional[tuple[type[BaseException], ...]]
Default:None

Exception types to ignore.

extraOptional[dict]
Default:None

Extra data to send to LangSmith.

Use 'metadata' instead.

Constructors

constructor
__init__
NameType
namestr
run_typels_client.RUN_TYPE_T
inputsOptional[dict]
extraOptional[dict]
project_nameOptional[str]
parentOptional[Union[run_trees.RunTree, str, Mapping, Literal['ignore']]]
tagsOptional[list[str]]
metadataOptional[Mapping[str, Any]]
clientOptional[ls_client.Client]
run_idOptional[ls_client.ID_TYPE]
reference_example_idOptional[ls_client.ID_TYPE]
exceptions_to_handleOptional[tuple[type[BaseException], ...]]
attachmentsOptional[schemas.Attachments]

Attributes

attribute
name: name
attribute
run_type: run_type
attribute
inputs: inputs
attribute
attachments: attachments
attribute
extra: extra
attribute
project_name: project_name
attribute
parent: parent
attribute
run_tree
attribute
tags: tags
attribute
metadata: metadata
attribute
client: client
attribute
run_id: run_id
attribute
reference_example_id: reference_example_id
attribute
exceptions_to_handle: exceptions_to_handle
attribute
new_run: Optional[run_trees.RunTree]
attribute
old_ctx: Optional[dict]
View source on GitHub