@sincpro/client-framework 2.4.0 → 2.6.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/AGENTS.md CHANGED
@@ -210,6 +210,12 @@ options)`: no route, no verb, no RPC method. The contract's bindings (`rest`, `r
210
210
  its optional entry, and nothing else imports one (`make doctor`).
211
211
  - **A span nothing records claims no trace.** OpenTelemetry's API with no provider answers an
212
212
  all-zeros span: the adapter gives no ids, so no `traceparent` of zeros reaches the server.
213
+ - **A run with no parent may start under the application's active span — only when asked.**
214
+ `openTelemetryTracer(tracer, { adoptActiveSpan: true })` reads `context.active()` for a span
215
+ given no parent, and nowhere else: a span given one (the run above, a delivered message) keeps
216
+ it, the framework never makes its own spans active (no `context.with`) and registers no context
217
+ manager — that is the application's (Node: what `NodeSDK` or `@vercel/otel` register, or
218
+ `AsyncLocalStorageContextManager`). Without one, as in a browser, it changes nothing.
213
219
  - **Reported means unexpected.** A `TransportError` the server answered with a 4xx is `refused`,
214
220
  an `AbortError` is `aborted`; neither is reported (`outcomeOf`). A bounded context adds its own
215
221
  with `expectErrors(...)`; a process replaces the rule with `ProcessOptions.outcomeOf`. Never
package/MANIFESTO.md CHANGED
@@ -23,11 +23,18 @@ The backend already answers how a use case is written, traced and reported. This
23
23
  every client the same answer, once: **a Feature written here runs in a browser, on a phone, in a
24
24
  server-side render, in a script and in a test, unchanged.**
25
25
 
26
+ And it serves many projects, not one. Each application chooses its shape — a single-page app, a
27
+ server render, both in one, a phone, a script —, its shell, its bundler and its style; this
28
+ package fixes only how a use case is written, run and observed, so every one of them is built
29
+ the same way underneath and read the same way when something goes wrong.
30
+
26
31
  ## What it is responsible for
27
32
 
28
33
  1. **Services.** A `Feature` executes a registered Command through `execute(dto)`;
29
34
  an `ApplicationService` composes its context's Features through `featureBus`, never another
30
- ApplicationService. Dependencies are typed attributes supplied by the bounded context.
35
+ ApplicationService. Dependencies are typed attributes supplied by the bounded context. A
36
+ service's name — what its span, its logs and its reports say — survives any build: where a
37
+ bundler renames classes, its registration gives it (`{ name }`).
31
38
  2. **Execution.** Every Command and event enters one execution pipeline, defined here: context,
32
39
  chain, span, log lines, outcome, report, error handlers — not handwritten by each service. An
33
40
  application changes it from outside through its extension points, as the backend's
@@ -38,7 +45,10 @@ server-side render, in a script and in a test, unchanged.**
38
45
  with its trace id; what the server already explained (a validation, a conflict), or what a
39
46
  bounded context declares expected, not reported.
40
47
  The platform plugs the implementation — OpenTelemetry, GlitchTip, a queue on the phone, memory
41
- in a test — once, for the process (`configureProcess`). Structured logs are tagged by layer
48
+ in a test — once, for the process (`configureProcess`). One trace crosses the platforms: a run
49
+ carries its `traceparent` to the server, and where the platform holds a span of its own — a
50
+ server render's request — a run can start under it (`adoptActiveSpan`), so a page, its reads
51
+ and what the backend did are one tree. Structured logs are tagged by layer
42
52
  (infrastructure, adapter, bounded context, ApplicationService, Feature) and by execution;
43
53
  console filtering never controls another sink's delivery.
44
54
  4. **Context.** The levels a call sees — the process, its bounded context, a scope — read once
@@ -131,6 +141,10 @@ server-side render, in a script and in a test, unchanged.**
131
141
  dependency it can avoid.
132
142
  9. **Grow by evidence.** Nothing before its second use; every change ships with a test that fails
133
143
  without it.
144
+ 10. **Grow without breaking.** A new capability arrives as an option, never as a change to what
145
+ exists. Every form keeps working — standard decorators, legacy decorators, the plain call —
146
+ on every platform and in every rendering: a single-page app, a server render, a phone. An
147
+ application upgrades by changing a version number; nothing is deprecated to make room.
134
148
 
135
149
  ## How it is composed
136
150
 
@@ -195,6 +209,11 @@ whatever backend — in the backend's kinds and next steps; retrying, setting as
195
209
  a screen's answer follow from it. A run can be cancelled, and its requests with it. The
196
210
  backend's circuit breaker guards any transport.
197
211
 
