slackapi / slackapi/bolt-js

Enable developers to log request/response

Open
#486 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement
Dominant language
TypeScript
Stars
2.9k
Forks
445
Avg merge
1d 3h
Merged PRs (30d)
28

Description

Description

I would like to log all interactions with Slack so that I can see what gets sent across the wire.

What type of issue is this? (place an x in one of the [ ])
  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion
Requirements (place an x in each of the [ ])
  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Getting the Request information is fairly easy by doing the following:

// Show Received payload
app.use(async ({ next, payload, body, client, context }) => {
    util.prettyJSON(payload, 'RECEIVED (payload): ');
    await next();
});

However, getting the Response information has been more challenging. So far, I am doing the following, which works, but probably isn't the best way:

const logSent = config => {
    util.prettyJSON(config, 'SENT: ')
    return config;
}

// Show sent payload
app.client.axios.interceptors.request.use(logSent, error => Promise.reject(error));
app.use(async ({ next, client }) => {
    if (client.fixed !== true) {
        client.axios.interceptors.request.use(logSent, error => Promise.reject(error));
        client.fixed = true;
    }
    await next();
});

I would prefer to do this at a framework level in one place, rather than in each individual listener. Is there a better way?

Reproducible in:

package version: 2.0.1

node version: v13.12.0

OS version(s): Mac 10.15.3

Steps to reproduce:
  1. Send a request to bot
  2. Send a response via .say()
  3. Send a response via api.client.[]
  4. Send a response via listener's client.[]
Expected result:
  1. Send a request to bot and log the request
  2. Send a response via .say() and log the response
  3. Send a response via api.client.[] and log the response
  4. Send a response via listener's client.[] and log the response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names app.use middleware and app.client.axios interceptors as current entry points; start by tracing how requests from .say(), api.client.[], and listener client.[] flow through the framework. Done means a framework-level mechanism can log incoming requests and outgoing responses for all four paths, with coverage for those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
api, backend, observability
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.