How to use App Insights with Prompt Flow

Diogo Guerreiro 0 Reputation points
2025-02-19T15:20:39.4133333+00:00

I'm working on implementing a new flow using Azure Prompt Flow in VSCode, and I'm trying to have the insights displayed in App Insights. Currently I have:

An .env file inside the project and inside the file I have this:

APPLICATIONINSIGHTS_CONNECTION_STRING="
InstrumentationKey=KEY1;IngestionEndpoint=KEY2;LiveEndpoint=K3;ApplicationId=KE4"

But when I run the project on VSCode, I'm getting the messages:

  • No connection string detected, app insight metric exporter is disabled.
  • No connection string detected, app insight trace exporter is disabled.
  • No connection string detected, app insight log exporter is disabled.

Do you have any idea of what it could be the problem? Thanks in advance.

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,153 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 28,211 Reputation points MVP
    2025-02-19T16:27:25.1066667+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    It looks like your Azure Application Insights connection string isn't being detected correctly by your Prompt Flow environment in VSCode. Here are some troubleshooting steps to resolve the issue:

    1. Ensure the .env file is being loaded
    • Check that your .env file is in the root of your project.
    • Restart VSCode to ensure environment variables are loaded.
    • If using a virtual environment, activate it before running the script.
    1. Verify the format of the .env file

    Make sure there are no syntax errors in your .env file. It should be formatted like this:

    APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=KEY1;IngestionEndpoint=KEY2;LiveEndpoint=K3;ApplicationId=KE4"

    1. Check how environment variables are loaded in your script

    If you're running a Python script, ensure you are loading environment variables properly using dotenv:

    from dotenv import load_dotenv import os load_dotenv() # Load variables from .env print(os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")) # Debugging step

    If the output is None, then the .env file is not being read correctly.

    1. Explicitly set the environment variable

    Try setting the variable manually in your terminal before running VSCode:

    export APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=KEY1;IngestionEndpoint=KEY2;LiveEndpoint=K3;ApplicationId=KE4"

    1. Verify Prompt Flow configuration

    Check if the connection string is being set correctly within your Prompt Flow setup. If Prompt Flow expects a different variable name or configuration file, adjust accordingly.

    • If using the integrated terminal, make sure it's using the same environment as your Prompt Flow execution.
    • Restart VSCode and retry.

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.