Integrating your Flagsmith project with Datadog: A step by step guide with real-time metrics
Integrating Flagsmith with your application offers a wide range of feature toggling capabilities out of the box. This guide walks us through the steps of integrating Datadog with our application to track all feature flag updates.
How does the Datadog integration help?
Do to the enormous power that Feature flags add to your application, they are quickly becoming an essential part of a company’s infrastructure. As that happens, the criticality of their performance rises and it becomes more important to monitor them to make sure everything is working as intended. With the Flagsmith and Datadog integration, you can monitor the performance of your feature flags alongside the rest of your tech stack!
Let’s get started!
In this tutorial we will assume that you already have an application that is using Flagsmith for feature flag management. If that’s not the case, please refer to https://flagsmith.com/blog/ and follow the tutorial for your programming language.
Add the Flagsmith integration on Datadog
- Login to Datadog by visiting this URL – https://app.datadoghq.com/ (or https://app.datadoghq.eu if you’re arriving from Europe)
- Navigate to “Integrations” on the left side bar
- Search for “Flagsmith”. Screenshot below shows Flagsmith integration available to add.
- Click on the “+ Available” sign
- Click on “Install Integration” as shown below
- Once done, you should see the option to Configure the integration
- Click on the “Datadog API Key” Hyperlink (which will take you to https://app.datadoghq.com/organization-settings/api-keys)
- Copy the latest API Key from here. It should look like the one shown below.
Add the Datadog integration on Flagsmith
- Visit https://app.flagsmith.com/projects and select the project that manages feature flags for your current application.
- Click on the “Integrations” tab on the left side bar.
- Click on “Add integration” beside Datadog
- It will ask you for “Base URL” and “API Key”
- For Base URL: enter https://api.datadoghq.com if you are using the US site, or https://api.datadoghq.eu if you are using the EU site. (This should be in sync with the base URL on your browser’s address bar).
- For API Key: Paste the one you copied above when adding the Flagsmith integration to Datadog.
- Click “Save”
Congrats! You have completed the Flagsmith <-> Datadog integration.
Leveraging the integration for your application
Now that the integration is complete, let’s explore the ways to utilize it.
First, let’s try toggling one of the feature flags from our project via the Flagsmith UI.
I made changes to 2 features named “datadog_event_test” and “deposit_enabled” by turning both of them off. The screenshot below shows the before and after scenario from the Flagsmith UI.
Let’s navigate to the Events section on Datadog.
These events appear here magically without any other effort. These events contain explicit information about the following:
- env – this indicates the environment in which the flag change happened. In my case it was “development”
- source – indicates the origin of the event
- Description – Contains information about what was changed and who changed it
Thus, we have a complete audit for our feature flag updates in a nice and clean UI.
Making the most out of the Datadog integration
We saw logging events above, now let’s go one step further and create monitors for these events. These monitors can prove to be very helpful when there is an unexpected change.
We can send an alert to the owning members for all changes. This way, they won’t have to rely on checking logs daily.
Ideally monitor alerts should be put in for critical changes only. For example, if a flag has been deleted or updated on the production environment.
Let’s create a monitor that triggers an alert when a feature is deleted in production.
- Navigate to https://app.datadoghq.com/monitors/manage
- Click on “New Monitor”
- Now, under “Custom” click on “Event”. This should take you to https://app.datadoghq.com/monitors/create/event
- In the search query, I have put the following:
- source:my_apps env:production message:(“Flag Remote Config Deleted *” OR “Flag state Remote Config value updated *”)
- Feel free to update the query as per your requirement
- The above query evaluates to true when
- There is an event from the source: “my_apps” AND
- Environment is “production” AND
- Event description contains text related to “Deleted” or “updated” indicating that a flag was deleted or updated.
- Set the alert conditions. I am setting it to alert when there is 1 such occurrence.
- Fill in the details based on your team setup for alerting when this occurs.
Our monitor is now ready. This will trigger when there is an event satisfying the above conditions.
Navigate back to the Flagsmith UI and update or delete some feature flags. I have deleted one feature and updated another. The corresponding events received are shown below:
On the Datadog monitor UI, it now shows alerts since there are 2 events that satisfy this condition. You can see below that the graph is in red.
Wrapping it up!
That’s all for this tutorial. Hope this helps make integration of Flagsmith and Datadog with your application seamless. Feel free to get in touch for any queries.