212
+ **A server render is one more client.** It runs the same use cases through the same pipeline;
213
+ its runs keep the names their registrations give, and nest under the request the server traces
214
+ when the application opts in. Nothing here knows which renderer, router or framework drew the
215
+ page.
216
+
198
217
  **Consumers have a guide.** The `sincpro-client-framework` skill says, for an application and for
199
218
  a platform's framework, what goes where and how each thing is done.
200
219
 
package/README.md CHANGED
@@ -581,11 +581,59 @@ name: an application's own object (an Odoo client with a `call`) reaches its use
581
581
  ignored: telling about a use case never changes its answer.
582
582
 
583
583
  The vendor entries wrap what the application built — they initialize nothing, read no
584
- environment and register nothing global. There is no context manager: the trace reaches the
584
+ environment and register nothing global. No context manager is needed: the trace reaches the
585
585
  wire through the transport. On the web, leave the backend's origin out of OpenTelemetry's
586
586
  automatic `fetch` instrumentation (`ignoreUrls`), or it writes a `traceparent` of a trace of its
587
587
  own over this one.
588
588
 
589
+ ### One trace from a server render
590
+
591
+ A run's parent is the run above it, or the message it continues — never what is active in
592
+ OpenTelemetry's context —, so a use case with neither starts a trace of its own. A server that
593
+ renders pages (Next.js) keeps a span of its own active while it renders; to have the use cases
594
+ the render runs start under it — one trace: render → use case → API —, opt in:
595
+
596
+ ```ts
597
+ import { context } from "@opentelemetry/api";
598
+ import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
599
+
600
+ // once, where the server registers its provider — NodeSDK and @vercel/otel already do this
601
+ context.setGlobalContextManager(new AsyncLocalStorageContextManager().enable());
602
+
603
+ configureProcess({
604
+ tracer: openTelemetryTracer(provider.getTracer("forge-web"), { adoptActiveSpan: true }),
605
+ });
606
+ ```
607
+
608
+ - **Only a run with no parent reads the active span.** A Feature under its ApplicationService, a
609
+ bounded context injected into a run, a run continuing a delivered message keep the parent they
610
+ are given — the active span is never mixed in —, and the framework never makes its own spans
611
+ active, so two renders at once never take each other's use cases. It is the backend's rule at
612
+ its root: sincpro_framework's use case is a child of the span active in its process.
613
+ - **It reads what the application registered, and registers nothing.** On Node that is a context
614
+ manager: `NodeSDK` and `@vercel/otel` register one; a bare `TracerProvider` does not, and then
615
+ the application registers `AsyncLocalStorageContextManager` itself, as above. Without one the
616
+ active context is the root and the option changes nothing.
617
+ - **In a browser it is harmless.** With no context manager registered (`browserTracer` registers
618
+ none) every root run starts its own trace, as without the option.
619
+ - **Off by default.** `openTelemetryTracer(tracer)` behaves as it always has.
620
+
621
+ ### A failure's detail: in the trace, or in the error tracker
622
+
623
+ A failed run's span carries its exception — an `exception` event with its type, message and stack
624
+ — and its message as the status. Where errors go to an error tracker with their trace id
625
+ (GlitchTip, through `sentryReporter`), keep the detail there:
626
+
627
+ ```ts
628
+ openTelemetryTracer(provider.getTracer("forge-web"), { recordExceptions: false });
629
+ ```
630
+
631
+ The failed span still says what failed — `error.type`, `sincpro.outcome`, `sincpro.fault` and an
632
+ ERROR status —, and the error tracker holds the message and the stack under its access rules, not
633
+ every backend that stores traces: in an ERP a failure's message can name a customer or an amount.
634
+ OpenTelemetry, too, moves away from exceptions as span events (2026). Default `true`: a span keeps
635
+ its exception, as it always has.
636
+
589
637
  ### Logging
590
638
 
591
639
  The application layer imports no logger. Two are predefined, for the code around the use cases:
@@ -1,5 +1,36 @@
1
1
  import { type Tracer as OtelTracer } from "@opentelemetry/api";
2
2
  import type { Tracer } from "../domain/tracing.js";
