Skip to main content
As mentioned in other guides, the following environment variables allow you to configure tracing enabled, the api endpoint, the api key, and the tracing project:
  • LANGSMITH_TRACING
  • LANGSMITH_API_KEY
  • LANGSMITH_ENDPOINT
  • LANGSMITH_PROJECT
If you need to trace runs with a custom configuration, are working in an environment that doesnโ€™t support typical environment variables (such as Cloudflare Workers), or would simply prefer not to rely on environment variables, LangSmith allows you to configure tracing programmatically.
Due to a number of asks for finer-grained control of tracing using the trace context manager, we changed the behavior of with trace to honor the LANGSMITH_TRACING environment variable in version 0.1.95 of the Python SDK. You can find more details in the release notes. The recommended way to disable/enable tracing without setting environment variables is to use the with tracing_context context manager, as shown in the example below.
  • Python: The recommended way to do this in Python is to use the tracing_context context manager. This works for both code annotated with traceable and code within the trace context manager.
  • TypeScript: You can pass in both the client and the tracingEnabled flag to the traceable decorator.
If you prefer a video tutorial, check out the Alternative Ways to Trace video from the Introduction to LangSmith Course.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.