Enable DataLens AI
Enable the DataLens AI service for ApsaraDB for SelectDB and send your first observability trace. The process takes about 15 minutes.
Prerequisites
-
An ApsaraDB for SelectDB instance, version 5.0 or later, is running.
-
Python 3.9 or later is installed on your local machine.
-
The DataLens AI service is activated. This service is currently in an invite-only preview. Contact technical support for access.
Step 1: Enable DataLens AI
-
Log in to the ApsaraDB for SelectDB console.
-
On the Instances page, click the ID of your target instance to open the Instance Details page.
-
In the left-side navigation pane, click AI Observability.
-
Click Enable Service.
-
In the dialog box, confirm that the following resources will be automatically created, and then click OK.
-
An ApsaraDB for SelectDB database with the
langfuseprefix. -
An ApsaraDB for SelectDB user with the
lfuprefix. -
An ApsaraDB for SelectDB whitelist group with the
lfuprefix. -
A Langfuse instance.
-
-
Wait about 1 to 2 minutes for the instance status to change to Running.
Releasing an ApsaraDB for SelectDB instance deletes all data from the associated Langfuse instance.
Step 2: Configure the whitelist
Add the public IP address of the host that runs your SDK to the whitelist so it can access the Langfuse service.
-
On the AI Observability page, in the Whitelist Settings section, find the whitelist group you want to modify and click Edit.
-
In the IP Whitelist text box, add the public IP address. Separate multiple IP addresses with commas (,).
-
Click OK.
Step 3: Create a user
-
On the AI Observability page, in the Connection Address section, obtain the public endpoint.
-
In your browser, go to the public endpoint. The format is
http://<your-public-ip-address>:3000. -
On the login page, click Sign up.
-
Enter a Name, Email, and Password, and then click Sign up.
Step 4: Create an organization and a project
After you register, the setup wizard starts automatically to help you create an organization and a project.
-
On the Create Organization page, enter a name for your organization and click Create.
-
On the Invite Members page, you can invite team members or click Next to skip.
-
On the Create Project page, enter a name for your project and click Create.
Step 5: Create an API key
-
After the project is created, on the Get Started page, click Create new API key.
-
The system generates and displays the Secret Key and Public Key. Copy and store them in a secure location.
The Secret Key is displayed only once upon creation. You must save it immediately; if lost, you must create a new API key.
Step 6: Send your first observability trace
Use the Python SDK to send your first observability trace and verify that the service is working.
-
Install the Langfuse SDK.
pip install langfuse -
Set the environment variables. Replace the placeholders with your actual values.
# Langfuse connection details (obtained in Step 5) export LANGFUSE_SECRET_KEY="<your-secret-key>" export LANGFUSE_PUBLIC_KEY="<your-public-key>" export LANGFUSE_HOST="<your-public-endpoint>" # Qwen API key (for the LLM call in the example) export DASHSCOPE_API_KEY="<your-dashscope-api-key>" -
Create and run the sample code
quick_start.py.import os from langfuse import observe from openai import OpenAI client = OpenAI( api_key=os.environ.get("DASHSCOPE_API_KEY"), base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", ) @observe() def chat(user_message): response = client.chat.completions.create( model="qwen-plus", messages=[{"role": "user", "content": user_message}], ) return response.choices[0].message.content if __name__ == "__main__": result = chat("What is ApsaraDB for SelectDB? Describe it in one sentence.") print(result) -
Run the script.
python quick_start.py -
Verify that the trace was sent successfully. Go to the Langfuse UI in your browser. In the left-side navigation pane, click Tracing. You should see the record of the call.