@sincpro/web-framework 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -373,8 +373,10 @@ import { configureProcess, processContext } from "@sincpro/client-framework";
373
373
  import { glitchtipReporter } from "@sincpro/web-framework/errors"; // optional
374
374
  import { browserTracer } from "@sincpro/web-framework/telemetry"; // optional
375
375
 
376
+ const release = "my-app:1.0.0"; // <name>:<version>, the backend's APP_RELEASE
376
377
  configureProcess({
377
- tracer: browserTracer({ endpoint: settings.otlp, service: "my-app", release }),
378
+ identity: { release }, // + tenant, when the deployment serves one
379
+ tracer: browserTracer({ endpoint: settings.otlp, release }),
378
380
  reporter: glitchtipReporter({ dsn: settings.glitchtip, release }),
379
381
  });
380
382
  processContext.set({ tenant_id: session.tenant }); // every use case runs with it and sends it
@@ -7,7 +7,7 @@ import type { ErrorReporter } from "@sincpro/client-framework";
7
7
  * // the application — domains/common/infrastructure/telemetry.ts
8
8
  * import { glitchtipReporter } from "./index.js";
9
9
  * const reporter = glitchtipReporter({ dsn: settings.glitchtip, release, environment });
10
- * configureProcess({ tracer, reporter }); // entrypoints/main.tsx
10
+ * configureProcess({ identity: { release }, tracer, reporter }); // entrypoints/main.tsx
11
11
  *
12
12
  * Context: optional on every count, like `./telemetry`: an entry of its own, `@sentry/browser`
13
13
  * an optional peer, and only a convenience — an application with its own client wraps it with
@@ -26,6 +26,7 @@ import type { ErrorReporter } from "@sincpro/client-framework";
26
26
  export type GlitchtipOptions = {
27
27
  /** The application's DSN. Public by nature: it ships to the browser. */
28
28
  dsn: string;
29
+ /** `<name>:<version>`, the same text as `configureProcess({ identity })`: GlitchTip's release. */
29
30
  release?: string;
30
31
  environment?: string;
31
32
  /** Fraction of errors sent, 0 to 1. Default 1. */
@@ -1,12 +1,13 @@
1
- import type { Attributes, Tracer } from "@sincpro/client-framework";
1
+ import { type Attributes, type Tracer } from "@sincpro/client-framework";
2
2
  /**
3
3
  * A `Tracer` for the browser, built from the application's own settings: OpenTelemetry's SDK
4
4
  * exporting OTLP/HTTP to the endpoint the application names.
5
5
  *
6
6
  * // the application — domains/common/infrastructure/telemetry.ts
7
7
  * import { browserTracer } from "./index.js";
8
- * const tracer = browserTracer({ endpoint: settings.otlp, service: "forge-web", release });
9
- * configureProcess({ tracer, reporter }); // entrypoints/main.tsx
8
+ * const release = "forge-web:1.4.0"; // the backend's APP_RELEASE
9
+ * const tracer = browserTracer({ endpoint: settings.otlp, release });
10
+ * configureProcess({ identity: { release }, tracer, reporter }); // entrypoints/main.tsx
10
11
  *
11
12
  * Context: optional on every count. It is an entry of its own that nothing else in this package
12
13
  * imports, and its SDK (`@opentelemetry/sdk-trace`, `@opentelemetry/exporter-trace-otlp-http`,
@@ -24,10 +25,14 @@ import type { Attributes, Tracer } from "@sincpro/client-framework";
24
25
  export type BrowserTracerOptions = {
25
26
  /** The application's OTLP/HTTP traces endpoint (`https://collector.example.com/v1/traces`). */
26
27
  endpoint: string;
27
- /** `service.name`: what this application is called in the traces. */
28
- service: string;
29
- /** `service.version`: the release running. */
28
+ /**
29
+ * `<name>:<version>` as deployed — the backend's `APP_RELEASE`, the same text
30
+ * `configureProcess({ identity })` takes. The resource's `release`, and `service.name` and
31
+ * `service.version` read out of it with the backend's rules (`identityOf`).
32
+ */
30
33
  release?: string;
34
+ /** `service.name`, when it is not the release's name. One of the two is needed. */
35
+ service?: string;
31
36
  /** `deployment.environment.name`: `production`, `staging`… */
32
37
  environment?: string;
33
38
  /** Headers the endpoint asks for. Never a secret: whatever ships to a browser is public. */
@@ -42,4 +47,10 @@ export type BrowserTracer = Tracer & {
42
47
  /** Sends what is buffered now. Called by itself when the page is hidden or left. */
43
48
  flush: () => Promise<void>;
44
49
  };
50
+ /**
51
+ * Who sends the traces, with sincpro_framework's keys: `service.name` and `service.version` read
52
+ * out of the release (`sincpro-forge-web:1.4.0` → `sincpro-forge-web`, `1.4.0`), the release
53
+ * itself, the environment and the application's own attributes.
54
+ */
55
+ export declare function tracerResource(options: BrowserTracerOptions): Attributes;
45
56
  export declare function browserTracer(options: BrowserTracerOptions): BrowserTracer;
@@ -1,3 +1,4 @@
1
+ import { identityOf, } from "@sincpro/client-framework";
1
2
  const SILENT = {
2
3
  traceId: "",
3
4
  spanId: "",
@@ -5,6 +6,21 @@ const SILENT = {
5
6
  set: () => undefined,
6
7
  end: () => undefined,
7
8
  };
9
+ /**
10
+ * Who sends the traces, with sincpro_framework's keys: `service.name` and `service.version` read
11
+ * out of the release (`sincpro-forge-web:1.4.0` → `sincpro-forge-web`, `1.4.0`), the release
12
+ * itself, the environment and the application's own attributes.
13
+ */
14
+ export function tracerResource(options) {
15
+ const identity = options.release ? identityOf(options.release) : undefined;
16
+ return {
17
+ "service.name": options.service ?? identity?.serviceName ?? "unknown_service",
18
+ ...(identity?.serviceVersion ? { "service.version": identity.serviceVersion } : {}),
19
+ ...(identity ? { release: identity.release } : {}),
20
+ ...(options.environment ? { "deployment.environment.name": options.environment } : {}),
21
+ ...options.attributes,
22
+ };
23
+ }
8
24
  export function browserTracer(options) {
9
25
  let ready = null;
10
26
  let flush = () => Promise.resolve();
@@ -20,21 +36,15 @@ export function browserTracer(options) {
20
36
  url: options.endpoint,
21
37
  ...(options.headers ? { headers: { ...options.headers } } : {}),
22
38
  });
39
+ const resource = tracerResource(options);
23
40
  const provider = new TracerProvider({
24
- resource: resourceFromAttributes({
25
- "service.name": options.service,
26
- ...(options.release ? { "service.version": options.release } : {}),
27
- ...(options.environment
28
- ? { "deployment.environment.name": options.environment }
29
- : {}),
30
- ...options.attributes,
31
- }),
41
+ resource: resourceFromAttributes(resource),
32
42
  sampler: new ParentBasedSampler({
33
43
  root: new TraceIdRatioBasedSampler(options.sampling ?? 1),
34
44
  }),
35
45
  spanProcessors: [new BatchSpanProcessor({ exporter })],
36
46
  });
37
- ready = openTelemetryTracer(provider.getTracer(options.service));
47
+ ready = openTelemetryTracer(provider.getTracer(String(resource["service.name"])));
38
48
  flush = () => provider.forceFlush();
39
49
  // A page that is hidden may never come back: what is buffered goes now.
40
50
  const leave = () => void flush().catch(() => undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "@opentelemetry/resources": "^3.1.0",
41
41
  "@opentelemetry/sdk-trace": "^3.1.0",
42
42
  "@sentry/browser": "^11.11.0",
43
- "@sincpro/client-framework": "^1.4.0",
43
+ "@sincpro/client-framework": "^1.5.0",
44
44
  "@sincpro/criteria": "^2.1.0",
45
45
  "@sincpro/criteria-react": "^2.1.0",
46
46
  "@sincpro/web-composer": "^1.6.0",
@@ -72,7 +72,7 @@
72
72
  "@opentelemetry/resources": "3.1.0",
73
73
  "@opentelemetry/sdk-trace": "3.1.0",
74
74
  "@sentry/browser": "11.11.0",
75
- "@sincpro/client-framework": "^1.4.0",
75
+ "@sincpro/client-framework": "^1.5.0",
76
76
  "@sincpro/criteria": "^2.1.0",
77
77
  "@sincpro/criteria-react": "^2.1.0",
78
78
  "@sincpro/web-composer": "^1.6.0",