LangChain Support
Back to LangSmith Observability

How do I disable or toggle LangSmith tracing during execution?

LangSmith Observability·1 min read·Sep 8, 2025··

Context

When using LangSmith for tracing LangChain executions, you may want to temporarily disable tracing or control when traces are collected during your application's runtime. This could be useful when you only want to trace specific parts of your code or need to manage the volume of traces being collected.

Answer

The recommended way to toggle LangSmith tracing during execution is to use the tracing context manager. Here's how to do it:

  1. Import the langsmith package:

    import langsmith as ls
  2. Use the tracing_context manager to disable tracing for specific code blocks:

    with ls.tracing_context(enabled=False):
        my_thing.invoke()

Important notes:

  • The tracing context should be set before executing the trace you want to disable

  • While environment variables like LANGSMITH_TRACING can be used to configure tracing, they are loaded at startup and won't affect runtime behavior

  • Setting the tracing_sample_rate directly on a client instance won't affect the global tracing behavior in LangChain

Source: LangSmith documentation and official guidance from the LangSmith team.