# Initialize the tracer
opik_tracer = OpikTracer(project_name="langchain-examples")

llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ("human", "Translate the following text to French: {text}")
])
chain = prompt | llm

result = chain.invoke(
    {"text": "Hello, how are you?"},
    config={"callbacks": [opik_tracer]}
)
print(result.content)
```

The `OpikTracer` will automatically log the run and its details to Opik, including the input prompt, the output, and metadata for each step in the chain.

For detailed parameter information, see the [OpikTracer SDK reference](https://www.comet.com/docs/opik/python-sdk-reference/integrations/langchain/OpikTracer.html).

## Practical Example: Text-to-SQL with Evaluation

Let's walk through a real-world example of using LangChain with Opik for a text-to-SQL query generation task. This example demonstrates how to create synthetic datasets, build LangChain chains, and evaluate your application.

### Setting up the Environment

First, let's set up our environment with the necessary dependencies:

```python
import os
import getpass
import opik
from opik.integrations.openai import track_openai
from openai import OpenAI