Enable DataLens AI

Updated at:
Copy as MD

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

  1. Log in to the ApsaraDB for SelectDB console.

  2. On the Instances page, click the ID of your target instance to open the Instance Details page.

  3. In the left-side navigation pane, click AI Observability.

  4. Click Enable Service.

  5. In the dialog box, confirm that the following resources will be automatically created, and then click OK.

    • An ApsaraDB for SelectDB database with the langfuse prefix.

    • An ApsaraDB for SelectDB user with the lfu prefix.

    • An ApsaraDB for SelectDB whitelist group with the lfu prefix.

    • A Langfuse instance.

  6. Wait about 1 to 2 minutes for the instance status to change to Running.

Important

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.

  1. On the AI Observability page, in the Whitelist Settings section, find the whitelist group you want to modify and click Edit.

  2. In the IP Whitelist text box, add the public IP address. Separate multiple IP addresses with commas (,).

  3. Click OK.

Step 3: Create a user

  1. On the AI Observability page, in the Connection Address section, obtain the public endpoint.

  2. In your browser, go to the public endpoint. The format is http://<your-public-ip-address>:3000.

  3. On the login page, click Sign up.

  4. 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.

  1. On the Create Organization page, enter a name for your organization and click Create.

  2. On the Invite Members page, you can invite team members or click Next to skip.

  3. On the Create Project page, enter a name for your project and click Create.

Step 5: Create an API key

  1. After the project is created, on the Get Started page, click Create new API key.

  2. The system generates and displays the Secret Key and Public Key. Copy and store them in a secure location.

Important

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.

  1. Install the Langfuse SDK.

    pip install langfuse
  2. 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>"
  3. 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)
  4. Run the script.

    python quick_start.py
  5. 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.