Skip to content
Source
Sign inSign up

releaseResource.ts

24 lines1.1 KB

1import { type CliReleaseChannel, cliReleaseChannelOf } from "./cliRelease.ts";
2​
3export type ReleaseChannel = "dev" | CliReleaseChannel;
4​
5// Desktop PR preview builds are stamped `X.Y.Z-pr.<number>.<run>`; the CLI updater must not see them as preview.
6export const releaseChannelOf = (version: string): ReleaseChannel =>
7 /-pr\.\d+\.\d+$/.test(version) ? "preview" : cliReleaseChannelOf(version);
8​
9// Effect lets code attributes beat OTEL_RESOURCE_ATTRIBUTES, so the operator value is applied here.
10export const releaseResourceAttributes = (
11 channel: ReleaseChannel,
12 operatorAttributes: Readonly<Record<string, unknown>> = {},
13) => {
14 const operatorValue = (key: string) => {
15 const value = operatorAttributes[key];
16 return typeof value === "string" && value !== "" ? value : undefined;
17 };
18 return {
19 "t3code.release.channel": operatorValue("t3code.release.channel") ?? channel,
20 "deployment.environment.name":
21 operatorValue("deployment.environment.name") ??
22 (channel === "dev" ? "development" : channel === "preview" ? "staging" : "production"),
23 };
24};