3
+ /** How `openTelemetryTracer` places a use case's span. Every option is off by default. */
4
+ export type OpenTelemetryTracerOptions = {
5
+ /**
6
+ * A span given no parent — a run with no run above it and no delivered message to continue —
7
+ * starts in OpenTelemetry's active context, a child of the span active there: a use case run
8
+ * while a server renders a page is a child of the render, one trace from the page to the API,
9
+ * as sincpro_framework's use case is a child of the span active in its process. A span given a
10
+ * parent keeps it, always — the active span is never mixed in —, and the framework never makes
11
+ * its own spans active, so two runs at once never take each other's. Default `false`: a run
12
+ * with no parent starts a trace of its own, whatever is active.
13
+ *
14
+ * It reads what the application registered and registers nothing. On Node that is a context
15
+ * manager: `AsyncLocalStorageContextManager` from `@opentelemetry/context-async-hooks`, or the
16
+ * one its SDK registers (`NodeSDK`, `@vercel/otel`). Without one the active context is the
17
+ * root and this changes nothing — so in a browser that registers none it is harmless; one that
18
+ * does (`ZoneContextManager`) has a root run start under the span active where it is executed.
19
+ */
20
+ readonly adoptActiveSpan?: boolean;
21
+ /**
22
+ * A failed run's span carries its exception — an `exception` event with its type, message and
23
+ * stack — and its message as the status. Default `true`, as always.
24
+ *
25
+ * `false` keeps a failed span to what the run sets (`error.type`, `sincpro.outcome`,
26
+ * `sincpro.fault`) and an ERROR status, without the message or the stack. Recommended where
27
+ * errors go to an error tracker with their trace id (GlitchTip, through `sentryReporter`): the
28
+ * detail lives there, under its access rules, and not in every backend that stores traces — in
29
+ * an ERP the message of a failure can name a customer or an amount. OpenTelemetry, too, moves
30
+ * away from exceptions as span events (2026).
31
+ */
32
+ readonly recordExceptions?: boolean;
33
+ };
3
34
  /**
4
35
  * The `Tracer` port over OpenTelemetry's API: every use case a span of whatever provider the
5
36
  * platform registered.
@@ -8,14 +39,20 @@ import type { Tracer } from "../domain/tracing.js";
8
39
  * const tracer = openTelemetryTracer(provider.getTracer("forge-web"));
9
40
  * configureProcess({ tracer });
10
41
  *
42
+ * // a server that renders pages (Next.js), with a context manager registered: a use case
43
+ * // the render runs is a child of the render's span
44
+ * openTelemetryTracer(provider.getTracer("forge-web"), { adoptActiveSpan: true });
45
+ *
11
46
  * Context: only `@opentelemetry/api`, which runs the same on every platform — the provider, its
12
47
  * exporter and where it sends are the platform's (the browser's OTLP over fetch, a phone's
13
48
  * queue, a server's SDK). An optional entry with an optional peer: an application that does not
14
49
  * import it installs nothing and ships nothing.
15
50
  *
16
- * The parent is given, never read from OpenTelemetry's context: a run carries its own execution
17
- * (`Execution`), so two use cases at once never take each other's span, and no context manager
18
- * (Zone.js) is needed. A span nothing records (a sampler said no, no provider registered)
19
- * answers no ids — so no `traceparent` claims a trace that does not exist.
51
+ * The parent is given — the run above, the message a run continues —, never read from
52
+ * OpenTelemetry's context: a run carries its own execution (`Execution`), so two use cases at
53
+ * once never take each other's span, and no context manager (Zone.js) is needed. A run given
54
+ * none starts a trace of its own; the one place the active context is read is there, and only
55
+ * when the application asks (`adoptActiveSpan`). A span nothing records (a sampler said no, no
56
+ * provider registered) answers no ids — so no `traceparent` claims a trace that does not exist.
20
57
  */
21
- export declare function openTelemetryTracer(tracer: OtelTracer): Tracer;
58
+ export declare function openTelemetryTracer(tracer: OtelTracer, { adoptActiveSpan, recordExceptions }?: OpenTelemetryTracerOptions): Tracer;
@@ -1,4 +1,4 @@
1
- import { isSpanContextValid, ROOT_CONTEXT, SpanKind, SpanStatusCode, trace, TraceFlags, } from "@opentelemetry/api";
1
+ import { context as otelContext, isSpanContextValid, ROOT_CONTEXT, SpanKind, SpanStatusCode, trace, TraceFlags, } from "@opentelemetry/api";
2
2
  /**
3
3
  * The `Tracer` port over OpenTelemetry's API: every use case a span of whatever provider the
4
4
  * platform registered.
@@ -7,32 +7,29 @@ import { isSpanContextValid, ROOT_CONTEXT, SpanKind, SpanStatusCode, trace, Trac
7
7
  * const tracer = openTelemetryTracer(provider.getTracer("forge-web"));
8
8
  * configureProcess({ tracer });
9
9
  *
10
+ * // a server that renders pages (Next.js), with a context manager registered: a use case
11
+ * // the render runs is a child of the render's span
12
+ * openTelemetryTracer(provider.getTracer("forge-web"), { adoptActiveSpan: true });
13
+ *
10
14
  * Context: only `@opentelemetry/api`, which runs the same on every platform — the provider, its
11
15
  * exporter and where it sends are the platform's (the browser's OTLP over fetch, a phone's
12
16
  * queue, a server's SDK). An optional entry with an optional peer: an application that does not
13
17
  * import it installs nothing and ships nothing.
14
18
  *
15
- * The parent is given, never read from OpenTelemetry's context: a run carries its own execution
16
- * (`Execution`), so two use cases at once never take each other's span, and no context manager
17
- * (Zone.js) is needed. A span nothing records (a sampler said no, no provider registered)
18
- * answers no ids — so no `traceparent` claims a trace that does not exist.
19
+ * The parent is given — the run above, the message a run continues —, never read from
20
+ * OpenTelemetry's context: a run carries its own execution (`Execution`), so two use cases at
21
+ * once never take each other's span, and no context manager (Zone.js) is needed. A run given
22
+ * none starts a trace of its own; the one place the active context is read is there, and only
23
+ * when the application asks (`adoptActiveSpan`). A span nothing records (a sampler said no, no
24
+ * provider registered) answers no ids — so no `traceparent` claims a trace that does not exist.
19
25
  */
