Integrating your Flagsmith project with Datadog: A step by step guide with real-time metrics

By Abhishek Agarwal on January 24, 2023

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

  1. Login to Datadog by visiting this URL – https://app.datadoghq.com/ (or https://app.datadoghq.eu if you’re arriving from Europe)
  2. Navigate to “Integrations” on the left side bar
  3. Search for “Flagsmith”. Screenshot below shows Flagsmith integration available to add. 
  4. Click on the “+ Available” sign 
  5. Click on “Install Integration” as shown below
  1. Once done, you should see the option to Configure the integration
  1. Click on the “Datadog API Key” Hyperlink (which will take you to https://app.datadoghq.com/organization-settings/api-keys
  2. Copy the latest API Key from here. It should look like the one shown below. 

Add the Datadog integration on Flagsmith

  1. Visit https://app.flagsmith.com/projects and select the project that manages feature flags for your current application.
  1. Click on the “Integrations” tab on the left side bar. 
  1. Click on “Add integration” beside Datadog
  2. It will ask you for “Base URL” and “API Key”
    1. 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).
    2. For API Key: Paste the one you copied above when adding the Flagsmith integration to Datadog. 
  1. 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. 

BeforeAfter

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:

  1. env – this indicates the environment in which the flag change happened. In my case it was “development”
  2. source – indicates the origin of the event
  3. 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. 

  1. Navigate to https://app.datadoghq.com/monitors/manage 
  1. Click on “New Monitor”
  2. Now, under “Custom” click on “Event”. This should take you to https://app.datadoghq.com/monitors/create/event 
  3. 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. 
  1. Set the alert conditions. I am setting it to alert when there is 1 such occurrence. 
  2. 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.