DevOps: Integration Of Twilio And Dynatrace Using Github Actions

Author: Pulkit Bindal

Introduction

The integration of Twilio and Dynatrace using GitHub Actions is a powerful solution for managing and monitoring your communications and performance in a seamless and efficient manner. The problem that many organizations face is the lack of a unified platform for managing and monitoring their communications and performance. This leads to a disjointed and time-consuming process, which can result in lost productivity and increased costs. The solution is to integrate Twilio and Dynatrace using GitHub Actions, which will provide a single platform for managing and monitoring all aspects of communications and performance.

The approach for integrating Twilio and Dynatrace using GitHub Actions involves several steps. First, the organization must establish a Github Actions workflow that will be used to automate the integration of Twilio and Dynatrace. This workflow will include the use of GitHub Actions to trigger the Twilio REST API and finally send data to Dynatrace UI. Next, the organization will need to configure the Dynatrace token. This will include setting up the appropriate access keys and tokens, as well as configuring the appropriate parameters for the Twilio and Dynatrace APIs. Finally, the organization will need to test the integration to ensure that it is working properly and that all of the desired functionality is available.

Overall, the integration of Twilio and Dynatrace using GitHub Actions is a powerful solution for managing and monitoring communications and performance in a seamless and efficient manner. It provides a unified platform for managing and monitoring all aspects of communications and performance, reducing the time and costs associated with disjointed processes. By following a structured approach, organizations can easily implement this solution and enjoy the benefits of a more streamlined and efficient process.

What is Twilio? 

Twilio is a cloud communications platform that enables developers to build, scale, and operate communications within software applications. Twilio provides a range of services, including voice and messaging APIs, contact center solutions, and video and voice calling. These services can be used to add features such as voice and SMS functionality to applications, as well as to build scalable, high-quality voice and messaging applications. Twilio’s platform is used by developers around the world to build applications that require communications functionality.

Why Integration of Twilio and Dynatrace?

There are a few potential reasons why an organization might want to integrate Twilio and Dynatrace:

Data integration: By integrating Twilio and Dynatrace, an organization can use the data from both systems together, which can provide a more complete picture of their operations and performance.

Improved visibility: The integration can help the organization to gain better visibility into the relationship between Twilio and Dynatrace performance, which can be useful for identifying and troubleshooting issues.

Enhanced functionality: The integration may allow the organization to build new functionality that combines the capabilities of both systems. For example, they might be able to use Twilio to send alerts or notifications based on Dynatrace data or to use Dynatrace data to optimize the performance of their Twilio-based applications.

Prerequisites: 

There are a few prerequisites that may be necessary for integrating Twilio and Dynatrace:

Accounts: In order to use the Twilio and Dynatrace APIs, you will need to have accounts with both platforms. You will also need to have the necessary permissions to access and modify the data in these accounts.

API keys: You will need to obtain API keys for both Twilio and Dynatrace in order to use the APIs. These keys will be used to authenticate your requests to the APIs.

Twilio Account SID: You will need to obtain an Account SID for Twilio in order to use the REST APIs. These IDs will be used to authenticate your requests to the APIs.

Development environment: Depending on how you plan to integrate Twilio and Dynatrace, you may need to set up a development environment with the necessary tools and libraries. For example, if you are using GitHub Actions to build the integration, you will need to have a GitHub account and be familiar with using Actions.

To integrate Twilio and Dynatrace using GitHub Actions, you will need to create a new GitHub Actions workflow and configure it to run when specific events occur in your repository (Let’s say “push”). The workflow will use the Twilio API to send messages.

Here are the steps you can follow to create a workflow that integrates Twilio and Dynatrace using GitHub Actions:

  1. Create a new GitHub Actions workflow by going to the Actions tab of your repository and clicking on the “New workflow” button.
  2. Configure the trigger for the workflow to run when specific events occur, such as when a new commit is pushed to the repository or when a pull request is opened.
  3. Use the Twilio API to fetch the SMS count and store it in a variable using GitHub actions. You can use the Twilio API to send SMS messages, phone calls, or other forms of communication.

Twilio API for SMS Count: http://api.twilio.com/2010-04-01/Accounts/<ACCOUNTID>/Usage/Records.json?Category=sms

  1. Keep Dynatrace Token handy with Ingest Events and Ingest Metrics permission open.
  2. Schedule the workflow to run at regular intervals, such as every 5 minutes or every hour, or maybe every day, to ensure that you are always aware of any issues or performance problems with your application.
  3. By integrating Twilio and Dynatrace using GitHub Actions, you can improve the monitoring and messaging capabilities of your application, and be alerted in real time of any issues or performance problems.
How to store Dynatrace Token as Secrets in GitHub UI

