Skip to content

Commit

Permalink
feat: Adds namsepacing by pack name
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodedrift committed Jan 21, 2025
1 parent 2598347 commit 5c85623
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-houses-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@taskless/loader": patch
---

Introduces namespacing. When recording telemetry, the Pack's name will be included as part of the telemetry item automatically. This allows multiple Packs to use the same name such as "status" without conflicts
11 changes: 8 additions & 3 deletions src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,20 @@ export const createHandler = ({
// get modules from parent scope
return getModules();
},
async onResult(result: PluginOutput) {
async onResult(pack: Pack, result: PluginOutput) {
for (const [key, value] of Object.entries(result.capture ?? {})) {
// name = @taskless/apm
// new key to be = @taskless/apm/durationMs
// remove an slashes from the key to prevent namespace issues
const cleanedKey = key.replaceAll("/", "");
const nskey = `${pack.name}/${cleanedKey}`;
capture({
requestId,
dimension: key,
dimension: nskey,
value: `${value}`,
});
logItem.dimensions.push({
name: key,
name: nskey,
value: `${value}`,
});
}
Expand Down
9 changes: 6 additions & 3 deletions src/lib/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ const createSandbox = async (
};

type getModulesCallback = () => Promise<Map<string, Promise<Plugin>>>;
type onResultCallback = (result: NonNullable<PluginOutput>) => Promise<void>;
type onResultCallback = (
pack: Pack,
result: NonNullable<PluginOutput>
) => Promise<void>;
type onErrorCallback = (error: any) => void;
type Callbacks = {
getModules: getModulesCallback;
Expand Down Expand Up @@ -119,7 +122,7 @@ export const runSandbox = async (
context[`${index}`] = result.context;
}

await callbacks.onResult(result);
await callbacks.onResult(pack, result);
})
);

Expand Down Expand Up @@ -162,7 +165,7 @@ export const runSandbox = async (
context[`${index}`] = result.context;
}

await callbacks.onResult(result);
await callbacks.onResult(pack, result);
})
);

Expand Down

0 comments on commit 5c85623

Please sign in to comment.