20
- export function openTelemetryTracer(tracer) {
26
+ export function openTelemetryTracer(tracer, { adoptActiveSpan = false, recordExceptions = true } = {}) {
21
27
  return {
22
28
  start(name, options) {
23
- const parent = options.parent;
24
- const parentContext = parent !== undefined && parent.traceId !== "" && parent.spanId !== ""
25
- ? trace.setSpanContext(ROOT_CONTEXT, {
26
- traceId: parent.traceId,
27
- spanId: parent.spanId,
28
- traceFlags: parent.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
29
- isRemote: false,
30
- })
31
- : ROOT_CONTEXT;
32
29
  const span = tracer.startSpan(name, {
33
30
  kind: SpanKind.INTERNAL,
34
31
  ...(options.attributes ? { attributes: options.attributes } : {}),
35
- }, parentContext);
32
+ }, parentContextOf(options.parent, adoptActiveSpan));
36
33
  const own = span.spanContext();
37
34
  const valid = isSpanContextValid(own);
38
35
  const state = own.traceState?.serialize();
@@ -42,14 +39,32 @@ export function openTelemetryTracer(tracer) {
42
39
  sampled: valid && (own.traceFlags & TraceFlags.SAMPLED) === TraceFlags.SAMPLED,
43
40
  ...(state ? { state } : {}),
44
41
  set: (attributes) => void span.setAttributes(attributes),
45
- end: (outcome, error) => close(span, outcome, error),
42
+ end: (outcome, error) => close(span, outcome, recordExceptions ? error : undefined),
46
43
  };
47
44
  },
48
45
  };
49
46
  }
47
+ /**
48
+ * Where a span starts. Given a parent, under it — at the root when that parent traces nothing —,
49
+ * never in the active context: the run above, or the message it continues, is its parent. Given
50
+ * none, in the active context when the application asked for it, else at the root.
51
+ */
52
+ function parentContextOf(parent, adoptActiveSpan) {
53
+ if (parent === undefined)
54
+ return adoptActiveSpan ? otelContext.active() : ROOT_CONTEXT;
55
+ if (parent.traceId === "" || parent.spanId === "")
56
+ return ROOT_CONTEXT;
57
+ return trace.setSpanContext(ROOT_CONTEXT, {
58
+ traceId: parent.traceId,
59
+ spanId: parent.spanId,
60
+ traceFlags: parent.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
61
+ isRemote: false,
62
+ });
63
+ }
50
64
  /**
51
65
  * How the use case ended, said the way OpenTelemetry reads it: `failed` is an error — with its
52
- * exception on the span where it was raised, the only one handed it —; `refused` and `aborted`
66
+ * exception on the span where it was raised, the only one handed it, unless the application keeps
67
+ * the detail out of its traces (`recordExceptions: false`: no error is handed over) —; `refused` and `aborted`
53
68
  * are expected answers, never an error, the way the backend leaves a refusal out of its error
54
69
  * rate. `sincpro.outcome` (`ok` or the failure's kind), `sincpro.fault` and `error.type` are set
55
70
  * by the run before it ends.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/client-framework",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "description": "The client side of sincpro_framework, for every platform: Feature and ApplicationService traced and reported by default, applications made of domains, and the typed client generated from a service's contract. No React, no DOM.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -98,6 +98,7 @@
98
98
  "devDependencies": {
99
99
  "@eslint/js": "^10.0.1",
100
100
  "@opentelemetry/api": "1.10.0",
101
+ "@opentelemetry/context-async-hooks": "3.1.0",
101
102
  "@opentelemetry/sdk-trace": "3.1.0",
102
103
  "@sincpro/criteria": "^2.1.0",
103
104
  "@types/node": "^26.6.6",