@ah-monica/cloudflare 0.1.0 → 0.2.0

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
@@ -49,6 +49,24 @@ handlerで送信完了を処理結果に含めたい場合は、直接`await`し
49
49
  await monica.captureException(error, { tags: { trigger: "scheduled" } });
50
50
  ```
51
51
 
52
+ ## 送信が拒否されたとき
53
+
54
+ `422`(envelope schema 不正)のとき、既定で`console.warn`へ1行出す(Workersのログに出る)。
55
+
56
+ ```
57
+ monica: ingest rejected the envelope with 422 (invalid_envelope): 1 issue(s); $.items[0].request.method: Invalid type: Expected string
58
+ ```
59
+
60
+ 出力先を変える場合は`onDiagnostic`を渡す。`null`を渡すと何も出さない。
61
+ `flush()`の戻り値の`status` / `issues` / `error`からも取得できる。
62
+
63
+ `401`(鍵の失効・種別違い)を受けると、そのclientからは以後1回もPOSTしない。
64
+ `flush()`の戻り値の`stopped: true`と次の1行で分かる。
65
+
66
+ ```
67
+ monica: ingest rejected the envelope with 401 (invalid_key); no further envelopes will be sent
68
+ ```
69
+
52
70
  ## PII方針
53
71
 
54
72
  SDKは、例外message、stack、request、contextがPIIかどうかを推測せず、自動除去も
package/dist/client.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createCoreClient, createFetchTransport, } from "@ah-monica/core";
2
+ import { SDK_VERSION } from "./version.js";
2
3
  const DEFAULT_FLUSH_TIMEOUT_MS = 2_000;
3
4
  const DEFAULT_MAX_CAUSE_DEPTH = 10;
4
5
  const DEFAULT_MAX_STACK_FRAMES = 200;
@@ -16,12 +17,13 @@ export function createCloudflareClient(options) {
16
17
  fetch: options.fetch,
17
18
  maxRetries: options.maxRetries ?? 0,
18
19
  requestTimeoutMs: options.requestTimeoutMs,
20
+ onDiagnostic: options.onDiagnostic,
19
21
  }),
20
22
  environment: options.environment,
21
23
  release: options.release,
22
24
  sampleRate: options.sampleRate,
23
25
  beforeSend: options.beforeSend,
24
- sdk: { name: "@ah-monica/cloudflare", version: "0.1.0" },
26
+ sdk: { name: "@ah-monica/cloudflare", version: SDK_VERSION },
25
27
  });
26
28
  async function captureAndFlush(input, hint) {
27
29
  try {
@@ -86,7 +88,7 @@ function contextValues(context) {
86
88
  ? { breadcrumbs: context.breadcrumbs.map((breadcrumb) => ({ ...breadcrumb })) }
87
89
  : {}),
88
90
  ...(context.request ? { request: cloneRequest(context.request) } : {}),
89
- ...(context.fingerprint ? { fingerprint: [...context.fingerprint] } : {}),
91
+ ...(context.fingerprint?.length ? { fingerprint: [...context.fingerprint] } : {}),
90
92
  };
91
93
  }
92
94
  function cloneRequest(request) {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { createCloudflareClient } from "./client.js";
2
2
  export type { CloudflareCaptureContext, CloudflareClientOptions, MonicaCloudflareClient, WaitUntilContext, } from "./types.js";
3
- export type { BeforeSend, FlushResult, MonicaBreadcrumb, MonicaErrorItem, MonicaItem, MonicaLevel, MonicaRequest, MonicaUser, } from "@ah-monica/core";
3
+ export type { BeforeSend, FlushResult, MonicaBreadcrumb, MonicaErrorItem, MonicaItem, MonicaLevel, MonicaRequest, MonicaUser, TransportDiagnostic, TransportDiagnosticHandler, } from "@ah-monica/core";
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BeforeSend, FetchLike, FlushResult, MonicaBreadcrumb, MonicaLevel, MonicaRequest, MonicaUser } from "@ah-monica/core";
1
+ import type { BeforeSend, FetchLike, FlushResult, MonicaBreadcrumb, MonicaLevel, MonicaRequest, MonicaUser, TransportDiagnosticHandler } from "@ah-monica/core";
2
2
  export interface CloudflareClientOptions {
3
3
  dsn: string;
4
4
  environment: string;
@@ -9,6 +9,11 @@ export interface CloudflareClientOptions {
9
9
  maxRetries?: number;
10
10
  maxCauseDepth?: number;
11
11
  maxStackFrames?: number;
12
+ /**
13
+ * ingest が envelope を拒否したときの診断の受け取り先。既定は `console.warn` に
14
+ * 1 行出す(422 の `issues` の path を含む)。`null` を渡すと何も出さない。
15
+ */
16
+ onDiagnostic?: TransportDiagnosticHandler | null;
12
17
  /**
13
18
  * The application owns PII removal. MONICA does not infer which values are PII.
14
19
  * Return null to discard an event or return a sanitized event to send it.
@@ -0,0 +1,2 @@
1
+ /** package.json の version と同じ値。bun run version X.Y.Z が書き換える */
2
+ export declare const SDK_VERSION = "0.2.0";
@@ -0,0 +1,2 @@
1
+ /** package.json の version と同じ値。bun run version X.Y.Z が書き換える */
2
+ export const SDK_VERSION = "0.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ah-monica/cloudflare",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Cloudflare Workers adapter for sending application errors to MONICA",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -26,11 +26,11 @@
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "git+https://github.com/Accel-Hack/monica.git",
30
- "directory": "sdk/typescript/cloudflare"
29
+ "url": "git+https://github.com/Accel-Hack/monica-sdk-js.git",
30
+ "directory": "cloudflare"
31
31
  },
32
32
  "dependencies": {
33
- "@ah-monica/core": "0.1.0"
33
+ "@ah-monica/core": "0.2.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/bun": "^1.2.21",