Skip to content

chore(mcp-adoption-value-discovery): Adding docs traffic sources attrs#1002

Merged
Abdkhan14 merged 5 commits into
mainfrom
abdk/mcp-docs-traffic-attrs
May 28, 2026
Merged

chore(mcp-adoption-value-discovery): Adding docs traffic sources attrs#1002
Abdkhan14 merged 5 commits into
mainfrom
abdk/mcp-docs-traffic-attrs

Conversation

@Abdkhan14

Copy link
Copy Markdown
Contributor

Enables Sentry browser tracing on the SPA so we get pageload transactions for mcp.sentry.dev/ traffic. Added two attrs for traffic source tracking:

app.utm_source — sanitized in-product utm_source query param from window.location. Used to group by in-app sources as we surface mcp doc links more in Sentry.

app.referrer.family — low-cardinality bucket of the Referer header host: google, github, sentry, sentry-docs, or other for now. Used to see where external traffic is arriving from.

integrations: [Sentry.browserTracingIntegration()],
});

resolveAttribution();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

beforeSendSpan might be a good alternative here, removes the assumption that the pageload span is active when resolveAttribution runs.

Something like:

const utmSource = resolveUtmSource(
  new URLSearchParams(window.location.search).get("utm_source"),
);
const referrerFamily = resolveReferrerFamily(document.referrer);

Sentry.init({
  // ...
  integrations: [Sentry.browserTracingIntegration()],
  beforeSendSpan(span) {
    if (span.op === "pageload") {
      span.data = {
        ...span.data,
        ...(utmSource && { "app.utm_source": utmSource }),
        ...(referrerFamily && { "app.referrer.family": referrerFamily }),
      };
    }
    return span;
  },
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jaydgoss great callout, pushed the change thanks 💯

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fwiw im not a fan of beforeSendSpan and that kind of magic behavior. its way too brittle. much safer to just bind it explicitly where its needed so it doesnt randomly break in the future when e.g. op gets renamed or something like that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah I understand ^, beforeSendSpan + op filter does end up coupled to internal SDK strings.

Reverting to explicit getActiveSpan + setAttribute right after init in the next push

beforeSendSpan: attributionBeforeSendSpan,
environment:
import.meta.env.VITE_SENTRY_ENVIRONMENT ?? import.meta.env.NODE_ENV,
integrations: [Sentry.browserTracingIntegration()],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think i had this disabled because the data is mostly inactionable/junk. we can see how it goes but i want to make sure the quality of the telemetry stays as high as it can on this project

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3020473. Configure here.

Comment thread packages/mcp-cloudflare/src/client/instrument.ts
Abdkhan14 added a commit to getsentry/sentry that referenced this pull request May 28, 2026
@Abdkhan14 Abdkhan14 merged commit 04e87a2 into main May 28, 2026
18 checks passed
@Abdkhan14 Abdkhan14 deleted the abdk/mcp-docs-traffic-attrs branch May 28, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants