Skip to content

Commit 847f8e1

Browse files
committed
feat: add runtime OpenTelemetry configuration interface for dynamic client resource building
1 parent 5d4d7d8 commit 847f8e1

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/packages/core/src/util/open-telemetry.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
import {resourceFromAttributes} from "@opentelemetry/resources";
22

3-
export const resource = resourceFromAttributes({
4-
...(process.env.NEXT_PUBLIC_OTEL_SERVICE_NAME ? {'service.name': process.env.NEXT_PUBLIC_OTEL_SERVICE_NAME} : {}),
5-
'service.version': (process.env.NEXT_PUBLIC_SCULPTOR_VERSION ?? "0.0.0") + "-" + (process.env.NEXT_PUBLIC_EDITION ?? "edition"),
6-
...(process.env.NEXT_PUBLIC_OTEL_ENVIRONMENT ? {'deployment.environment.name': process.env.NEXT_PUBLIC_OTEL_ENVIRONMENT} : {}),
3+
/**
4+
* Runtime OpenTelemetry configuration for the browser. These values are served
5+
* by the `/api/config` route handler and read on the server at request
6+
* time, so they can be changed at runtime without rebuilding the app (unlike
7+
* `NEXT_PUBLIC_*` variables, which are inlined at build time).
8+
*/
9+
export interface ClientOtelConfig {
10+
tracesEndpoint?: string | null
11+
logsEndpoint?: string | null
12+
header?: string | null
13+
serviceName?: string | null
14+
environment?: string | null
15+
version?: string | null
16+
edition?: string | null
17+
}
18+
19+
export const buildClientResource = (config: ClientOtelConfig) => resourceFromAttributes({
20+
...(config.serviceName ? {'service.name': config.serviceName} : {}),
21+
'service.version': (config.version ?? "0.0.0") + "-" + (config.edition ?? "edition"),
22+
...(config.environment ? {'deployment.environment.name': config.environment} : {}),
723
});
824

925
export const serverResource = resourceFromAttributes({

0 commit comments

Comments
 (0)