Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions packages/junior/src/chat/slack/footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as Sentry from "@/chat/sentry";
import type { TurnThinkingSelection } from "@/chat/services/turn-thinking-level";
import type { AgentTurnUsage } from "@/chat/usage";

const SENTRY_CONVERSATION_SEARCH_STATS_PERIOD = "14d";

interface SlackMrkdwnTextObject {
text: string;
type: "mrkdwn";
Expand Down Expand Up @@ -54,10 +52,6 @@ function escapeSlackLinkUrl(url: string): string {
.replaceAll(">", "%3E");
}

function quoteSentrySearchValue(value: string): string {
return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
}

function getSentryOrgSlug(): string | undefined {
const slug = process.env.SENTRY_ORG_SLUG?.trim();
return slug || undefined;
Expand All @@ -82,9 +76,7 @@ function buildSentryWebBaseUrl(dsn: {
return `${dsn.protocol}://${dsn.host}${port}${path}`;
}

function getSentryConversationSearchUrl(
conversationId: string,
): string | undefined {
function getSentryConversationUrl(conversationId: string): string | undefined {
const client = Sentry.getClient();
const dsn = client?.getDsn();
if (!dsn?.host || !dsn.projectId) {
Expand All @@ -96,21 +88,17 @@ function getSentryConversationSearchUrl(
return undefined;
}

const encodedId = encodeURIComponent(conversationId);
const params = new URLSearchParams();
params.set(
"query",
`gen_ai.conversation.id:${quoteSentrySearchValue(conversationId)}`,
);
params.set("project", dsn.projectId);
params.set("statsPeriod", SENTRY_CONVERSATION_SEARCH_STATS_PERIOD);

const search = `explore/traces/?${params.toString()}`;
const path = `explore/conversations/${encodedId}/?${params.toString()}`;

if (isSentrySaasDsnHost(dsn.host)) {
return `https://${orgSlug}.sentry.io/${search}`;
return `https://${orgSlug}.sentry.io/${path}`;
}

return `${buildSentryWebBaseUrl(dsn)}/organizations/${orgSlug}/${search}`;
return `${buildSentryWebBaseUrl(dsn)}/organizations/${orgSlug}/${path}`;
}

function formatSlackTokenCount(value: number): string {
Expand Down Expand Up @@ -194,7 +182,7 @@ export function buildSlackReplyFooter(args: {
label: "ID",
value: conversationId,
};
const conversationUrl = getSentryConversationSearchUrl(conversationId);
const conversationUrl = getSentryConversationUrl(conversationId);
if (conversationUrl) {
idItem.url = conversationUrl;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/junior/tests/unit/slack/footer-sentry-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ afterEach(() => {
});

describe("Slack footer Sentry links", () => {
it("links the ID to an Explore traces search using org slug subdomain for SaaS", async () => {
it("links the ID to the conversations page using org slug subdomain for SaaS", async () => {
process.env.SENTRY_ORG_SLUG = "my-org";
mockSentryClient({
dsn: {
Expand All @@ -55,7 +55,7 @@ describe("Slack footer Sentry links", () => {
elements: [
{
type: "mrkdwn",
text: "*ID:* <https://my-org.sentry.io/explore/traces/?query=gen_ai.conversation.id%3A%22slack%3AC123%3A1700000000.000100%22&amp;project=4501&amp;statsPeriod=14d|slack:C123:1700000000.000100>",
text: "*ID:* <https://my-org.sentry.io/explore/conversations/slack%3AC123%3A1700000000.000100/?project=4501|slack:C123:1700000000.000100>",
},
],
},
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("Slack footer Sentry links", () => {
items: [
{
label: "ID",
url: "https://sentry.example.com/organizations/my-org/explore/traces/?query=gen_ai.conversation.id%3A%22conversation-1%22&project=4501&statsPeriod=14d",
url: "https://sentry.example.com/organizations/my-org/explore/conversations/conversation-1/?project=4501",
value: "conversation-1",
},
],
Expand Down
Loading