### Run FeatBit with OpenTelemetry Example Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/observability/opentelemetry.mdx Clone the FeatBit repository, build Docker images, and start services including the OpenTelemetry collector, Seq, Jaeger, and Prometheus. This setup allows you to observe FeatBit's performance and behavior. ```shell # Clone the repository git clone https://github.com/featbit/featbit.git cd featbit # Build the test images docker compose --project-directory . -f ./docker/composes/docker-compose-dev.yml build # Start OTEL collector, Seq, Jaeger, and Prometheus docker compose --project-directory . -f ./docker/composes/docker-compose-otel-collector-contrib.yml up -d # Start FeatBit services docker compose --project-directory . -f ./docker/composes/docker-compose-otel.yml up -d ``` -------------------------------- ### Start Development Server Source: https://github.com/featbit/featbit-docs/blob/main/README.md Execute this command to start the local development server. Access the application at localhost:3000. ```bash pnpm dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/featbit/featbit-docs/blob/main/README.md Run this command to install project dependencies before starting development. ```bash pnpm i ``` -------------------------------- ### Start FeatBit Services Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/single-sign-on/keycloak.mdx This command starts the FeatBit services using Docker Compose. Ensure you are in the correct directory containing your docker-compose.yml file. ```bash cd featbit docker-compose up -d ``` -------------------------------- ### Example curl request with required headers Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/using-featbit-rest-api.mdx This example demonstrates how to include the Authorization and Content-Type headers in a curl request. ```bash curl -X GET 'http://localhost:5000/api/v1/envs/9d782f01-6ffb-4a7c-83a2-79304d801a46/feature-flags' \ -H 'Authorization: EXAMPLE-API-ACCESS-TOKEN' \ -H 'Content-Type: application/json' ``` -------------------------------- ### Example CORS Headers Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/overview.mdx These are example headers that demonstrate Cross-Origin Resource Sharing (CORS) support for the FeatBit API. They specify allowed headers, methods, and origins. ```http Access-Control-Allow-Headers: Accept, Content-Type, Content-Length, Accept-Encoding, Authorization Access-Control-Allow-Methods: OPTIONS, GET, DELETE, PATCH Access-Control-Allow-Origin: * Access-Control-Max-Age: 300 ``` -------------------------------- ### Example JSON response for feature flags Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/using-featbit-rest-api.mdx This is an example of a successful JSON response when retrieving a list of feature flags. ```json { "success": true, "errors": [], "data": { "totalCount": 1, "items": [ { "id": "e3d78102-8a67-4698-a744-afcb005e8dfa", "name": "flag 1", "description": "", "key": "flag-1", "isEnabled": false, "variationType": "boolean", "variations": [ { "id": "838b01b2-d443-4317-b8d3-adb2bed483c0", "value": "true" }, { "id": "0c742a83-0053-4f37-8f34-9ef164c17875", "value": "false" } ], "updatedAt": "2023-03-20T05:44:15.765Z", "serves": { "enabledVariations": [ "true" ], "disabledVariation": "false" }, "tags": [] } ] } } ``` -------------------------------- ### Run Keycloak with Docker Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/single-sign-on/keycloak.mdx This command starts a Keycloak instance using Docker. It maps port 9000 for access and sets up administrative credentials for initial login. ```bash docker run -d -p 9000:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin --name=keycloak quay.io/keycloak/keycloak:22.0.1 start-dev ``` -------------------------------- ### Complete Example with Variations and Metrics Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/track-insights-api.md Send a comprehensive insight for a single user, including feature flag variations and custom events with associated metrics. This is useful for detailed user journey analysis. ```json [ { "user": { "keyId": "user-456", "name": "Jane Smith", "customizedProperties": [ { "name": "country", "value": "USA" }, { "name": "plan", "value": "enterprise" } ] }, "variations": [ { "featureFlagKey": "recommendation-algorithm", "variation": { "id": "7d2e4f3b-8c6a-4d9e-b2f7-1a5c3e8b6d4f", "value": "algorithm-v2" }, "sendToExperiment": true, "timestamp": 1704067300000 } ], "metrics": [ { "route": "/api/checkout/complete", "type": "CustomEvent", "eventName": "purchase-completed", "numericValue": 299.99, "appType": "Web", "timestamp": 1704067350000 }, { "route": "/api/items/add-to-cart", "type": "CustomEvent", "eventName": "item-added", "numericValue": 1.0, "appType": "Web", "timestamp": 1704067250000 } ] } ] ``` -------------------------------- ### Clone and Run FeatBit with Docker Compose Source: https://github.com/featbit/featbit-docs/blob/main/pages/installation/docker-compose.mdx Clone the FeatBit repository and use Docker Compose to start the services. Choose the appropriate docker-compose file for Standalone, Standard, or Professional versions. ```bash git clone https://github.com/featbit/featbit cd featbit # for Standalone version, run docker compose up -d # for Standard version, run docker compose -f docker-compose-standard.yml up -d # for Professional version, run docker compose -f docker-compose-pro.yml up -d ``` -------------------------------- ### Authorization Header Example Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/flag-evaluation-api.md Include your environment secret key in the Authorization header for API authentication. Refer to FAQ documentation for obtaining the secret key. ```text Authorization: your-environment-secret-key ``` -------------------------------- ### Simple Insight Tracking Example Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/track-insights-api.md A basic example of the request body for the Track Insights API, containing user information and a feature flag variation. This structure can be extended to include custom metrics. ```json [ { "user": { "keyId": "user-123", "name": "John Doe", "customizedProperties": [ { "name": "email", "value": "john.doe@example.com" }, { "name": "role", "value": "premium" } ] }, "variations": [ { "featureFlagKey": "new-checkout-flow", "variation": { "id": "3c9f8e2a-5b1d-4f7c-a3e6-8d4b2c1a9f5e", "value": "true" }, "sendToExperiment": true, "timestamp": 1704067200000 } ], "metrics": [] } ] ``` -------------------------------- ### Example Feature Flag Evaluation Response Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/flag-evaluation-api.md This is an example of a successful response when evaluating multiple feature flags. It includes flag keys, variation details, match reasons, and experiment tracking information. ```json [ { "key": "new-dashboard-design", "variation": { "id": "08aceef3-5513-4b38-80ad-4b27bebe8871", "type": "boolean", "value": "true", "matchReason": "premium user rule", "sendToExperiment": true } }, { "key": "theme-color", "variation": { "id": "c5364cfd-292a-4e06-8e8e-b0ae7387f791", "type": "string", "value": "dark", "matchReason": "default", "sendToExperiment": false } }, { "key": "max-file-upload-size", "variation": { "id": "34683e86-b436-4694-b335-29628c0896e3", "type": "number", "value": "104857600", "matchReason": "premium user rule", "sendToExperiment": true } } ] ``` -------------------------------- ### Client-Side API: Response Example Source: https://github.com/featbit/featbit-docs/blob/main/pages/sdk/retrieve-feature-flags.mdx This is an example JSON response from the client-side API. It includes feature flag details, evaluation results, and a `timestamp` field that should be used for subsequent polling requests. ```json { "messageType":"data-sync", "data":{ "eventType":"full", "userKeyId":"bot-id", "featureFlags":[ { "id":"hello-world", "variation":"false", "variationType":"boolean", "variationId":"3f02a597-a150-4c3f-83b9-27a2de80c7dc", "matchReason":"flag disabled", "variationOptions":[ { "id":"fafb6319-9270-4a4b-b2c3-12d2be29e69a", "value":"true" }, { "id":"3f02a597-a150-4c3f-83b9-27a2de80c7dc", "value":"false" } ], "sendToExperiment":false, "timestamp":1712755780494 } ] } } ``` -------------------------------- ### Batch Example with Multiple Users Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/track-insights-api.md Send insights for multiple users in a single request to optimize network requests. Each user object can contain their respective feature flag variations and metrics. ```json [ { "user": { "keyId": "user-001", "name": "Alice" }, "variations": [ { "featureFlagKey": "feature-x", "variation": { "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d", "value": "control" }, "sendToExperiment": true, "timestamp": 1704067200000 } ], "metrics": [] }, { "user": { "keyId": "user-002", "name": "Bob" }, "variations": [ { "featureFlagKey": "feature-x", "variation": { "id": "f9e8d7c6-b5a4-4938-8271-6a5b4c3d2e1f", "value": "treatment" }, "sendToExperiment": true, "timestamp": 1704067300000 } ], "metrics": [] } ] ``` -------------------------------- ### FeatBit CLI Commands for Project and Flag Management Source: https://github.com/featbit/featbit-docs/blob/main/pages/feature-flags/flag-lifecycle-management/set-cleanup-expectations.mdx Use these FeatBit CLI commands to manage projects, list flags, inspect environments, and audit flag history. Ensure you have the FeatBit CLI installed and configured. ```bash featbit project list --json ``` ```bash featbit project get --project-id --json ``` ```bash featbit project flags --project-id --all --json ``` ```bash featbit project flags --project-id --tags --all --json ``` ```bash featbit flag list --env-id --all --json ``` ```bash featbit flag audit-logs --env-id --flag-key --all --json ``` ```bash featbit flag evaluate --user-key --env-secret --flag-keys --json ``` ```bash featbit flag archive --env-id --flag-key --json ``` -------------------------------- ### Next.js App Component Setup Source: https://github.com/featbit/featbit-docs/blob/main/pages/_app.mdx This is the default App component for a Next.js application. It imports global styles and renders the current page component with its props. ```javascript import '../styles/main.css' export default function App({ Component, pageProps }) { return } ``` -------------------------------- ### Client-Side API: Initial Request Source: https://github.com/featbit/featbit-docs/blob/main/pages/sdk/retrieve-feature-flags.mdx Use this `curl` command to make an initial request to the client-side API to retrieve all feature flags for a user. Include your client environment secret in the `Authorization` header and provide user-specific `customizedProperties`. ```bash curl -X POST {Host}/api/public/sdk/client/latest-all \ -H 'Content-Type: application/json' \ -H 'Authorization: client-env-secret' \ -d '{ "keyId": "bot-id", "name": "bot", "customizedProperties": [ { "name": "level", "value": "high" }, { "name": "location", "value": "us" } ] }' ``` -------------------------------- ### Forbidden Response Example Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/api-access-tokens.md This JSON response indicates a forbidden access attempt, typically due to insufficient permissions or a deactivated token. ```json { "success": false, "errors": [ "Forbidden" ], "data": null } ``` -------------------------------- ### Use 'json' Handlebars Helper in Template Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/webhooks.mdx Example of using the custom 'json' Handlebars helper to display the JSON string representation of an object. ```handlebars {{json theObject}} ``` -------------------------------- ### Okta SSO Configuration Parameters Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/single-sign-on/okta.mdx These are the parameters required for configuring Okta as an SSO provider in FeatBit. Ensure you replace placeholder values with your actual Okta account details. ```json { "clientId": "0oaiz2sm4iWjBAhCD697", "clientSecret": "ZfPgmM_M5TNbco0U_uXdozlEY9YQlwIJjKHCLeposPGOE93gWEIe_Te8jN282GWy", "tokenEndpoint": "https://trial-4157686.okta.com/oauth2/v1/token", "clientAuthenticationMethod": "client_secret_post", "authorizationEndpoint": "https://trial-4157686.okta.com/oauth2/v1/authorize", "userEmailClaim": "email", "scope": "openid profile email" } ``` -------------------------------- ### Use 'eq' Handlebars Helper in Template Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/webhooks.mdx Example of using the custom 'eq' Handlebars helper to conditionally render content based on a value's equality. ```handlebars {{#eq value "a"}} A {{/eq}} ``` -------------------------------- ### Configure FeatBit Portal Public Accessibility Source: https://github.com/featbit/featbit-docs/blob/main/pages/installation/faq.md Set the API_URL and EVALUATION_URL environment variables in your docker-compose.yml to make the FeatBit UI accessible from external machines or the internet. Ensure the machine running FeatBit has a public IP or domain name. ```yaml ui: image: featbit/featbit-ui:latest container_name: ui environment: # example: 192.168.56.1:5000 - API_URL=http://[REPLACE_WITH_THE_API_SERVER_IP_OR_DOMAIN] # keep it like this, this is for tutorial - DEMO_URL=https://featbit-samples.vercel.app # example: 192.168.56.1:5100 - EVALUATION_URL=http://[REPLACE_WITH_THE_EVALUATION_SERVER_IP_OR_DOMAIN] depends_on: - api-docs-server ports: - "8081:80" networks: - featbit-network ``` -------------------------------- ### Response for Single Feature Flag Evaluation Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/flag-evaluation-api.md This is an example response when evaluating a single feature flag. The response is an array containing a single element representing the evaluated flag. ```json [ { "key": "new-dashboard-design", "variation": { "id": "ac727073-8cc5-4ec5-9405-59737ea737bb", "type": "boolean", "value": "false", "matchReason": "flag disabled", "sendToExperiment": false } } ] ``` -------------------------------- ### Flag Evaluation Request Body Example Source: https://github.com/featbit/featbit-docs/blob/main/pages/api-docs/flag-evaluation-api.md Construct a JSON request body to evaluate feature flags for a specific user. You can filter flags by tags, keys, and specify a timestamp for changes. ```json { "user": { "keyId": "user-123", "name": "John Doe", "customizedProperties": [ { "name": "country", "value": "US" }, { "name": "plan", "value": "premium" } ] }, "filter": { "tagFilterMode": "and", "tags": ["frontend", "mobile"], "keys": [] } } ``` -------------------------------- ### Server-Side API: Initial Request Source: https://github.com/featbit/featbit-docs/blob/main/pages/sdk/retrieve-feature-flags.mdx Make an initial request to the server-side API to retrieve raw feature flags and segment data. Provide your server environment secret in the `Authorization` header. This endpoint does not require a `timestamp` parameter for the initial call. ```bash curl -H "Authorization: server-env-secret" {Host}/api/public/sdk/server/latest-all ``` -------------------------------- ### Auth0 SSO Configuration JSON Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/single-sign-on/auth0.mdx This JSON object represents the configuration parameters required for setting up Auth0 as an SSO provider for FeatBit. Ensure all values are replaced with your actual credentials and endpoints. ```json { "clientId": "eI9NSqLyw03WqKhMT2h1McqNf4Wre86W", "clientSecret": "ZghOBGxQrrcj1Iw3DdJiRE5k6TgPFJT_epSUG7v0XPibS7IWxRdIL8_bS7OLyw1J", "tokenEndpoint": "https://dev-nyi0i4bvcwpfd0ca.us.auth0.com/oauth/token", "clientAuthenticationMethod": "client_secret_post", "authorizationEndpoint": "https://dev-nyi0i4bvcwpfd0ca.us.auth0.com/authorize", "userEmailClaim": "email", "scope": "openid profile email" } ``` -------------------------------- ### Export Experiment Metric Events to Azure Event Hub Source: https://github.com/featbit/featbit-docs/blob/main/pages/data-import-and-export/data-export.mdx Use this command to run the pipeline for exporting Experiment Metric Events to Azure Event Hub. Verify that the event type and pipeline name match the desired export. ```bash ./FeatBit.DataExport -e "32f6be54-6796-44dd-bc82-f4824b0da13c" -t "2023-12-12 07:41:51.288" -c "Host=127.0.0.1;Protocol=http;Port=8123;Database=featbit" -s 1000 -i 100 -b 5 -a "Endpoint=sb://featbitexportdata.servicebus.windows.net/;SharedAccessKeyName=flagvalueevents;SharedAccessKey=Q0sXMCyF***FAKE***Yz/kUnGu1wAbjeRnB+AEhJIzHhU=" --azevthubplan "Basic" --azevthubname "flagvaluecapture" --eventtype "CustomEvent" --pipeline "CustomEventToAzureEventHub" ``` -------------------------------- ### Optional FeatBit MCP Tools for Feature Flag Management Source: https://github.com/featbit/featbit-docs/blob/main/pages/feature-flags/flag-lifecycle-management/set-cleanup-expectations.mdx These FeatBit MCP tools can be used as alternatives to the FeatBit CLI when FeatBit MCP is already configured in the agent environment. They provide programmatic access to flag data and evaluation. ```javascript GetProjectFeatureFlags(projectId, tags, fetchAll: true) ``` ```javascript GetFeatureFlags(envId, name, tags, isEnabled, isArchived, fetchAll: true) ``` ```javascript GetFeatureFlag(envId, key) ``` ```javascript GetFeatureFlagAuditLogs(envId, flagKey, fetchAll: true) ``` ```javascript EvaluateFeatureFlags(userKeyId, flagKeys, tags, tagFilterMode) ``` ```javascript ArchiveFeatureFlag(envId, key) ``` -------------------------------- ### Growthbook Experiment Assignment Query Source: https://github.com/featbit/featbit-docs/blob/main/pages/integrations/data-analytic/growthbook.mdx Use this SQL query to fetch FeatBit's feature flag usage data from ClickHouse for experiment assignments in Growthbook. Ensure the 'event' is 'FlagValue' and 'sendToExperiment' is true. ```sql SELECT JSONExtract(properties, 'userKeyId', 'String') as user_id, timestamp as timestamp, JSONExtract(properties, 'variationId', 'String') as variation_id, 'experiment_001' as experiment_id FROM events WHERE event = 'FlagValue' AND JSONExtract(properties, 'sendToExperiment', 'Bool') = true ```