Send logs privately from Azure container apps environment to Log analytic workspace

Van Huy Tuyen 0 Reputation points
2025-03-28T03:55:04.85+00:00

Dear team,

I implement Azure Monitor Private Link Scopes in order to send logs from Azure container apps environment to log analytic workspace.

But I see it doesn't work. It works in the first time. I can see log in the first time. But after that I don't see the new log.

Please help to check.

Thank you!

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,661 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Luis Arias 8,621 Reputation points Volunteer Moderator
    2025-03-29T19:33:22.5166667+00:00

    Hi Van Huy Tuyen,

    Looks like you're dealing with some log issues when sending data from your Azure Container Apps environment to a Log Analytics workspace. It worked at first, but now nothing’s showing up frustrating, Let’s troubleshoot this step by step:

    This is the expected setup:

    User's image

    • Make sure everything is properly configured in Azure Monitor Private Link Scopes. Sometimes, it’s easy to miss a step when connecting to the Log Analytics workspace.
    • Head to the portal and confirm your Container Apps environment is still hooked up to the Private Link Scope. There could be a hiccup there.
    • Make sure the private endpoint tied to the scope is active and set up correctly. DNS settings, NSGs (network security groups), or route tables might be blocking things—worth a look.
    • Check out the logs and see if there are any error messages. Also, verify that permissions are all good on the resources you're using.
    • If none of this works, try removing and re-adding the connections between the environment, Private Link Scope, and Log Analytics workspace. Sometimes a clean slate fixes things.

    Finally to ensure the setup works, you can test sending a log message from within the VNet to the Log Analytics workspace using Azure CLI:

    # Replace these values with your own
    WORKSPACE_ID="<Your-Log-Analytics-Workspace-ID>"
    SHARED_KEY="<Your-Shared-Key>"
    LOG_TYPE="NetworkTestLog"
    MESSAGE="Testing log message through VNet."
    
    # Create a JSON payload
    JSON_PAYLOAD=$(jq -n --arg message "$MESSAGE" '[{"message": $message}]')
    
    # Generate the authorization signature
    DATE=$(date -u +"%a, %d %b %Y %H:%M:%S GMT")
    STRING_TO_HASH="POST\n$(echo -n $JSON_PAYLOAD | wc -c)\napplication/json\nx-ms-date:$DATE\n/api/logs"
    SIGNATURE=$(echo -en $STRING_TO_HASH | openssl dgst -sha256 -hmac "$SHARED_KEY" -binary | base64)
    
    # Submit the log via HTTPS
    curl -X POST \
      -d "$JSON_PAYLOAD" \
      -H "Content-Type: application/json" \
      -H "Log-Type: $LOG_TYPE" \
      -H "x-ms-date: $DATE" \
      -H "Authorization: SharedKey $WORKSPACE_ID:$SIGNATURE" \
      "https://$WORKSPACE_ID.ods.opinsights.azure.com/api/logs?api-version=2016-04-01"
    

    Refences:

    If the information helped address your question, please Accept the answer.

    Luis

    0 comments No comments

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.