Three Ways to Integrate Slack With Heroku — DZone Web Dev

On December 1, Salesforce made the decision to acquire the industry-leading business communication platform, Slack, in order to combine functionality with the Salesforce Customer 360 software product. Heroku, a cloud-based platform as a service (PaaS) offering, has been a Salesforce product since being purchased ten years ago, nearly to the day.

As a result of this announcement, I thought it would be fun to demonstrate how to integrate Slack with three Heroku add-ons. For this article, the following products will be utilized:

My goal is to demonstrate how Slack-a tool already used for intra-team communication-can also be the target for application status updates, logging, and unexpected issues.

Activity To Go

Installing the Activity To Go add-on can be done using the Heroku user interface or the following command:

heroku addons:create activitytogo:free

Once installed, the Activity To Go dashboard is available via the Heroku user interface:

Once launched, the Dashboard appears as shown below:

Connecting to Slack

In order to accomplish this, the Add subscription button is used from the Activity To Go dashboard. That opens a new subscription form:

For the purposes of this example, I named my subscription Service Alerts and selected the Release and App options. Next, click the Configure button for “Send a Slack message.”

This pops up a modal to allow access to Slack:

From here, select the service-alerts Slack channel and choose the Allow button.

The Configure Slack action modal is displayed so the settings can be confirmed:

Upon pressing the Done button, you are ready to save the new subscription:

Once saved, the Activity To Go Dashboard is updated:

Coralogix Logging

Adding the Coralogix Logging add-on can be completed using the Heroku user interface or the following command:

heroku addons:create coralogix:free-30mbday

Once installed, the Coralogix dashboard can be displayed from the Heroku user interface:

Connecting to Slack

With the Slack instance open, launch the following URL:

Create a new Slack Webhook

Select the channel you wish to use (or create a new one) and single-click the Add Incoming Webhooks Integration button:

If the page does not automatically refresh, refresh it yourself and note the Webhook URL value.

Copy and paste the value in the Coralogix webhook form.

To validate, single-click the Test Configuration button. A message similar to what is displayed below should appear in the Slack instance:

At this point, Coralogix is now integrated with the specified Slack channel.

Configuring Alerts

  • Activity alert
  • Out of bounds error alert

Activity Alert

Out of Bounds Error Alert

Adding Rollbar

To install the Rollbar add-on, use the Heroku user interface or the following command:

heroku addons:create rollbar:free

The pom.xml file has already been updated in this repository to include the following dependency:

<dependency>
<groupId>com.rollbar</groupId>
<artifactId>rollbar-spring-boot-webmvc</artifactId>
<version>1.7.4</version>
</dependency>

Next, the application.yml file was updated to include the following settings:

rollbar:
access-token: ${ROLLBAR_ACCESS_TOKEN}
branch: master
environment: ${ROLLBAR_ENVIRONMENT}
code-version: ${HEROKU_RELEASE_VERSION}
spring:
application:
name: heroku-slack

Finally, sending information to Rollbar can be as easy as this example from the RollbarEvents:

@RequiredArgsConstructor
@Slf4j
@Component
public class RollbarEvents {
private final Environment environment;
private final RollbarConfigurationProperties rollbarConfigurationProperties;
private final Rollbar rollbar;

@PostConstruct
public void postConstruct() {
log.info("Started {} on port #{} using Rollbar accessToken={} ({})",
environment.getProperty("spring.application.name"),
environment.getProperty("server.port"),
SecurityUtils.maskCredentialsRevealPrefix(rollbarConfigurationProperties.getAccessToken(), 5, '*'),
rollbarConfigurationProperties.getEnvironment());
rollbar.info(String.format("Started %s on port #%s using Rollbar accessToken=%s (%s)",
environment.getProperty("spring.application.name"),
environment.getProperty("server.port"),
SecurityUtils.maskCredentialsRevealPrefix(rollbarConfigurationProperties.getAccessToken(), 5, '*'),
rollbarConfigurationProperties.getEnvironment()));
}
}

The following configuration items were set up in the Heroku instance for use by Rollbar:

Connecting to Slack

After selecting my existing access token, I selected the #application-errors channel and left all other defaults in place.

Pushing the Send Test Notification button will send a test message to Slack. Navigating to Slack and the #application-errors channel show the following test message:

Our Example — A Simple RESTful Application

https://gitlab.com/johnjvester/heroku-slack

The heroku-slack service returns the Artist object in all available URIs.

The object is quite simple and is displayed below:

@AllArgsConstructor
@NoArgsConstructor
@Data
public class Artist {
private String name;
}

Please review the heroku-slack repository for additional information on this RESTful service.

Interacting With Slack

Deploying a New Release

Heroku Dyno Configuration Changes

Making a Simple Request

Generating a Bad Request

Trigging off the ERROR alert, Coralogix Logging posts the following message in the #coralogix channel in Slack:

Based upon the Java code updates and the GlobalControllerExceptionHandler, Rollbar posts the following message in the #application-errors channel in Slack:

The Rollbar product provides additional value in its ability to assign the error to a configured team member, directly from the Slack instance:

Please note that the error level can also be updated directly from Slack.

Summary Information

The Coralogix Logging alert summary provides a nice break-down of all the alerts that have been captured:

Coralogix Logging provides a high-level dashboard as well:

Rollbar provides an advanced dashboard which can even link directly to the source code:

The Items view provides a high-level summary of each error as well:

Conclusion

In the end, the project in Heroku contains the following add-ons. As you can see, for this demonstration, none of the employed items will carry a monthly cost for use:

This article focused on three add-ons currently available in the Heroku catalog. Using a keyword search of “slack” provided a list of twenty options ready for use with the Slack program. Of course, more options likely exist via standard webhook connectivity.

Heroku was designed to help developers focus on meeting the business needs of their application. Integrating with Slack is another example of how feature teams can remain focused while keeping a pulse on their dynos running in Heroku. After all, many feature teams are likely already using Slack.

If you are interested in the source code for this article, please review the following repository on GitLab:

https://gitlab.com/johnjvester/heroku-slack

Have a really great day!

Originally published at https://dzone.com.

Information Technology professional with 25+ years expertise in application architecture, design and development. Agile project and team management.

Get the Medium app