Here is a step-by-step process for storing the Dynatrace URL (DT_URL) and token (DT_TOKEN) as secrets in the GitHub UI:

  1. Go to the main page of your GitHub repository.
  2. Click on the “Settings” tab located on the right-hand side of the page.
  3. In the left-hand menu, select “Secrets”.
  1. Click on the “New repository secret” button.
  2. In the “Name” field, enter a name for the secret. For example, “DT_URL”.
  3. In the “Value” field, enter the actual Dynatrace URL.
  4. Click on the “Add secret” button to save the secret.
  5. Repeat steps 4-7 to add the second secret, the Dynatrace token (DT_TOKEN)
  6. Once you have added both secrets, you can use them in your GitHub Actions workflow file.
  7. In the workflow file, use the secrets by referencing them as ${{ secrets.SECRET_NAME }}.
  8. For example, ${{ secrets.DT_URL }} and ${{ secrets.DT_TOKEN }}.

Commit and push the changes to the repository, the workflow will now be able to access the secrets and use them to authenticate the API calls to Dynatrace.

Note: It is important to note that secrets are encrypted and can only be accessed by GitHub Actions running on the same repository. Also, make sure that you don’t share your secrets, and don’t check them into version control.

GitHub Action Workflow YAML File: 
name: Fetch and Send SMS Count Dyna

on:

  schedule:

    - cron: '*/2 * * * *'

jobs:

  Fetching:

    name: Fetch SMS Count 

    runs-on: ubuntu-latest

    steps:

      - name: Fetch SMS Count Number

        id: smsCount

        run: |

          records_json=$(curl 'https://api.twilio.com/2010-04-01/Accounts/<AccountID>/Usage/Records.usage_records.json?Category=sms' -u <AccountID>:<AuthKey>)

          smscount=$(echo "$records_json" | jq -r '.usage_records[0]["count"]')

          price=$(echo "$records_json" | jq -r '.usage_records[0]["price"]')

          echo "smscount: smscount is : $smscount"

          echo ::set-output name=smscount::"$smscount"      

          echo "price: price is : $price"

          echo ::set-output name=price::"$price"   

      - name: Sending Build Count

        uses: dynatrace-oss/dynatrace-github-action@v8

        with:

          url: '${{ secrets.DT_URL }}'

          token: '${{ secrets.DT_TOKEN }}'

          metrics: |

            - metric: "twilio_SMS_Count.Counter"

              value: "1.0"

              dimensions:

                project: "Twilio-REST-API"

                branch: "${{ github.ref }}"

                event: push

                sms-count: "${{ steps.smsCount.outputs.smscount }}"

                sms-price: "${{ steps.smsCount.outputs.price}}"

                owner: pulkit

Refer to the attached logs

How to fetch the metrics sent by Github Action in Dynatrace

Here is a step-by-step process for fetching the “twilio_SMS_Count.Counter” metric from the Data Explorer in Dynatrace:

  1. Log in to your Dynatrace tenant.
  2. Click on the “Data explorer” button located on the left-hand side of the page.
  1. In the search bar at the top of the page, enter “twilio_SMS_Count.Counter” and press enter.
  2. The metric will appear in the list of results, click on it.
  3. You will be taken to the metric’s detail view, where you can see the current value of the metric, as well as any associated data such as time series data, breakdowns and dimension.
  4. To see the time series data, click on the “Chart” tab.
  5. To see the breakdowns of the metric, click on the “Breakdown” tab.
  6. To see the dimension of the metric, click on the “Dimensions” tab.
  7. You can use the time range picker on the top right corner of the page, to filter the data based on a specific time range.
  1. You can also use the filter button on the top right corner of the page to filter the data based on specific conditions.
  2. Once you have the data you need, you can export it as a CSV or JSON file, or create a dashboard with the data.
How to create a dashboard and pin the Twilio SMS Count metric in it

Here is a step-by-step process for creating a dashboard named “TWILIO SMS” and pinning the metric named “twilio_SMS_Count.Counter” in Dynatrace:

  1. Log in to your Dynatrace tenant.
  2. Click on the “Dashboards” button located on the left-hand side of the page.
  1. Click on the “Create dashboard” button on the top right corner of the page.
  1. In the “Name” field, enter “TWILIO SMS” as the name of the dashboard.
  2. Click on the “Create” button to create the dashboard.
  3. Once the dashboard is created, you will be taken to the “Edit” view.
  4. In the search bar at the top of the page, enter “twilio_SMS_Count.Counter” and press enter.
  5. Click on the metric to add it to the dashboard.
  6. The metric will appear as a widget on the dashboard. You can adjust the size and position of the widget by dragging and dropping it.
  7. You can also customize the widget by clicking on the “Customize” button, you will have options to change the title, time range, and add different types of visualizations.
  8. You can also add other widgets to the dashboard, such as charts, tables, and custom HTML.
  9. Once you have finished customizing the dashboard, click on the “Save” button on the top right corner of the page.
  10. The dashboard will be saved and will be accessible to you and other users with access to the dashboard.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.