feature-flag-poc is an Azure Function-based proof of concept for implementing feature flagging using Azure App Configuration. This project uses TypeScript and integrates with OpenTelemetry for observability.
- Installation
- Usage
- Scripts
- Environment Variables
- Dependencies
- Dev Dependencies
- Function Details
- Commitizen and Commitlint
Project_structure
├── dist
│ └── src
│ ├── functions
│ └── utils
├── terraform
├── src
│ ├── functions
│ └── utils
├── azurite_config
└── project_config
- Clone the repository:
git clone <repository-url>
cd feature-flag-poc
- Install the dependencies:
pnpm install
- Build the project:
pnpm run build
- Start the Azure Function locally:
pnpm start
- build: Compiles TypeScript files to JavaScript.
pnpm run build
- watch: Compiles TypeScript files in watch mode.
pnpm run watch
- clean: Removes the
dist
directory.
pnpm run clean
- prestart: Cleans and builds the project before starting.
pnpm run prestart
- start: Starts the Azure Function.
pnpm start
- test: Placeholder for test command.
pnpm run test
commit: Use Commitizen for standardized commit messages.
pnpm run commit
Create a .env
file in the root directory and add your Azure App Configuration connection string:
AZURE_APP_CONFIG_CONNECTION_STRING=Endpoint=https://tech-radar-v2-feature-app-config.azconfig.io;Id=xxx
- @azure/app-configuration: Used for managing application settings and feature flags in Azure.
- @azure/functions: Provides support for creating Azure Functions, enabling serverless computing.
- @effect/schema: Utilized for data validation and schema definitions.
- @opentelemetry/api, @opentelemetry/sdk- and related packages*: These packages are part of the OpenTelemetry suite, which we use for tracing, logging, and metrics collection to monitor application performance and behavior.
- dotenv: Loads environment variables from a
.env
file, for managing configuration settings securely. - durable-functions: Enables the creation of stateful workflows within Azure Functions.
- effect: A functional programming library for building applications with a focus on effect management.
- @biomejs/biome: Provides a comprehensive toolkit for managing and maintaining code quality, including linting and formatting.
- @commitlint/cli: Helps enforce consistent commit messages across the project.
- azure-functions-core-tools: CLI tools for developing, running, and deploying Azure Functions locally.
- commitizen: Assists in creating standardized commit messages, improving readability and project history.
- cz-emoji-conventional: An adapter for Commitizen that adds emojis to commit messages following the conventional commits specification.
- msw: Mock Service Worker for API mocking, facilitating testing and development.
- typescript: The primary language for our project, providing type safety and modern JavaScript features.
- vitest: A fast unit testing framework that is powereed by Vite.
An Azure Function HTTP trigger that fetches a feature flag from Azure App Configuration and returns its value.
To work with Azure Functions and Azure Storage locally, you can use Azurite, an open-source emulator for Azure Storage. Here's a guide to setting it up and integrating it with your Azure Functions project.
- Visual Studio Code
- Node.js
- Azure Functions Core Tools
- Azurite extension for Visual Studio Code
-
Install Azurite Extension in VSCode:
- Open Visual Studio Code.
- Go to the Extensions view by clicking the Extensions icon in the Activity Bar on the side of the window.
- Search for
Azurite
and install it.
-
Start Azurite:
- After installation, you can start Azurite by opening the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
on macOS) and typingAzurite: Start
. - You should see Azurite starting in the Terminal window with logs indicating that the Blob, Queue, and Table services are running.
- After installation, you can start Azurite by opening the Command Palette (
-
Configure Azure Function to Use Azurite:
- Open your Azure Functions project in VSCode.
- Create or update the
local.settings.json
file to configure your Azure Functions to use the Azurite emulator. Ensure yourlocal.settings.json
file looks like this:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "node", "APP_CONFIG_CONNECTION_STRING": "YourAppConfigConnectionString" } }
UseDevelopmentStorage=true
tells your function app to use the local Azurite storage emulator.
-
Create a Storage Account in Azurite:
- Azurite will automatically handle storage account creation. You just need to use the connection string
UseDevelopmentStorage=true
.
- Azurite will automatically handle storage account creation. You just need to use the connection string
-
Develop and Test Azure Functions Locally:
- With Azurite running, you can now develop and test your Azure Functions locally as if you were using actual Azure Storage.
- Use the Azure Functions Core Tools to start your function app locally:
func start
- Your functions will interact with the local storage emulator instead of the cloud.
-
Check Azurite Data:
- You can view and manage your Azurite data using tools like
Azure Storage Explorer
or directly within Visual Studio Code if you have theAzure Storage
extension installed. - Connect to
http://127.0.0.1:10000/devstoreaccount1
to view the storage account contents.
- You can view and manage your Azurite data using tools like
docker run --rm -it -p 18888:18888 -p 4317:18889 -d --name aspire-dashboard \
mcr.microsoft.com/dotnet/aspire-dashboard:8.0.0
-
Azurite Ports: By default, Azurite listens on the following ports:
- Blob service:
10000
- Queue service:
10001
- Table service:
10002
- Ensure these ports are not being used by other services on your machine.
- Blob service:
-
Environment Variables: Make sure that your local environment variables and
local.settings.json
are correctly configured to match your development needs.
By following these steps, you can set up a local development environment for Azure Functions using Azurite in Visual Studio Code, allowing you to develop and test your functions without needing access to cloud resources.
- Replace
<repository-url>
with the actual repository URL. - Ensure that the Azure App Configuration connection string is correctly set in the
.env
file. - This function can be tested locally using Azure Functions Core Tools.
- Implement test cases using
vitest
. - Integrate full OpenTelemetry observability.
- Integrate Aspire dashboard for local observability.
- Add more comprehensive error handling and logging.
- Set up Infrastructure as Code (IaC) with Terraform.
This project uses Commitizen to standardize commit messages. To make a commit, run:
pnpm run commit
This will prompt you to fill out a standardized commit message.
Commitlint checks if your commit messages meet the conventional commit format. It is configured to work with Commitizen.
The configuration for Commitizen and Commitlint is specified in the package.json
file:
{
"config": {
"commitizen": {
"path": "node_modules/cz-emoji-conventional"
}
}
}