GithubHelp home page GithubHelp logo

isabella232 / integration-platform-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from getsentry/integration-platform-example

0.0 0.0 0.0 2.13 MB

An example kanban application which explores the ways developers can build apps on Sentry's integration platform

Home Page: https://docs.sentry.io/product/integrations/integration-platform/

License: Apache License 2.0

JavaScript 0.95% Python 46.49% TypeScript 51.19% Makefile 0.82% HTML 0.24% Dockerfile 0.31%

integration-platform-example's Introduction

Integration Platform Example

So you want to integrate with the Sentry Integration Platform. Great! We're looking forward to it ๐ŸŽ‰ That's why we built out this codebase; clone and fork away!

This repository contains some starter code for interfacing with the Integration Platform that is meant to be a tool for your reference. It demos an example kanban application which will be integrating with Sentry to auto-generate tickets, links and create a richer user experience.

Kanban application user interface

In it, we'll be covering the following features:

  • Handling Installation (with OAuth)
  • Using the Sentry API
  • Verifying Installations
  • Handling Uninstallations
  • Handling Webhooks
    • Issues
    • Comments
    • Alerts
  • Implementing UI Components
    • Issue Linking
    • Alert Rule Actions

If we missed something, or you're still having trouble, feel free to create an issue, and we'll see what we can do! Happy Developing!

Table of Contents

Getting Started

Prerequisites

  • Sentry - You must be either a Manager or Owner of an organization on Sentry.
  • Docker - This demo application uses Docker to setup and communicate between its different services.
  • Disable your adblocker - This is a common pitfall that developers fall into when building on Sentry, doing it early can save your time down the line!
  • Select a codebase - This demo application comes with a mock frontend and a choice between two backends, one in Node (Express, Sequelize, TypeScript) and another in Python (Flask, SQLAlchemy). Pick the commands and environment that is more appropriate for your implementation.
  • A local PostgreSQL DB Client (Optional) - Great for viewing changes on objects, and debugging, removing, or editing data. We suggest Postico.

Step 0: Choose an Integration

Before setting anything up, you must determine the type of integration you're building on Sentry's Integration Platform.

Public integrations are meant to be accessed by all Sentry Customers, regardless of whether or not they belong to your organization.

If you only wish to provide an application to your team or organization, you should probably develop an Internal integration. These are far easier to get up and running, as they skip the OAuth installation process and become immediately available for webhooks, UI components or API usage.

This tutorial assumes you're building a public integration, but most of the steps are identical for internal integrations unless stated otherwise.

Step 1: Setup ngrok

To get started, you'll need access to ngrok. ngrok is a tool which lets you expose your locally running servers to the internet. Since Sentry requires an HTTP connection to your application, this is the easiest way to test changes without having to deploy constantly. You can find installation instructions here.

Make sure you add an authtoken in order to generate a configuration file.

Open that configuration file and set it up as follows:

version: "2"
authtoken: <YOUR AUTHTOKEN HERE>

tunnels:
  acme-frontend:
    proto: http
    # Make sure this addr matches REACT_APP_PORT in .env
    addr: 3000 
  acme-backend-py:
    proto: http
    # Make sure this addr matches FLASK_RUN_PORT in .env
    addr: 5100 
  acme-backend-ts:
    proto: http
    # Make sure this addr matches EXPRESS_LISTEN_PORT in .env
    addr: 5200 

This will let you easily set up your tunnels with:

ngrok start --all

With ngrok running, you'll be presented with an interface that might look like the following:

ngrok

Session Status      online
Account             Sentry (Plan: Pro)
Version             3.0.3
Region              United States (us)
Latency             96.595653ms
Web Interface       http://127.0.0.1:4040
Forwarding          https://random-uuid-frontend.ngrok.io -> http://localhost:3000 
Forwarding          https://random-uuid-backend-py.ngrok.io -> http://localhost:5100 
Forwarding          https://random-uuid-backend-ts.ngrok.io -> http://localhost:5200 

Connections         ttl     opn     rt1     rt5     p50     p90
                    0       0       0.00    0.00    0.00    0.00

Take a note of the forwarding addresses (ending with .ngrok.io), as you'll need them to setup your integration within Sentry. You can identify which address coordinates with which server by the port they map to on your local machine. By default:

