Skip to content

feat: add instrumentation to address error rates#600

Open
zimeg wants to merge 5 commits intomainfrom
zimeg-feat-instrument
Open

feat: add instrumentation to address error rates#600
zimeg wants to merge 5 commits intomainfrom
zimeg-feat-instrument

Conversation

@zimeg
Copy link
Copy Markdown
Member

@zimeg zimeg commented May 1, 2026

Summary

This PR adds instrumentation to address error rates with a User-Agent header added to requests 🎹

Preview

With additional logging in development to reveal we find these headers for different techniques:

API Method

@slack:slack-github-action/3.0.2 @slack:web-api/7.15.0 node/24.15.0 linux/6.12.76-linuxkit

Webhook

@slack:slack-github-action/3.0.2 axios/1.15.0 node/24.15.0 linux/6.12.76-linuxkit

CLI

🎺 Instrumentation is left to adjacent implementations for installations and particular command usage.

Requirements

@zimeg zimeg added this to the 3.1 milestone May 1, 2026
@zimeg zimeg self-assigned this May 1, 2026
@zimeg zimeg added enhancement New feature or request semver:patch labels May 1, 2026
@zimeg zimeg requested a review from a team as a code owner May 1, 2026 03:28
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 1, 2026

🦋 Changeset detected

Latest commit: 709a4d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@slack/slack-github-action Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.86%. Comparing base (feba1e2) to head (709a4d6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #600   +/-   ##
=======================================
  Coverage   99.86%   99.86%           
=======================================
  Files           7        7           
  Lines         718      736   +18     
=======================================
+ Hits          717      735   +18     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member Author

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏛️ A few comments follow for the amazing reviewers!

Comment thread src/config.js
Comment on lines +140 to +144
this.axios.defaults.headers.common["User-Agent"] =
`${packageJson.name.replace("/", ":")}/${packageJson.version} ` +
`axios/${this.axios.VERSION} ` +
`node/${process.version.replace("v", "")} ` +
`${os.platform()}/${os.release()}`;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪬 thought: We should prefer the @slack/webhook package if support is added for Workflow Builder but for now we match the format:

https://github.com/slackapi/node-slack-sdk/blob/4af912df43532331d17bddfd4f9c47157e5160ea/packages/webhook/src/instrument.ts#L12-L15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 💯 recently we had to update the user agent from the web-api so that it is compliant with latin1, but I think this implementation does not need this patch since we aren't including the process.title

Comment thread test/config.spec.js
Comment on lines +164 to +185
it("adds metadata to webapi with package name and version", async () => {
const stub = sinon.stub();
const original = Object.getOwnPropertyDescriptor(
webapi,
"addAppMetadata",
);
Object.defineProperty(webapi, "addAppMetadata", {
value: stub,
configurable: true,
});
try {
mocks.core.getInput.withArgs("method").returns("chat.postMessage");
mocks.core.getInput.withArgs("token").returns("xoxb-example");
new Config(mocks.core);
assert.ok(stub.calledOnce);
const { name, version } = stub.firstCall.args[0];
assert.equal(name, "@slack/slack-github-action");
assert.ok(version);
} finally {
Object.defineProperty(webapi, "addAppMetadata", original);
}
});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 note: We don't capture actual requests in tests at the moment so this is our current approach to checking expected behavior.

🔭 thought: Recent node improvements might allow us to improve how we test overall:

A little-known fact is that there is a builtin way to mock fetch.

📚 https://nodejs.org/learn/test-runner/mocking#apis

Comment thread package.json
@@ -1,5 +1,5 @@
{
"name": "slack-github-action",
"name": "@slack/slack-github-action",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 💯 praise 🙏

Copy link
Copy Markdown
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job 💯

Comment thread package.json
@@ -1,5 +1,5 @@
{
"name": "slack-github-action",
"name": "@slack/slack-github-action",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 💯 praise 🙏

Comment thread src/config.js
Comment on lines +140 to +144
this.axios.defaults.headers.common["User-Agent"] =
`${packageJson.name.replace("/", ":")}/${packageJson.version} ` +
`axios/${this.axios.VERSION} ` +
`node/${process.version.replace("v", "")} ` +
`${os.platform()}/${os.release()}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 💯 recently we had to update the user agent from the web-api so that it is compliant with latin1, but I think this implementation does not need this patch since we aren't including the process.title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants