@ttt-productions/monitoring-core 0.13.2 → 0.13.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"sentry-node.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry-node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA0BvD,eAAO,MAAM,iBAAiB,EAAE,iBAgI/B,CAAC"}
1
+ {"version":3,"file":"sentry-node.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry-node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA2BvD,eAAO,MAAM,iBAAiB,EAAE,iBA4H/B,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { applyCaptureContext } from "../capture-context.js";
1
2
  let sentryNodePromise = null;
2
3
  let sentryNodeInstance = null;
3
4
  function getSentryNode() {
@@ -28,10 +29,7 @@ export const SentryNodeAdapter = {
28
29
  if (sentryNodeInstance) {
29
30
  if (context) {
30
31
  sentryNodeInstance.withScope((scope) => {
31
- for (const [k, v] of Object.entries(context)) {
32
- if (typeof scope?.setExtra === "function")
33
- scope.setExtra(k, v);
34
- }
32
+ applyCaptureContext(scope, context);
35
33
  sentryNodeInstance.captureException(error);
36
34
  });
37
35
  return;
@@ -43,10 +41,7 @@ export const SentryNodeAdapter = {
43
41
  const S = await getSentryNode();
44
42
  if (context) {
45
43
  S.withScope((scope) => {
46
- for (const [k, v] of Object.entries(context)) {
47
- if (typeof scope?.setExtra === "function")
48
- scope.setExtra(k, v);
49
- }
44
+ applyCaptureContext(scope, context);
50
45
  S.captureException(error);
51
46
  });
52
47
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"sentry-node.js","sourceRoot":"","sources":["../../src/adapters/sentry-node.ts"],"names":[],"mappings":"AAaA,IAAI,iBAAiB,GAAmC,IAAI,CAAC;A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AAU,EAAE,GAAG,EAAE,GAAE,CAAC;SACrB,CAAC;QAEF,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,KAAY,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;IAED,aAAa,CAAC,UAKb;QACC,IAAI,kBAAkB,EAAE,CAAC;YACvB,kBAAkB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAC7C,OAAO;QACT,CAAC;QACD,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAC9B,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;CACF,CAAC","sourcesContent":["import type { MonitoringAdapter } from \"../adapter.js\";\nimport type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"../types.js\";\n\ntype SentryNodeLike = {\n init: (opts: any) => void;\n captureException: (e: unknown, hint?: any) => void;\n captureMessage: (m: string, level?: any) => void;\n setUser: (u: any) => void;\n setTag: (k: string, v: string) => void;\n withScope: (fn: (scope: any) => void) => void;\n addBreadcrumb: (breadcrumb: any) => void;\n};\n\nlet sentryNodePromise: Promise<SentryNodeLike> | null = null;\nlet sentryNodeInstance: SentryNodeLike | null = null;\n\nfunction getSentryNode(): Promise<SentryNodeLike> {\n if (!sentryNodePromise) {\n sentryNodePromise = import(\"@sentry/node\").then((m) => {\n sentryNodeInstance = m as any;\n return sentryNodeInstance!;\n });\n }\n return sentryNodePromise;\n}\n\nexport const SentryNodeAdapter: MonitoringAdapter = {\n async init(options: MonitoringInitOptions) {\n const enabled = options.enabled ?? true;\n if (!enabled || !options.dsn) return;\n\n const S = await getSentryNode();\n S.init({\n dsn: options.dsn,\n environment: options.environment,\n enabled: true,\n release: options.release,\n ...(options.tracesSampleRate !== undefined ? { tracesSampleRate: options.tracesSampleRate } : {}),\n ...(options.integrations !== undefined ? { integrations: options.integrations } : {}),\n });\n },\n\n captureException(error: unknown, context?: Record<string, unknown>) {\n if (sentryNodeInstance) {\n if (context) {\n sentryNodeInstance.withScope((scope) => {\n for (const [k, v] of Object.entries(context)) {\n if (typeof scope?.setExtra === \"function\") scope.setExtra(k, v);\n }\n sentryNodeInstance!.captureException(error);\n });\n return;\n }\n sentryNodeInstance.captureException(error);\n return;\n }\n\n void (async () => {\n const S = await getSentryNode();\n\n if (context) {\n S.withScope((scope) => {\n for (const [k, v] of Object.entries(context)) {\n if (typeof scope?.setExtra === \"function\") scope.setExtra(k, v);\n }\n S.captureException(error);\n });\n return;\n }\n\n S.captureException(error);\n })();\n },\n\n captureMessage(message: string, level?: any) {\n if (sentryNodeInstance) {\n sentryNodeInstance.captureMessage(message, level);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.captureMessage(message, level);\n })();\n },\n\n setUser(user: MonitoringUser | null) {\n if (sentryNodeInstance) {\n sentryNodeInstance.setUser(user as any);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.setUser(user as any);\n })();\n },\n\n setTag(key: string, value: string) {\n if (sentryNodeInstance) {\n sentryNodeInstance.setTag(key, value);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.setTag(key, value);\n })();\n },\n\n // NOTE: withScope calls `fn` exactly once. When Sentry is already loaded\n // (the expected steady state — `init()` awaits the dynamic import, and\n // callers must await `initMonitoring()` before serving traffic), it runs\n // synchronously through the real Sentry scope. Only during the narrow\n // pre-load race window (a call that races the very first `getSentryNode()`\n // resolution) does it fall back to a synchronous no-op-scope call plus an\n // async replay against the real scope — mirroring the browser adapter's\n // same accepted tradeoff for that same race window.\n withScope<T>(fn: (scope: ScopeLike) => T): T {\n if (sentryNodeInstance) {\n let result: T;\n sentryNodeInstance.withScope((scope) => {\n result = fn(scope as any);\n });\n return result!;\n }\n\n const minimalScope: ScopeLike = {\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n };\n\n void (async () => {\n const S = await getSentryNode();\n S.withScope((scope) => fn(scope as any));\n })();\n\n return fn(minimalScope);\n },\n\n addBreadcrumb(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }) {\n if (sentryNodeInstance) {\n sentryNodeInstance.addBreadcrumb(breadcrumb);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.addBreadcrumb(breadcrumb);\n })();\n },\n};"]}
1
+ {"version":3,"file":"sentry-node.js","sourceRoot":"","sources":["../../src/adapters/sentry-node.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAY5D,IAAI,iBAAiB,GAAmC,IAAI,CAAC;AAC7D,IAAI,kBAAkB,GAA0B,IAAI,CAAC;AAErD,SAAS,aAAa;IACpB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACpD,kBAAkB,GAAG,CAAQ,CAAC;YAC9B,OAAO,kBAAmB,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAsB;IAClD,KAAK,CAAC,IAAI,CAAC,OAA8B;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;QACxC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG;YAAE,OAAO;QAErC,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;QAChC,CAAC,CAAC,IAAI,CAAC;YACL,GAAG,EAAE,OAAO,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AAG,EAAE,CAAC,KAAY,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,OAAO,MAAO,CAAC;QACjB,CAAC;QAED,MAAM,YAAY,GAAc;YAC9B,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;YAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;YACjB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;SACrB,CAAC;QAEF,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,KAAY,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;IAED,aAAa,CAAC,UAKb;QACC,IAAI,kBAAkB,EAAE,CAAC;YACvB,kBAAkB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAC7C,OAAO;QACT,CAAC;QACD,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAC9B,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;CACF,CAAC","sourcesContent":["import type { MonitoringAdapter } from \"../adapter.js\";\nimport type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"../types.js\";\nimport { applyCaptureContext } from \"../capture-context.js\";\n\ntype SentryNodeLike = {\n init: (opts: any) => void;\n captureException: (e: unknown, hint?: any) => void;\n captureMessage: (m: string, level?: any) => void;\n setUser: (u: any) => void;\n setTag: (k: string, v: string) => void;\n withScope: (fn: (scope: any) => void) => void;\n addBreadcrumb: (breadcrumb: any) => void;\n};\n\nlet sentryNodePromise: Promise<SentryNodeLike> | null = null;\nlet sentryNodeInstance: SentryNodeLike | null = null;\n\nfunction getSentryNode(): Promise<SentryNodeLike> {\n if (!sentryNodePromise) {\n sentryNodePromise = import(\"@sentry/node\").then((m) => {\n sentryNodeInstance = m as any;\n return sentryNodeInstance!;\n });\n }\n return sentryNodePromise;\n}\n\nexport const SentryNodeAdapter: MonitoringAdapter = {\n async init(options: MonitoringInitOptions) {\n const enabled = options.enabled ?? true;\n if (!enabled || !options.dsn) return;\n\n const S = await getSentryNode();\n S.init({\n dsn: options.dsn,\n environment: options.environment,\n enabled: true,\n release: options.release,\n ...(options.tracesSampleRate !== undefined ? { tracesSampleRate: options.tracesSampleRate } : {}),\n ...(options.integrations !== undefined ? { integrations: options.integrations } : {}),\n });\n },\n\n captureException(error: unknown, context?: Record<string, unknown>) {\n if (sentryNodeInstance) {\n if (context) {\n sentryNodeInstance.withScope((scope) => {\n applyCaptureContext(scope, context);\n sentryNodeInstance!.captureException(error);\n });\n return;\n }\n sentryNodeInstance.captureException(error);\n return;\n }\n\n void (async () => {\n const S = await getSentryNode();\n\n if (context) {\n S.withScope((scope) => {\n applyCaptureContext(scope, context);\n S.captureException(error);\n });\n return;\n }\n\n S.captureException(error);\n })();\n },\n\n captureMessage(message: string, level?: any) {\n if (sentryNodeInstance) {\n sentryNodeInstance.captureMessage(message, level);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.captureMessage(message, level);\n })();\n },\n\n setUser(user: MonitoringUser | null) {\n if (sentryNodeInstance) {\n sentryNodeInstance.setUser(user as any);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.setUser(user as any);\n })();\n },\n\n setTag(key: string, value: string) {\n if (sentryNodeInstance) {\n sentryNodeInstance.setTag(key, value);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.setTag(key, value);\n })();\n },\n\n // NOTE: withScope calls `fn` exactly once. When Sentry is already loaded\n // (the expected steady state — `init()` awaits the dynamic import, and\n // callers must await `initMonitoring()` before serving traffic), it runs\n // synchronously through the real Sentry scope. Only during the narrow\n // pre-load race window (a call that races the very first `getSentryNode()`\n // resolution) does it fall back to a synchronous no-op-scope call plus an\n // async replay against the real scope — mirroring the browser adapter's\n // same accepted tradeoff for that same race window.\n withScope<T>(fn: (scope: ScopeLike) => T): T {\n if (sentryNodeInstance) {\n let result: T;\n sentryNodeInstance.withScope((scope) => {\n result = fn(scope as any);\n });\n return result!;\n }\n\n const minimalScope: ScopeLike = {\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n };\n\n void (async () => {\n const S = await getSentryNode();\n S.withScope((scope) => fn(scope as any));\n })();\n\n return fn(minimalScope);\n },\n\n addBreadcrumb(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }) {\n if (sentryNodeInstance) {\n sentryNodeInstance.addBreadcrumb(breadcrumb);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.addBreadcrumb(breadcrumb);\n })();\n },\n};"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA0BvD,eAAO,MAAM,aAAa,EAAE,iBA8H3B,CAAC"}
1
+ {"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA2BvD,eAAO,MAAM,aAAa,EAAE,iBA0H3B,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { applyCaptureContext } from "../capture-context.js";
1
2
  let sentryPromise = null;
2
3
  let sentryInstance = null;
3
4
  function getSentry() {
@@ -28,10 +29,7 @@ export const SentryAdapter = {
28
29
  if (sentryInstance) {
29
30
  if (context && sentryInstance.withScope) {
30
31
  sentryInstance.withScope((scope) => {
31
- for (const [k, v] of Object.entries(context)) {
32
- if (typeof scope?.setExtra === "function")
33
- scope.setExtra(k, v);
34
- }
32
+ applyCaptureContext(scope, context);
35
33
  sentryInstance.captureException(error);
36
34
  });
37
35
  return;
@@ -43,10 +41,7 @@ export const SentryAdapter = {
43
41
  const S = await getSentry();
44
42
  if (context && S.withScope) {
45
43
  S.withScope((scope) => {
46
- for (const [k, v] of Object.entries(context)) {
47
- if (typeof scope?.setExtra === "function")
48
- scope.setExtra(k, v);
49
- }
44
+ applyCaptureContext(scope, context);
50
45
  S.captureException(error);
51
46
  });
52
47
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/adapters/sentry.ts"],"names":[],"mappings":"AAaA,IAAI,aAAa,GAA+B,IAAI,CAAC;AACrD,IAAI,cAAc,GAAsB,IAAI,CAAC;AAE7C,SAAS,SAAS;IAChB,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YAClD,cAAc,GAAG,CAAQ,CAAC;YAC1B,OAAO,cAAe,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,KAAK,CAAC,IAAI,CAAC,OAA8B;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;QACxC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG;YAAE,OAAO;QAErC,MAAM,CAAC,GAAG,MAAM,SAAS,EAAE,CAAC;QAC5B,CAAC,CAAC,IAAI,CAAC;YACL,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,CAAC,OAAO,CAAC,gBAAgB,KA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{ MonitoringInitOptions, MonitoringUser, ScopeLike } from \"../types.js\";\n\ntype SentryLike = {\n init: (opts: any) => void;\n captureException: (e: unknown) => void;\n captureMessage: (m: string, level?: any) => void;\n setUser: (u: any) => void;\n setTag: (k: string, v: string) => void;\n withScope?: (fn: (scope: any) => void) => void;\n addBreadcrumb?: (breadcrumb: any) => void;\n};\n\nlet sentryPromise: Promise<SentryLike> | null = null;\nlet sentryInstance: SentryLike | null = null;\n\nfunction getSentry(): Promise<SentryLike> {\n if (!sentryPromise) {\n sentryPromise = import(\"@sentry/nextjs\").then((m) => {\n sentryInstance = m as any;\n return sentryInstance!;\n });\n }\n return sentryPromise;\n}\n\nexport const SentryAdapter: MonitoringAdapter = {\n async init(options: MonitoringInitOptions) {\n const enabled = options.enabled ?? true;\n if (!enabled || !options.dsn) return;\n\n const S = await getSentry();\n S.init({\n dsn: options.dsn,\n environment: options.environment,\n enabled: true,\n release: options.release,\n ...(options.tracesSampleRate !== undefined ? { tracesSampleRate: options.tracesSampleRate } : {}),\n ...(options.integrations !== undefined ? { integrations: options.integrations } : {}),\n });\n },\n\n captureException(error: unknown, context?: Record<string, unknown>) {\n if (sentryInstance) {\n if (context && sentryInstance.withScope) {\n sentryInstance.withScope((scope) => {\n for (const [k, v] of Object.entries(context)) {\n if (typeof scope?.setExtra === \"function\") scope.setExtra(k, v);\n }\n sentryInstance!.captureException(error);\n });\n return;\n }\n sentryInstance.captureException(error);\n return;\n }\n\n void (async () => {\n const S = await getSentry();\n\n if (context && S.withScope) {\n S.withScope((scope) => {\n for (const [k, v] of Object.entries(context)) {\n if (typeof scope?.setExtra === \"function\") scope.setExtra(k, v);\n }\n S.captureException(error);\n });\n return;\n }\n\n S.captureException(error);\n })();\n },\n\n captureMessage(message: string, level?: any) {\n if (sentryInstance) {\n sentryInstance.captureMessage(message, level);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.captureMessage(message, level);\n })();\n },\n\n setUser(user: MonitoringUser | null) {\n if (sentryInstance) {\n sentryInstance.setUser(user as any);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.setUser(user as any);\n })();\n },\n\n setTag(key: string, value: string) {\n if (sentryInstance) {\n sentryInstance.setTag(key, value);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.setTag(key, value);\n })();\n },\n\n withScope<T>(fn: (scope: ScopeLike) => T): T {\n if (sentryInstance && sentryInstance.withScope) {\n let result: T;\n sentryInstance.withScope((scope) => {\n result = fn(scope as any);\n });\n return result!;\n }\n\n // Sentry not loaded yet — run with no-op scope, then replay async\n const minimalScope: ScopeLike = {\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n };\n\n void (async () => {\n const S = await getSentry();\n if (!S.withScope) return;\n S.withScope((scope) => fn(scope as any));\n })();\n\n return fn(minimalScope);\n },\n\n addBreadcrumb(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }) {\n if (sentryInstance) {\n if (sentryInstance.addBreadcrumb) {\n sentryInstance.addBreadcrumb(breadcrumb);\n }\n return;\n }\n void (async () => {\n const S = await getSentry();\n if (S.addBreadcrumb) {\n S.addBreadcrumb(breadcrumb);\n }\n })();\n },\n};"]}
1
+ {"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/adapters/sentry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAY5D,IAAI,aAAa,GAA+B,IAAI,CAAC;AACrD,IAAI,cAAc,GAAsB,IAAI,CAAC;AAE7C,SAAS,SAAS;IAChB,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YAClD,cAAc,GAAG,CAAQ,CAAC;YAC1B,OAAO,cAAe,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,aAAa,C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AC;YAC9B,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;CACF,CAAC","sourcesContent":["import type { MonitoringAdapter } from \"../adapter.js\";\nimport type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"../types.js\";\nimport { applyCaptureContext } from \"../capture-context.js\";\n\ntype SentryLike = {\n init: (opts: any) => void;\n captureException: (e: unknown) => void;\n captureMessage: (m: string, level?: any) => void;\n setUser: (u: any) => void;\n setTag: (k: string, v: string) => void;\n withScope?: (fn: (scope: any) => void) => void;\n addBreadcrumb?: (breadcrumb: any) => void;\n};\n\nlet sentryPromise: Promise<SentryLike> | null = null;\nlet sentryInstance: SentryLike | null = null;\n\nfunction getSentry(): Promise<SentryLike> {\n if (!sentryPromise) {\n sentryPromise = import(\"@sentry/nextjs\").then((m) => {\n sentryInstance = m as any;\n return sentryInstance!;\n });\n }\n return sentryPromise;\n}\n\nexport const SentryAdapter: MonitoringAdapter = {\n async init(options: MonitoringInitOptions) {\n const enabled = options.enabled ?? true;\n if (!enabled || !options.dsn) return;\n\n const S = await getSentry();\n S.init({\n dsn: options.dsn,\n environment: options.environment,\n enabled: true,\n release: options.release,\n ...(options.tracesSampleRate !== undefined ? { tracesSampleRate: options.tracesSampleRate } : {}),\n ...(options.integrations !== undefined ? { integrations: options.integrations } : {}),\n });\n },\n\n captureException(error: unknown, context?: Record<string, unknown>) {\n if (sentryInstance) {\n if (context && sentryInstance.withScope) {\n sentryInstance.withScope((scope) => {\n applyCaptureContext(scope, context);\n sentryInstance!.captureException(error);\n });\n return;\n }\n sentryInstance.captureException(error);\n return;\n }\n\n void (async () => {\n const S = await getSentry();\n\n if (context && S.withScope) {\n S.withScope((scope) => {\n applyCaptureContext(scope, context);\n S.captureException(error);\n });\n return;\n }\n\n S.captureException(error);\n })();\n },\n\n captureMessage(message: string, level?: any) {\n if (sentryInstance) {\n sentryInstance.captureMessage(message, level);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.captureMessage(message, level);\n })();\n },\n\n setUser(user: MonitoringUser | null) {\n if (sentryInstance) {\n sentryInstance.setUser(user as any);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.setUser(user as any);\n })();\n },\n\n setTag(key: string, value: string) {\n if (sentryInstance) {\n sentryInstance.setTag(key, value);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.setTag(key, value);\n })();\n },\n\n withScope<T>(fn: (scope: ScopeLike) => T): T {\n if (sentryInstance && sentryInstance.withScope) {\n let result: T;\n sentryInstance.withScope((scope) => {\n result = fn(scope as any);\n });\n return result!;\n }\n\n // Sentry not loaded yet — run with no-op scope, then replay async\n const minimalScope: ScopeLike = {\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n };\n\n void (async () => {\n const S = await getSentry();\n if (!S.withScope) return;\n S.withScope((scope) => fn(scope as any));\n })();\n\n return fn(minimalScope);\n },\n\n addBreadcrumb(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }) {\n if (sentryInstance) {\n if (sentryInstance.addBreadcrumb) {\n sentryInstance.addBreadcrumb(breadcrumb);\n }\n return;\n }\n void (async () => {\n const S = await getSentry();\n if (S.addBreadcrumb) {\n S.addBreadcrumb(breadcrumb);\n }\n })();\n },\n};"]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Capture-context application — the one place that decides how a capture's
3
+ * context argument lands on a Sentry scope.
4
+ *
5
+ * Context keys become EXTRAS, with one exception: a key named `tags` whose
6
+ * value is a flat string map is applied as REAL Sentry tags (`scope.setTag`),
7
+ * so those values are searchable, filterable, and alert-routable. A `tags`
8
+ * value that is not a flat string map (nested objects, arrays, non-string
9
+ * values) is left as an ordinary extra — nothing is dropped.
10
+ */
11
+ /**
12
+ * Narrow an arbitrary value to a flat `Record<string, string>`, or `null` when
13
+ * it is not one. An empty object qualifies (it carries no tags and no
14
+ * information, so it yields neither a tag nor an extra).
15
+ */
16
+ export declare function asFlatStringTagMap(value: unknown): Record<string, string> | null;
17
+ /**
18
+ * Apply a capture context to a scope: real tags for a flat-string-map `tags`
19
+ * entry, extras for everything else. Tolerates a scope missing either method.
20
+ */
21
+ export declare function applyCaptureContext(scope: unknown, context: Record<string, unknown>): void;
22
+ //# sourceMappingURL=capture-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture-context.d.ts","sourceRoot":"","sources":["../src/capture-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAShF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAkB1F"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Capture-context application — the one place that decides how a capture's
3
+ * context argument lands on a Sentry scope.
4
+ *
5
+ * Context keys become EXTRAS, with one exception: a key named `tags` whose
6
+ * value is a flat string map is applied as REAL Sentry tags (`scope.setTag`),
7
+ * so those values are searchable, filterable, and alert-routable. A `tags`
8
+ * value that is not a flat string map (nested objects, arrays, non-string
9
+ * values) is left as an ordinary extra — nothing is dropped.
10
+ */
11
+ /**
12
+ * Narrow an arbitrary value to a flat `Record<string, string>`, or `null` when
13
+ * it is not one. An empty object qualifies (it carries no tags and no
14
+ * information, so it yields neither a tag nor an extra).
15
+ */
16
+ export function asFlatStringTagMap(value) {
17
+ if (value === null || typeof value !== "object" || Array.isArray(value))
18
+ return null;
19
+ const out = {};
20
+ for (const [key, entry] of Object.entries(value)) {
21
+ if (typeof entry !== "string")
22
+ return null;
23
+ out[key] = entry;
24
+ }
25
+ return out;
26
+ }
27
+ /**
28
+ * Apply a capture context to a scope: real tags for a flat-string-map `tags`
29
+ * entry, extras for everything else. Tolerates a scope missing either method.
30
+ */
31
+ export function applyCaptureContext(scope, context) {
32
+ const target = scope;
33
+ for (const [key, value] of Object.entries(context)) {
34
+ if (key === "tags") {
35
+ const tagMap = asFlatStringTagMap(value);
36
+ if (tagMap) {
37
+ if (typeof target?.setTag === "function") {
38
+ for (const [tagKey, tagValue] of Object.entries(tagMap)) {
39
+ target.setTag(tagKey, tagValue);
40
+ }
41
+ }
42
+ continue;
43
+ }
44
+ }
45
+ if (typeof target?.setExtra === "function")
46
+ target.setExtra(key, value);
47
+ }
48
+ }
49
+ //# sourceMappingURL=capture-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture-context.js","sourceRoot":"","sources":["../src/capture-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAErF,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;QAC5E,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC3C,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc,EAAE,OAAgC;IAClF,MAAM,MAAM,GAAG,KAA8C,CAAC;IAE9D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;YACnB,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACzC,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,OAAO,MAAM,EAAE,MAAM,KAAK,UAAU,EAAE,CAAC;oBACzC,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;wBACxD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBAClC,CAAC;gBACH,CAAC;gBACD,SAAS;YACX,CAAC;QACH,CAAC;QAED,IAAI,OAAO,MAAM,EAAE,QAAQ,KAAK,UAAU;YAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC","sourcesContent":["/**\n * Capture-context application — the one place that decides how a capture's\n * context argument lands on a Sentry scope.\n *\n * Context keys become EXTRAS, with one exception: a key named `tags` whose\n * value is a flat string map is applied as REAL Sentry tags (`scope.setTag`),\n * so those values are searchable, filterable, and alert-routable. A `tags`\n * value that is not a flat string map (nested objects, arrays, non-string\n * values) is left as an ordinary extra — nothing is dropped.\n */\n\nimport type { ScopeLike } from \"./types.js\";\n\n/**\n * Narrow an arbitrary value to a flat `Record<string, string>`, or `null` when\n * it is not one. An empty object qualifies (it carries no tags and no\n * information, so it yields neither a tag nor an extra).\n */\nexport function asFlatStringTagMap(value: unknown): Record<string, string> | null {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return null;\n\n const out: Record<string, string> = {};\n for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {\n if (typeof entry !== \"string\") return null;\n out[key] = entry;\n }\n return out;\n}\n\n/**\n * Apply a capture context to a scope: real tags for a flat-string-map `tags`\n * entry, extras for everything else. Tolerates a scope missing either method.\n */\nexport function applyCaptureContext(scope: unknown, context: Record<string, unknown>): void {\n const target = scope as Partial<ScopeLike> | null | undefined;\n\n for (const [key, value] of Object.entries(context)) {\n if (key === \"tags\") {\n const tagMap = asFlatStringTagMap(value);\n if (tagMap) {\n if (typeof target?.setTag === \"function\") {\n for (const [tagKey, tagValue] of Object.entries(tagMap)) {\n target.setTag(tagKey, tagValue);\n }\n }\n continue;\n }\n }\n\n if (typeof target?.setExtra === \"function\") target.setExtra(key, value);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttt-productions/monitoring-core",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ttt-productions/ttt-packages.git",