@spfn/monitor 0.1.0-beta.1 → 0.1.0-beta.2

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/dist/server.d.ts CHANGED
@@ -248,6 +248,7 @@ interface ErrorTrackingContext {
248
248
  userId?: string;
249
249
  headers?: Record<string, string>;
250
250
  query?: Record<string, string>;
251
+ environment?: string;
251
252
  }
252
253
  /**
253
254
  * Generate a deterministic fingerprint for error deduplication
@@ -402,6 +403,11 @@ interface MonitorErrorHandlerOptions {
402
403
  * @default env.SPFN_MONITOR_MIN_STATUS_CODE or 500
403
404
  */
404
405
  minStatusCode?: number;
406
+ /**
407
+ * Environment label (e.g. 'production', 'staging', 'development')
408
+ * Displayed in Slack notifications for easy identification.
409
+ */
410
+ environment?: string;
405
411
  /**
406
412
  * Extract custom metadata from error and context
407
413
  */
package/dist/server.js CHANGED
@@ -2928,29 +2928,30 @@ var monitorLogger = {
2928
2928
  import { sendSlack } from "@spfn/notification/server";
2929
2929
  import { getSlackWebhookUrl } from "@spfn/monitor/config";
2930
2930
  var logger = monitorLogger.notification;
2931
- async function notifyErrorToSlack(group, event, reason) {
2931
+ async function notifyErrorToSlack(group, event, reason, environment) {
2932
2932
  const webhookUrl = getSlackWebhookUrl();
2933
2933
  if (!webhookUrl) {
2934
2934
  logger.warn("Slack webhook URL not configured, skipping notification");
2935
2935
  return;
2936
2936
  }
2937
- const { text: text4, blocks } = formatSlackMessage(group, event, reason);
2937
+ const { text: text4, blocks } = formatSlackMessage(group, event, reason, environment);
2938
2938
  const result = await sendSlack({ webhookUrl, text: text4, blocks });
2939
2939
  if (!result.success) {
2940
2940
  logger.warn("Failed to send Slack notification", { error: result.error });
2941
2941
  }
2942
2942
  }
2943
- function formatSlackMessage(group, event, reason) {
2943
+ function formatSlackMessage(group, event, reason, environment) {
2944
2944
  const isNew = reason === "new";
2945
2945
  const emoji = isNew ? ":rotating_light:" : ":warning:";
2946
2946
  const label = isNew ? "New Error" : "Re-opened Error";
2947
- const title = `${emoji} ${label} \u2014 ${group.statusCode}`;
2947
+ const envTag = environment ? ` [${environment}]` : "";
2948
+ const title = `${emoji}${envTag} ${label} \u2014 ${group.statusCode}`;
2948
2949
  const blocks = [
2949
2950
  {
2950
2951
  type: "header",
2951
2952
  text: {
2952
2953
  type: "plain_text",
2953
- text: `${label} \u2014 ${group.statusCode}`,
2954
+ text: `${envTag ? envTag.trim() + " " : ""}${label} \u2014 ${group.statusCode}`,
2954
2955
  emoji: true
2955
2956
  }
2956
2957
  },
@@ -3046,7 +3047,7 @@ async function trackError(err, ctx, metadata) {
3046
3047
  });
3047
3048
  const event = await createEvent(group.id, err, ctx, metadata);
3048
3049
  logger2.info("New error group tracked", { fingerprint, groupId: group.id });
3049
- notifyErrorToSlack(group, event, "new").catch((e) => logger2.warn("Slack notification failed", e));
3050
+ notifyErrorToSlack(group, event, "new", ctx.environment).catch((e) => logger2.warn("Slack notification failed", e));
3050
3051
  return;
3051
3052
  }
3052
3053
  if (existing.status === "resolved") {
@@ -3057,7 +3058,8 @@ async function trackError(err, ctx, metadata) {
3057
3058
  notifyErrorToSlack(
3058
3059
  { ...existing, status: "active", count: existing.count + 1 },
3059
3060
  event,
3060
- "reopened"
3061
+ "reopened",
3062
+ ctx.environment
3061
3063
  ).catch((e) => logger2.warn("Slack notification failed", e));
3062
3064
  return;
3063
3065
  }
@@ -3292,7 +3294,8 @@ function createMonitorErrorHandler(options = {}) {
3292
3294
  requestId: ctx.requestId,
3293
3295
  userId: ctx.userId,
3294
3296
  headers: ctx.request.headers,
3295
- query: ctx.request.query
3297
+ query: ctx.request.query,
3298
+ environment: options.environment
3296
3299
  };
3297
3300
  const metadata = options.extractMetadata?.(err, trackingCtx);
3298
3301
  try {