Azure Functions HTTP Trigger Not Updating Cosmos DB Visitor Count on Live Website

Mohammadfaizan Shaikh 0 Reputation points
2024-04-21T04:20:30.79+00:00

I'm working on a serverless resume website using Azure Functions with an HTTP trigger to increment a visitor count stored in Azure Cosmos DB. The functionality was working perfectly during development, but after deploying to the live website, the visitor count no longer updates.

Here's what I've observed:

  • The website itself functions normally.
  • The Cosmos DB data remains unchanged despite refreshing the live site.
  • Deployment from Visual Studio Code with GitHub Actions works as expected.

I've checked the following:

  • The Azure Function seems to be triggered by website visits.
  • The connection string to Cosmos DB is correct within the function code.
  • There are no errors logged in the Azure Function logs. I'm working on a serverless resume website using Azure Functions with an HTTP trigger to increment a visitor count stored in Azure Cosmos DB. The functionality was working perfectly during development, but after deploying to the live website, the visitor count no longer updates.
  • it was also working prior to me editing my frontend.main.yml file and then I changed the background for my website by editing my index.html and layout.css file and pushed using github actions and the counter went away.

Question:

  • What could be causing the disconnect between the Azure Function and Cosmos DB update on the live website?
    • Are there any additional troubleshooting steps I can take to identify the root cause of this issue?
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,297 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,436 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,447 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde 28,626 Reputation points MVP
    2024-04-21T10:50:54.2666667+00:00

    Hello @Mohammadfaizan Shaikh ,

    welcome to this moderated Azure community forum.

    You are using 'serverless' compute which that is stateless.

    This means that every time the function is triggered, all logic in the function must be created again, including database connections.

    Depending on how you program, the sample you have used, and the programming language, it's recommended to start with adding more debug lines.

    This gives you more information about what is happening.

    Also, add more exception handling, especially around DB commands.

    If you are using C#, you can consider putting the connection instance in a static member. This way is survives the stateless behavior. Be aware you must be able to renew the connection if needed.

    Lastly, check out the CosmosDB output binding.

    The Azure Cosmos DB output binding lets you write a new document to an Azure Cosmos DB database using the SQL API.

    Can this work for you?


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.