> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting Started

> Get started with tracing by creating a project, generating an API key, and initializing your first traces.

To get started with tracing, we need to create a tracing project and a tracing application on the TrueFoundry UI, generate an API key for the tracing project and then add the tracing initialization code to our application along with the project
fqn, application name and the API key.

On creating a new tracing project, you can configure which users have read/write/view access

<Steps>
  <Step title="Create a tracing project">
    * Navigate to your Tracing.
    * Click `New Tracing Projects` and enter the project name, collaborators
    * Click Submit.

    <Frame caption="Creating tracing projects">
      <img src="https://mintcdn.com/truefoundry/w6ZeFG1j6PNL7ori/images/creating_Tracing_Projects.png?fit=max&auto=format&n=w6ZeFG1j6PNL7ori&q=85&s=69064bfbe1ebea420411b629f4190675" width="3024" height="1712" data-path="images/creating_Tracing_Projects.png" />
    </Frame>
  </Step>

  <Step title="Create a tracing application">
    * Select the Tracing project created in the previous steps
    * Navigate to `Applications`
    * Click `New Tracing Applications` and enter the application name
    * Click Submit.

    <Frame caption="Creating tracing projects">
      <img src="https://mintcdn.com/truefoundry/w6ZeFG1j6PNL7ori/images/creating_Tracing_Applications.png?fit=max&auto=format&n=w6ZeFG1j6PNL7ori&q=85&s=72e410525d6a1b2a373709405efdbc5f" width="3024" height="1716" data-path="images/creating_Tracing_Applications.png" />
    </Frame>
  </Step>

  <Step title="Generate API Key">
    Generate API key following the steps [here](/docs/generating-truefoundry-api-keys). Please save the value since we will need this in a later step.

    You can also use a [Virtual Account token](/docs/generating-truefoundry-api-keys#virtual-account-tokens-vats) with access to the Tracing Project, in case you don't want to use your personal token.
  </Step>

  <Step title="Install Traceloop SDK">
    Install Traceloop SDK using pip:

    ```bash lines theme={"dark"}
    pip install traceloop-sdk
    ```
  </Step>

  <Step title="Add the initialization code to your application">
    Add this initialization code your code

    ```
    TFY_API_KEY = os.environ.get("TFY_API_KEY")
    Traceloop.init(
        api_endpoint="<enter_your_control_plane_url>/api/otel",
        app_name="enter_your_tracing_application_name"
        headers = {
            "Authorization": f"Bearer {TFY_API_KEY}",
            "TFY-Tracing-Project": "enter_your_tracing_project_fqn",
        },
    )

    ```

    After adding the code snippet to your application, it should look something like this:

    ```python {4-13} lines theme={"dark"}
    import os
    from traceloop.sdk import Traceloop
    from openai import OpenAI

    TFY_API_KEY = os.environ.get("TFY_API_KEY")
    Traceloop.init(
        api_endpoint="<enter_your_control_plane_url>/api/otel",
        app_name="enter_your_tracing_application_name"
        headers = {
            "Authorization": f"Bearer {TFY_API_KEY}",
            "TFY-Tracing-Project": "enter_your_tracing_project_fqn",
        },
    )

    client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

    stream = client.chat.completions.create(
        messages = [
                {"role": "system", "content": "You are an AI bot."},
                {"role": "user", "content": "Enter your prompt here"},
        ],
        model= "openai-main/gpt-4o",
        stream=True,
        temperature=0.7,
        max_tokens=256,
        top_p=0.8,
        frequency_penalty=0,
        presence_penalty=0,
        stop=["</s>"],
    )

    for chunk in stream:
        if chunk.choices and len(chunk.choices) > 0 and chunk.choices[0].delta.content is not None:
            print(chunk.choices[0].delta.content, end="")
    ```

    <Note> Set environment variables for `TFY_API_KEY` as the API key you generated in step 2. </Note>
  </Step>

  <Step title="Run your application and view logged trace">
    Run your application and you should see traces on the TrueFoundry UI.

    <Frame caption="">
      <img src="https://mintcdn.com/truefoundry/FrY4JbiyZud2He3p/images/021b041d-7c02c8adaa2a87ec21a4976f18b00f79245a8e7b460ba66ec8d8368f4c8d6699-Screenshot_2025-04-05_at_12.49.29_AM.png?fit=max&auto=format&n=FrY4JbiyZud2He3p&q=85&s=c0e182727ad4495cd9f0ed00126245b6" width="2870" height="1724" data-path="images/021b041d-7c02c8adaa2a87ec21a4976f18b00f79245a8e7b460ba66ec8d8368f4c8d6699-Screenshot_2025-04-05_at_12.49.29_AM.png" />
    </Frame>
  </Step>
</Steps>

## Add Tracing to your code based on framework

<Columns cols={3}>
  <Card title="Langgraph" href="/docs/tracing/tracing-in-langgraph" />

  <Card title="CrewAI" href="/docs/tracing/tracing-in-crewai" />

  <Card title="Agno" href="/docs/tracing/tracing-in-agno" />

  <Card title="Google ADK" href="/docs/tracing/tracing-in-google-adk" />

  <Card title="OpenAI" href="/docs/tracing/tracing-in-openai" />

  <Card title="FastAPI" href="/docs/tracing/tracing-in-fastapi" />

  <Card title="Flask" href="/docs/tracing/tracing-in-flask" />

  {/* <Card title="Python Code" href="/docs/tracing/tracing-python-code"/> */}
</Columns>

## Advanced Configuration

### Tracing Sampling

For production environments with high traffic, you may want to configure tracing sampling to reduce costs and improve performance. Learn more about [Tracing Sampling](/docs/tracing/tracing-sampling) to understand how to implement sampling strategies.

### Annotate your Workflows, Agents and Tools

For complex workflows or chains, annotating them can help you gain better insights into their operations. With TrueFoundry, you can view the entire trace of your workflow for a comprehensive understanding.

Traceloop offers a set of decorators to simplify this process. For instance, if you have a function that renders a prompt and calls an LLM, you can easily add the `@workflow` decorator to track and annotate the workflow. Let's say your workflow calls more functions you can annotate them as `@task`

<CodeGroup>
  ```python Python lines theme={"dark"}
  from openai import OpenAI
  from traceloop.sdk.decorators import workflow, task

  client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

  @task(name="joke_creation")
  def create_joke():
      completion = client.chat.completions.create(
          model="gpt-3.5-turbo",
          messages=[{"role": "user", "content": "Tell me a joke about opentelemetry"}],
      )

      return completion.choices[0].message.content

  @task(name="signature_generation")
  def generate_signature(joke: str):
      completion = openai.Completion.create(
          model="davinci-002",[]
          prompt="add a signature to the joke:\n\n" + joke,
      )

      return completion.choices[0].text


  @workflow(name="pirate_joke_generator")
  def joke_workflow():
      eng_joke = create_joke()
      pirate_joke = translate_joke_to_pirate(eng_joke)
      signature = generate_signature(pirate_joke)
      print(pirate_joke + "\n\n" + signature)
  ```
</CodeGroup>

Similarly, when working with autonomous agents, you can use the `@agent` decorator to trace the agent as a single unit. Additionally, each individual tool within the agent should be annotated with the `@tool` decorator.

<CodeGroup>
  ```python Python lines theme={"dark"}
  from openai import OpenAI
  from traceloop.sdk.decorators import agent, tool

  client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

  @agent(name="joke_translation")
  def translate_joke_to_pirate(joke: str):
      completion = client.chat.completions.create(
          model="gpt-3.5-turbo",
          messages=[{"role": "user", "content": f"Translate the below joke to pirate-like english:\n\n{joke}"}],
      )

      history_jokes_tool()

      return completion.choices[0].message.content


  @tool(name="history_jokes")
  def history_jokes_tool():
      completion = client.chat.completions.create(
          model="gpt-3.5-turbo",
          messages=[{"role": "user", "content": f"get some history jokes"}],
      )

      return completion.choices[0].message.content
  ```
</CodeGroup>
