Skip to content

Commit b8cfbbd

Browse files
committed
chore: Automates versioning of manifest via changesets
1 parent 82e3aa2 commit b8cfbbd

File tree

4 files changed

+62
-37
lines changed

4 files changed

+62
-37
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
dist
3-
tmp
3+
tmp
4+
.env
5+
.env.*.local

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
{
22
"private": true,
33
"name": "@taskless/~core",
4-
"description": "",
5-
"version": "1.0.1",
4+
"description": "Core APM telemetry plugin for Taskless",
5+
"version": "0.0.7",
66
"author": "Taskless",
77
"license": "MIT",
88
"scripts": {
9-
"build": "run-s 'build:tsc' 'build:esbuild' 'build:extism' 'build:pack'",
9+
"build": "run-s 'build:tsc' 'build:esbuild' 'build:extism' 'build:pack' 'build:bundle'",
10+
"build:bundle": "pnpm dlx @taskless/pack@latest bundle --manifest ./dist/manifest.json --wasm ./dist/pack.wasm --out ./dist",
1011
"build:esbuild": "node esbuild.js",
1112
"build:extism": "extism-js dist/index.js -i src/index.d.ts -o dist/pack.wasm",
1213
"build:pack": "tsx scripts/packbuild.ts",
1314
"build:tsc": "tsc --noEmit",
1415
"codegen": "tsx scripts/generate.ts",
1516
"prepare": "husky",
1617
"prettier": "prettier",
18+
"push": "pnpm dlx @taskless/pack@latest publish --manifest ./dist/manifest.json --wasm ./dist/pack.wasm --env ./.env.publish.local",
1719
"syncpack": "syncpack",
18-
"test": "pnpm dlx @taskless/packcheck@latest --fixture ./test/fixture.json --manifest ./dist/manifest.json ./dist/plugin.wasm",
20+
"test": "pnpm dlx @taskless/pack@latest check --fixture ./test/fixture.json --manifest ./dist/manifest.json --wasm ./dist/pack.wasm",
1921
"tsx": "tsx",
2022
"xo": "xo"
2123
},
@@ -28,8 +30,8 @@
2830
"@changesets/cli": "^2.27.7",
2931
"@commitlint/cli": "^19.3.0",
3032
"@commitlint/config-conventional": "^19.2.2",
31-
"@extism/js-pdk": "^1.0.1",
32-
"@taskless/loader": "^0.0.27",
33+
"@extism/js-pdk": "^1.1.1",
34+
"@taskless/loader": "^0.0.29",
3335
"@types/node": "^22.13.5",
3436
"esbuild": "^0.19.6",
3537
"husky": "^9.0.11",

src/index.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ type Context = {
2020
start: number;
2121
};
2222

23-
type AnyResponse =
24-
| undefined
25-
| string
26-
| {
27-
error?: string;
28-
message?: string;
29-
err?: {
30-
type?: string;
31-
};
32-
};
23+
type AnyJsonResponse = {
24+
error?: string;
25+
message?: string;
26+
err?: {
27+
type?: string;
28+
};
29+
};
30+
31+
type AnyResponse = undefined | string | AnyJsonResponse;
3332

3433
const configuration = z
3534
.object({
@@ -55,32 +54,30 @@ export function pre() {
5554
return;
5655
}
5756

58-
const domain =
59-
(userConfig?.enableDomain ??
57+
const enableDomain =
58+
userConfig?.enableDomain ??
6059
manifest.fields.find((f) => f.name === "enableDomain")?.default ??
61-
true)
62-
? { domain: input.request.domain }
63-
: {};
60+
true;
61+
const domain = enableDomain ? input.request.domain : undefined;
6462

65-
const url =
66-
(userConfig?.enableUrl ??
63+
const enableUrl =
64+
userConfig?.enableUrl ??
6765
manifest.fields.find((f) => f.name === "enableUrl")?.default ??
68-
true)
69-
? { url: input.request.url }
70-
: {};
66+
true;
67+
const url = enableUrl ? input.request.url : undefined;
7168

72-
const path =
73-
(userConfig?.enablePath ??
69+
const enablePath =
70+
userConfig?.enablePath ??
7471
manifest.fields.find((f) => f.name === "enablePath")?.default ??
75-
true)
76-
? { path: input.request.path }
77-
: {};
72+
true;
73+
74+
const path = enablePath ? input.request.path : undefined;
7875

7976
writeOutput<PluginOutput<Context>>({
8077
capture: {
81-
...domain,
82-
...url,
83-
...path,
78+
domain,
79+
url,
80+
path,
8481
},
8582
context: {
8683
start: Date.now(),
@@ -107,7 +104,17 @@ export function post() {
107104

108105
let seenError: string | undefined;
109106
if (input.response?.status && input.response.status >= 400) {
110-
seenError = body?.error ?? body?.message ?? body?.err?.type;
107+
if (typeof body === "string") {
108+
try {
109+
const parsedBody = JSON.parse(body) as AnyJsonResponse;
110+
seenError =
111+
parsedBody.error ?? parsedBody.message ?? parsedBody.err?.type;
112+
} catch {
113+
// noop, the body wasn't JSON
114+
}
115+
} else if (typeof body === "object" && body !== null) {
116+
seenError = body?.error ?? body?.message ?? body?.err?.type;
117+
}
111118
}
112119

113120
const durationMs =

src/manifest.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import pk from "../package.json" with { type: "json" };
12
import { type Manifest } from "./__generated__/manifest.js";
23

34
export const manifest = {
45
schema: "pre2",
56
name: "core",
6-
version: "0.0.2",
7+
version: pk.version,
78
description:
89
"Taskless core Telemetry. The core telemetry contains common monitoring and logging found in APM-like solutions, and is a solid baseline for any observability stack.",
910
permissions: {
@@ -67,6 +68,19 @@ export const manifest = {
6768
aggregate: { p95: "core/durationMs" },
6869
},
6970
},
71+
{
72+
type: "step",
73+
title: "Response Time (p99)",
74+
definition: {
75+
bucket: { time: "HOUR" },
76+
series: {
77+
query: "core/domain = '%(dimension)s'",
78+
dimension: "core/domain",
79+
dimensionType: "string",
80+
},
81+
aggregate: { p99: "core/durationMs" },
82+
},
83+
},
7084
{
7185
type: "table",
7286
title: "Calls per Domain",

0 commit comments

Comments
 (0)