-
Notifications
You must be signed in to change notification settings - Fork 11
feat(slack): Link footer IDs to Sentry traces #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dcramer
wants to merge
1
commit into
main
Choose a base branch
from
feature/slack-footer-sentry-link
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
packages/junior/tests/unit/slack/footer-sentry-link.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| type MockDsn = { | ||
| host: string; | ||
| path?: string; | ||
| port?: string; | ||
| projectId: string; | ||
| protocol: "http" | "https"; | ||
| }; | ||
|
|
||
| function mockSentryClient(args: { dsn?: MockDsn; orgId?: number | string }) { | ||
| vi.doMock("@/chat/sentry", () => ({ | ||
| getClient: () => ({ | ||
| getDsn: () => args.dsn, | ||
| getOptions: () => ({ | ||
| orgId: args.orgId, | ||
| }), | ||
| }), | ||
| })); | ||
| } | ||
|
|
||
| async function loadFooter() { | ||
| return await import("@/chat/slack/footer"); | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| vi.doUnmock("@/chat/sentry"); | ||
| vi.resetModules(); | ||
| }); | ||
|
|
||
| describe("Slack footer Sentry links", () => { | ||
| it("links the ID to an Explore traces search from the active SaaS DSN", async () => { | ||
| mockSentryClient({ | ||
| dsn: { | ||
| protocol: "https", | ||
| host: "o123.ingest.us.sentry.io", | ||
| projectId: "4501", | ||
| }, | ||
| }); | ||
|
|
||
| const { buildSlackReplyBlocks, buildSlackReplyFooter } = await loadFooter(); | ||
| const footer = buildSlackReplyFooter({ | ||
| conversationId: "slack:C123:1700000000.000100", | ||
| }); | ||
|
|
||
| expect(buildSlackReplyBlocks("Hello world", footer)).toEqual([ | ||
| { | ||
| type: "markdown", | ||
| text: "Hello world", | ||
| }, | ||
| { | ||
| type: "context", | ||
| elements: [ | ||
| { | ||
| type: "mrkdwn", | ||
| text: "*ID:* <https://sentry.io/organizations/123/explore/traces/?query=gen_ai.conversation.id%3A%22slack%3AC123%3A1700000000.000100%22&project=4501&statsPeriod=14d|slack:C123:1700000000.000100>", | ||
| }, | ||
| ], | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("uses an explicit SDK orgId before the DSN host org ID", async () => { | ||
| mockSentryClient({ | ||
| dsn: { | ||
| protocol: "https", | ||
| host: "o123.ingest.sentry.io", | ||
| projectId: "4501", | ||
| }, | ||
| orgId: 456, | ||
| }); | ||
|
|
||
| const { buildSlackReplyFooter } = await loadFooter(); | ||
|
|
||
| expect(buildSlackReplyFooter({ conversationId: "conversation-1" })).toEqual( | ||
| { | ||
| items: [ | ||
| { | ||
| label: "ID", | ||
| url: "https://sentry.io/organizations/456/explore/traces/?query=gen_ai.conversation.id%3A%22conversation-1%22&project=4501&statsPeriod=14d", | ||
| value: "conversation-1", | ||
| }, | ||
| ], | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it("leaves the ID plain when the active DSN has no organization target", async () => { | ||
| mockSentryClient({ | ||
| dsn: { | ||
| protocol: "https", | ||
| host: "sentry.example.com", | ||
| projectId: "4501", | ||
| }, | ||
| }); | ||
|
|
||
| const { buildSlackReplyFooter } = await loadFooter(); | ||
|
|
||
| expect(buildSlackReplyFooter({ conversationId: "conversation-1" })).toEqual( | ||
| { | ||
| items: [ | ||
| { | ||
| label: "ID", | ||
| value: "conversation-1", | ||
| }, | ||
| ], | ||
| }, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same-named function with different semantics risks silent breakage
Low Severity
A private
toOptionalStringis introduced infooter.tsthat shares its name with the exportedtoOptionalStringincoerce.ts, but their behavior diverges: the footer version handlesnumberinputs (converting them viaString()) and trims returned strings, while the coerce version only accepts strings and returns them untrimmed. If a maintainer later consolidates by importing fromcoerce.ts, numericorgIdvalues from the Sentry SDK would silently becomeundefined, breaking link generation.Additional Locations (1)
packages/junior/src/chat/slack/footer.ts#L100-L102Reviewed by Cursor Bugbot for commit 8965643. Configure here.