[Frontend address]           -> http://localhost:3000 
[Python backend address]     -> http://localhost:5100 
[Typescript backend address] -> http://localhost:5200

Though, if you change your environment variables in Step 3, from their default values, this will not be the case.

Step 2: Setup Sentry

Next, we'll be setting up an integration for our app to connect to, and a project to which we'll send test errors. To set up the integration, perform the following steps in your Sentry instance.

  1. Click Settings > Developer Settings > Create New Integration > Public Integration
  2. Give your integration an appropriate name and author.
  3. Specify a Webhook and Redirect URL with your ngrok forwarding address.
    • Webhook URL: <YOUR BACKEND NGROK ADDRESS>/api/sentry/webhook/
    • Redirect URL: <YOUR FRONTEND NGROK ADDRESS>/sentry/setup/
      Using the above example, with the python backend, it may look like this:
    • Webhook URL: https://random-uuid-backend-py.ngrok.io/api/sentry/webhook/
    • Redirect URL: https://random-uuid-frontend.ngrok.io/sentry/setup/

Note: On the free plan for ngrok, if your service restarts, you will be issued a new forwarding address. If this happens, be sure to update these URLs in Sentry to keep your app functional while developing or testing.

  1. Ensure 'Verify Installation' is checked.
  2. Ensure 'Alert Rule Action' is checked.
  3. In the textbox for 'Schema', paste in the entire integration-schema.json file
  4. Enable 'Issue & Event - Read' permissions.
  5. Enable the webhooks
    • issue (for created, resolved, assigned, and ignored actions)
    • comment (for created, edited, and deleted actions)

Note: We aren't enabling error.created webhooks for this demo. See more on this decision here.

  1. Click 'Save Changes'.
  2. Make a note of the Client ID and Client Secret.

This demo integration can helpfully create errors in Sentry to trigger webhooks while developing, but you'll need to issue this app a DSN. We'll do this by setting a project.

  1. Click Projects > Create Project.
  2. Select React (JS).
  3. Give your project an appropriate name (for example: Demo Integration).
  4. Click Create Project.
  5. Make a note of the DSN URL.
    • It is a URL similar to the following if you're using Sentry SaaS: https://[email protected]/123456

Next, we'll be taking these values from Sentry and putting together our application's environment.

Step 3: Setup your environment

We've included a .env.sample file for you to refer to when building out your environment. To set it up, change the filename from .env.sample to .env. You can modify any of these variables as you see fit, but the following require changes to work as intended:

  • SENTRY_CLIENT_ID: The Client ID from Step 2
  • SENTRY_CLIENT_SECRET: The Client Secret from Step 2
  • REACT_APP_SENTRY_DSN: The DSN from Step 2
  • REACT_APP_BACKEND_URL: The ngrok forwarding address of your chosen backend from Step 1

Note: If you change REACT_APP_PORT, FLASK_RUN_PORT, or EXPRESS_LISTEN_PORT, you may have to reconfigure your ngrok setup and Integration URLs in Sentry

Great, now we're ready to serve our application!

Step 4: Build and serve the codebase

This example code comes with a mock frontend and a choice between two backends, one in NodeJS (Express + TS) and another in Python (Flask). To launch the application, you'll need to install Docker and ensure it is running.

Now you can spin up the project of your choice with:

make serve-python # A python server built on Flask and SQLAlchemy
# OR
make serve-typescript # A typescript node server built on Express and Sequelize

This command will build the Docker images needed to run the application (a Postgres database, a web application, and your chosen backend), and spin them up, all in one step! Once the server logs calm down, your application should be good to go! If you make any changes to the environment variables after this point, be sure to rebuild the images with:

make setup-python 
# OR
make setup-typescript 

Now the app is ready to test! Continue on to the Using your Integration section to playground your application as you make changes and trigger webhooks in Sentry. There are also some helpful debugging commands which you can check out via:

make help

Using your Integration

Building an app on our integration platform gives you access to lots of Sentry features. This section will detail how to go about testing them while building your integration.

Webhooks

UI Components

API Usage

Publishing

Once you've finalized, tested and deployed your application, you can submit a publication request on Sentry. Once it's reviewed, it'll be accessible to install by anyone on the Sentry platform.

Check out the docs to learn more about publishing.

Credits

integration-platform-example's People

Contributors

dependabot[bot] avatar leeandher avatar mgaeta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.