@c1m-public/dash-site-kit 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -141,7 +141,7 @@ a Vercel function bundle and turn a packaging error into silent telemetry loss.
141
141
  | Variable | Required | Meaning |
142
142
  | --- | --- | --- |
143
143
  | `CHANNEL_SITE_SENTRY_DSN` | no | Shared channel-sites Sentry DSN; absence disables reporting |
144
- | `CHANNEL_SITE_NAME` | with DSN | Stable site tag used to attribute events in the shared project |
144
+ | `CHANNEL_SITE_NAME` | no | Backwards-compatible site-tag override; otherwise the Vercel production hostname is used |
145
145
  | `CHANNEL_SITE_CHANNEL_ID` | no | Immutable channel identifier added as the `channel_id` tag |
146
146
  | `SENTRY_ENVIRONMENT` | no | Explicit Sentry environment; otherwise `VERCEL_ENV` is used |
147
147
 
@@ -154,10 +154,10 @@ import * as Sentry from "@sentry/nextjs";
154
154
  import { resolveChannelSiteSentryOptions } from "@c1m-public/dash-site-kit";
155
155
 
156
156
  const options = resolveChannelSiteSentryOptions({
157
- dsn: process.env.NEXT_PUBLIC_CHANNEL_SITE_SENTRY_DSN,
158
- environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
159
- release: process.env.NEXT_PUBLIC_CHANNEL_SITE_RELEASE,
160
- site: process.env.NEXT_PUBLIC_CHANNEL_SITE_NAME ?? "",
157
+ dsn: process.env.CHANNEL_SITE_BROWSER_SENTRY_DSN,
158
+ environment: process.env.NEXT_PUBLIC_VERCEL_ENV,
159
+ release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
160
+ site: globalThis.location.hostname,
161
161
  });
162
162
  if (options) Sentry.init(options);
163
163
 
@@ -167,8 +167,16 @@ export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
167
167
  The browser DSN is public by design. Source-map upload credentials remain
168
168
  build-only and must never use `NEXT_PUBLIC_*`.
169
169
 
170
- A configured but malformed DSN or missing site name fails fast. This prevents a
171
- deployment from claiming error reporting while sending no attributable events.
170
+ A configured but malformed DSN or missing site identity fails fast. On the
171
+ server the kit uses `CHANNEL_SITE_NAME` when present, then derives `site` from
172
+ `VERCEL_PROJECT_PRODUCTION_URL`. Browser composition roots use
173
+ `location.hostname`. Every event also receives `site_kind=dash-site`, so one
174
+ shared Sentry project and one Grafana dashboard can separate future site
175
+ families without another per-deployment variable. This prevents a deployment
176
+ from claiming error reporting while sending no attributable events. The
177
+ `observability.grafana_dashboard` event context links directly back to the same
178
+ site selection in the shared Grafana dashboard; it is derived from `site` and
179
+ does not need configuration.
172
180
  Use `CHANNEL_SITE_CHANNEL_ID` only when one deployment always represents one
173
181
  channel. If a process can serve multiple channels, attach `channel_id` inside a
174
182
  request-local Sentry scope after resolving the request instead of setting a
@@ -8,6 +8,7 @@ export interface ChannelSiteSentryEnvironment {
8
8
  NEXT_RUNTIME?: string;
9
9
  SENTRY_ENVIRONMENT?: string;
10
10
  VERCEL_ENV?: string;
11
+ VERCEL_PROJECT_PRODUCTION_URL?: string;
11
12
  }
12
13
  /** The narrow Sentry configuration surface owned by dash-site-kit. */
13
14
  export { ChannelSiteSentryConfigurationError };
@@ -2,6 +2,18 @@ import "server-only";
2
2
  import { ChannelSiteSentryConfigurationError, resolveChannelSiteSentryOptions as resolveOptions, } from "../sentry.js";
3
3
  /** The narrow Sentry configuration surface owned by dash-site-kit. */
4
4
  export { ChannelSiteSentryConfigurationError };
5
+ function siteFromProductionUrl(value) {
6
+ const candidate = value?.trim();
7
+ if (!candidate)
8
+ return "";
9
+ try {
10
+ const url = new URL(candidate.includes("://") ? candidate : `https://${candidate}`);
11
+ return url.hostname.toLowerCase().replace(/\.$/, "");
12
+ }
13
+ catch {
14
+ return "";
15
+ }
16
+ }
5
17
  /**
6
18
  * Resolve the common Sentry options for a channel site.
7
19
  *
@@ -17,7 +29,8 @@ export function resolveChannelSiteSentryOptions(environment = process.env) {
17
29
  channelId: environment.CHANNEL_SITE_CHANNEL_ID,
18
30
  dsn: rawDsn,
19
31
  environment: environment.SENTRY_ENVIRONMENT || environment.VERCEL_ENV,
20
- site: environment.CHANNEL_SITE_NAME ?? "",
32
+ site: environment.CHANNEL_SITE_NAME?.trim() ||
33
+ siteFromProductionUrl(environment.VERCEL_PROJECT_PRODUCTION_URL),
21
34
  });
22
35
  }
23
36
  /**
package/dist/sentry.d.ts CHANGED
@@ -10,9 +10,15 @@ export interface ChannelSiteSentryOptions {
10
10
  enableLogs: false;
11
11
  environment?: string;
12
12
  initialScope: {
13
+ contexts: {
14
+ observability: {
15
+ grafana_dashboard: string;
16
+ };
17
+ };
13
18
  tags: {
14
19
  channel_id?: string;
15
20
  site: string;
21
+ site_kind: "dash-site";
16
22
  };
17
23
  };
18
24
  release?: string;
package/dist/sentry.js CHANGED
@@ -39,8 +39,15 @@ export function resolveChannelSiteSentryOptions(configuration) {
39
39
  enableLogs: false,
40
40
  ...(environment ? { environment } : {}),
41
41
  initialScope: {
42
+ contexts: {
43
+ observability: {
44
+ grafana_dashboard: "https://cloud1medialtd.grafana.net/d/c1m-sites-errors-health/saasdash-sites-errors-health" +
45
+ `?var-site=${encodeURIComponent(site)}&var-site_kind=dash-site&from=now-24h&to=now`,
46
+ },
47
+ },
42
48
  tags: {
43
49
  site,
50
+ site_kind: "dash-site",
44
51
  ...(channelId ? { channel_id: channelId } : {}),
45
52
  },
46
53
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c1m-public/dash-site-kit",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Shared transport, domain and UI layer for MML dash-scoped public sites",