@sealant/sdk-next 0.40.0-next.954 → 0.40.0-next.956

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.
@@ -14,6 +14,10 @@
14
14
  * tracer and the request carries the SDK's HTTP span. When nothing exports them, the request carries
15
15
  * the parent's own `traceparent`, so the server's span hangs off a span that exists. With no parent
16
16
  * and no exporting tracer the request carries no trace header at all.
17
+ *
18
+ * A caller that turned tracing off (`References.TracerEnabled`) or propagation off
19
+ * (`Tracer.DisablePropagation`) is continued by nothing: its requests carry no trace header, and a
20
+ * disabled span, whose IDs read `noop`, is never sent as a parent.
17
21
  */
18
22
  import { Context, Effect, Tracer } from "effect";
19
23
  import type { SealantTraceContext } from "../types.js";
@@ -14,8 +14,12 @@
14
14
  * tracer and the request carries the SDK's HTTP span. When nothing exports them, the request carries
15
15
  * the parent's own `traceparent`, so the server's span hangs off a span that exists. With no parent
16
16
  * and no exporting tracer the request carries no trace header at all.
17
+ *
18
+ * A caller that turned tracing off (`References.TracerEnabled`) or propagation off
19
+ * (`Tracer.DisablePropagation`) is continued by nothing: its requests carry no trace header, and a
20
+ * disabled span, whose IDs read `noop`, is never sent as a parent.
17
21
  */
18
- import { Context, Effect, Fiber, Option, Tracer } from "effect";
22
+ import { Context, Effect, Fiber, Option, References, Tracer } from "effect";
19
23
  import { HttpClient } from "effect/http";
20
24
  /** The `tracestate` a call forwards; set from the captured caller trace. */
21
25
  export const CallerTraceState = Context.Reference("@sealant/sdk/CallerTraceState", { defaultValue: () => undefined });
@@ -90,16 +94,26 @@ export function activeOpenTelemetryContext() {
90
94
  return undefined;
91
95
  }
92
96
  }
93
- /** The calling Effect fiber's span and exporting tracer, when a fiber is running this call. */
97
+ /** Whether `span` names a span a `traceparent` can carry: not a disabled one (`noop`). */
98
+ const isPropagatable = (span) => parseTraceparent(formatTraceparent(span)) !== undefined;
99
+ /**
100
+ * The calling Effect fiber's span and exporting tracer, when a fiber is running this call, and
101
+ * whether that fiber turned propagation off.
102
+ */
94
103
  const fromCallingFiber = () => {
95
104
  try {
96
105
  const fiber = Fiber.getCurrent();
97
106
  if (fiber === undefined)
98
107
  return undefined;
108
+ if (!fiber.getRef(References.TracerEnabled) || fiber.getRef(Tracer.DisablePropagation)) {
109
+ return { parent: undefined, tracer: undefined, propagationOff: true };
110
+ }
99
111
  const tracer = fiber.getRef(Tracer.Tracer);
112
+ const parent = Option.getOrUndefined(Context.getOption(fiber.context, Tracer.ParentSpan));
100
113
  return {
101
- parent: Option.getOrUndefined(Context.getOption(fiber.context, Tracer.ParentSpan)),
114
+ parent: parent !== undefined && isPropagatable(parent) ? parent : undefined,
102
115
  tracer: tracer === Tracer.nativeTracer ? undefined : tracer,
116
+ propagationOff: false,
103
117
  };
104
118
  }
105
119
  catch {
@@ -152,6 +166,9 @@ export function captureCallerTrace(provider) {
152
166
  if (handedTrace !== undefined)
153
167
  return handedTrace.trace;
154
168
  const fiber = fromCallingFiber();
169
+ // A caller that turned propagation off is continued by nothing, not by a fallback.
170
+ if (fiber?.propagationOff === true)
171
+ return undefined;
155
172
  if (fiber?.parent !== undefined) {
156
173
  return { parent: fiber.parent, tracer: fiber.tracer, tracestate: undefined };
157
174
  }
@@ -176,7 +193,7 @@ export const continueCallerTrace = (trace) => (effect) => {
176
193
  };
177
194
  /** The trace headers a raw `fetch` made for a captured caller trace carries. */
178
195
  export function traceHeaders(trace) {
179
- if (trace?.parent === undefined)
196
+ if (trace?.parent === undefined || !isPropagatable(trace.parent))
180
197
  return {};
181
198
  const traceparent = formatTraceparent(trace.parent);
182
199
  return trace.tracestate === undefined
@@ -216,6 +233,10 @@ const sdkSpanAttributes = (name) => ({
216
233
  * the module comment).
217
234
  */
218
235
  export const traceCall = (name, attributes, effect, route) => Effect.gen(function* () {
236
+ // A caller with tracing or propagation off: no span of the SDK's, and no trace header.
237
+ if (!(yield* References.TracerEnabled) || (yield* Tracer.DisablePropagation)) {
238
+ return yield* Effect.provideService(effect, HttpClient.TracerPropagationEnabled, false);
239
+ }
219
240
  const parent = yield* Effect.serviceOption(Tracer.ParentSpan);
220
241
  const tracer = yield* Effect.tracer;
221
242
  const templated = route === undefined || tracer === Tracer.nativeTracer
@@ -231,7 +252,7 @@ export const traceCall = (name, attributes, effect, route) => Effect.gen(functio
231
252
  if (tracer !== Tracer.nativeTracer)
232
253
  return yield* spanned;
233
254
  const unpropagated = Effect.provideService(spanned, HttpClient.TracerPropagationEnabled, false);
234
- if (Option.isNone(parent))
255
+ if (Option.isNone(parent) || !isPropagatable(parent.value))
235
256
  return yield* unpropagated;
236
257
  return yield* Effect.provideService(unpropagated, DirectTraceparent, formatTraceparent(parent.value));
237
258
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealant/sdk-next",
3
- "version": "0.40.0-next.954",
3
+ "version": "0.40.0-next.956",
4
4
  "description": "The fluent public SDK for Sealant — create a workspace, run a harness, replay the record.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -26,12 +26,12 @@
26
26
  "node": ">=20"
27
27
  },
28
28
  "dependencies": {
29
- "@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.954"
29
+ "@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.956"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "effect": "^4.0.5"
33
33
  },
34
- "gitHead": "2c48b2c38a9aa5701eaf1550b805b22733e05cba",
34
+ "gitHead": "86d7a0b83920466f1e6489c78a3b6db522193917",
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  }