feat(core-shared): OTel resource builder

This commit is contained in:
2026-05-11 11:23:19 +02:00
parent 80e765c074
commit 12aeb8bf37
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { Resource } from "@opentelemetry/resources";
export type BuildResourceOpts = {
serviceName: string;
serviceVersion?: string;
environment: string;
namespace?: string;
};
/**
* Builds an OpenTelemetry Resource with semantic-convention attributes.
* Each app constructs its own resource at startup (per-app service name).
*/
export function buildResource(opts: BuildResourceOpts): Resource {
const attrs: Record<string, string> = {
"service.name": opts.serviceName,
"deployment.environment.name": opts.environment,
};
if (opts.serviceVersion) attrs["service.version"] = opts.serviceVersion;
if (opts.namespace) attrs["service.namespace"] = opts.namespace;
return new Resource(attrs);
}