@contractspec/lib.observability 3.4.0 → 3.4.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @contractspec/lib.observability
2
2
 
3
+ ## 3.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 78d56a4: fix: release workflow
8
+ - Updated dependencies [78d56a4]
9
+ - @contractspec/lib.contracts-integrations@3.4.2
10
+ - @contractspec/lib.contracts-spec@3.4.2
11
+ - @contractspec/lib.lifecycle@3.4.2
12
+
13
+ ## 3.4.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 8f47829: fix: circular import issue
18
+ - Updated dependencies [8f47829]
19
+ - @contractspec/lib.contracts-integrations@3.4.1
20
+ - @contractspec/lib.contracts-spec@3.4.1
21
+ - @contractspec/lib.lifecycle@3.4.1
22
+
3
23
  ## 3.4.0
4
24
 
5
25
  ### Minor Changes
package/dist/index.js CHANGED
@@ -148,7 +148,7 @@ class RootCauseAnalyzer {
148
148
  }
149
149
  }
150
150
 
151
- // src/tracing/index.ts
151
+ // src/tracing/core.ts
152
152
  import {
153
153
  SpanStatusCode,
154
154
  trace
@@ -217,7 +217,6 @@ async function traceModelSelection(fn, input) {
217
217
  return result;
218
218
  });
219
219
  }
220
-
221
220
  // src/telemetry/model-selection-telemetry.ts
222
221
  class ModelSelectionTelemetry {
223
222
  provider;
@@ -147,7 +147,7 @@ class RootCauseAnalyzer {
147
147
  }
148
148
  }
149
149
 
150
- // src/tracing/index.ts
150
+ // src/tracing/core.ts
151
151
  import {
152
152
  SpanStatusCode,
153
153
  trace
@@ -216,7 +216,6 @@ async function traceModelSelection(fn, input) {
216
216
  return result;
217
217
  });
218
218
  }
219
-
220
219
  // src/telemetry/model-selection-telemetry.ts
221
220
  class ModelSelectionTelemetry {
222
221
  provider;
@@ -0,0 +1,52 @@
1
+ // src/tracing/core.ts
2
+ import {
3
+ SpanStatusCode,
4
+ trace
5
+ } from "@opentelemetry/api";
6
+ var DEFAULT_TRACER_NAME = "@contractspec/lib.observability";
7
+ function getTracer(name = DEFAULT_TRACER_NAME) {
8
+ return trace.getTracer(name);
9
+ }
10
+ async function traceAsync(name, fn, tracerName) {
11
+ const tracer = getTracer(tracerName);
12
+ return tracer.startActiveSpan(name, async (span) => {
13
+ try {
14
+ const result = await fn(span);
15
+ span.setStatus({ code: SpanStatusCode.OK });
16
+ return result;
17
+ } catch (error) {
18
+ span.recordException(error);
19
+ span.setStatus({
20
+ code: SpanStatusCode.ERROR,
21
+ message: error instanceof Error ? error.message : String(error)
22
+ });
23
+ throw error;
24
+ } finally {
25
+ span.end();
26
+ }
27
+ });
28
+ }
29
+ function traceSync(name, fn, tracerName) {
30
+ const tracer = getTracer(tracerName);
31
+ return tracer.startActiveSpan(name, (span) => {
32
+ try {
33
+ const result = fn(span);
34
+ span.setStatus({ code: SpanStatusCode.OK });
35
+ return result;
36
+ } catch (error) {
37
+ span.recordException(error);
38
+ span.setStatus({
39
+ code: SpanStatusCode.ERROR,
40
+ message: error instanceof Error ? error.message : String(error)
41
+ });
42
+ throw error;
43
+ } finally {
44
+ span.end();
45
+ }
46
+ });
47
+ }
48
+ export {
49
+ traceSync,
50
+ traceAsync,
51
+ getTracer
52
+ };
@@ -0,0 +1,75 @@
1
+ // src/tracing/core.ts
2
+ import {
3
+ SpanStatusCode,
4
+ trace
5
+ } from "@opentelemetry/api";
6
+ var DEFAULT_TRACER_NAME = "@contractspec/lib.observability";
7
+ function getTracer(name = DEFAULT_TRACER_NAME) {
8
+ return trace.getTracer(name);
9
+ }
10
+ async function traceAsync(name, fn, tracerName) {
11
+ const tracer = getTracer(tracerName);
12
+ return tracer.startActiveSpan(name, async (span) => {
13
+ try {
14
+ const result = await fn(span);
15
+ span.setStatus({ code: SpanStatusCode.OK });
16
+ return result;
17
+ } catch (error) {
18
+ span.recordException(error);
19
+ span.setStatus({
20
+ code: SpanStatusCode.ERROR,
21
+ message: error instanceof Error ? error.message : String(error)
22
+ });
23
+ throw error;
24
+ } finally {
25
+ span.end();
26
+ }
27
+ });
28
+ }
29
+ function traceSync(name, fn, tracerName) {
30
+ const tracer = getTracer(tracerName);
31
+ return tracer.startActiveSpan(name, (span) => {
32
+ try {
33
+ const result = fn(span);
34
+ span.setStatus({ code: SpanStatusCode.OK });
35
+ return result;
36
+ } catch (error) {
37
+ span.recordException(error);
38
+ span.setStatus({
39
+ code: SpanStatusCode.ERROR,
40
+ message: error instanceof Error ? error.message : String(error)
41
+ });
42
+ throw error;
43
+ } finally {
44
+ span.end();
45
+ }
46
+ });
47
+ }
48
+
49
+ // src/tracing/model-selection.span.ts
50
+ async function traceModelSelection(fn, input) {
51
+ const startMs = performance.now();
52
+ return traceAsync("model.selection", async (span) => {
53
+ const result = await fn();
54
+ const durationMs = performance.now() - startMs;
55
+ span.setAttribute("model.selected", input.modelId);
56
+ span.setAttribute("model.provider", input.providerKey);
57
+ span.setAttribute("model.score", input.score);
58
+ span.setAttribute("model.alternatives_count", input.alternativesCount);
59
+ span.setAttribute("model.selection_duration_ms", durationMs);
60
+ span.setAttribute("model.reason", input.reason);
61
+ if (input.dimension) {
62
+ span.setAttribute("model.dimension", input.dimension);
63
+ }
64
+ if (input.constraints) {
65
+ span.setAttribute("model.constraints", JSON.stringify(input.constraints));
66
+ }
67
+ return result;
68
+ });
69
+ }
70
+ export {
71
+ traceSync,
72
+ traceModelSelection,
73
+ traceAsync,
74
+ getTracer
75
+ };
@@ -1,4 +1,4 @@
1
- // src/tracing/index.ts
1
+ // src/tracing/core.ts
2
2
  import {
3
3
  SpanStatusCode,
4
4
  trace
@@ -67,7 +67,6 @@ async function traceModelSelection(fn, input) {
67
67
  return result;
68
68
  });
69
69
  }
70
-
71
70
  // src/metrics/index.ts
72
71
  import {
73
72
  metrics
@@ -1,4 +1,4 @@
1
- // src/tracing/index.ts
1
+ // src/tracing/core.ts
2
2
  import {
3
3
  SpanStatusCode,
4
4
  trace
@@ -0,0 +1,4 @@
1
+ import { type Span, type Tracer } from '@opentelemetry/api';
2
+ export declare function getTracer(name?: string): Tracer;
3
+ export declare function traceAsync<T>(name: string, fn: (span: Span) => Promise<T>, tracerName?: string): Promise<T>;
4
+ export declare function traceSync<T>(name: string, fn: (span: Span) => T, tracerName?: string): T;
@@ -0,0 +1,53 @@
1
+ // @bun
2
+ // src/tracing/core.ts
3
+ import {
4
+ SpanStatusCode,
5
+ trace
6
+ } from "@opentelemetry/api";
7
+ var DEFAULT_TRACER_NAME = "@contractspec/lib.observability";
8
+ function getTracer(name = DEFAULT_TRACER_NAME) {
9
+ return trace.getTracer(name);
10
+ }
11
+ async function traceAsync(name, fn, tracerName) {
12
+ const tracer = getTracer(tracerName);
13
+ return tracer.startActiveSpan(name, async (span) => {
14
+ try {
15
+ const result = await fn(span);
16
+ span.setStatus({ code: SpanStatusCode.OK });
17
+ return result;
18
+ } catch (error) {
19
+ span.recordException(error);
20
+ span.setStatus({
21
+ code: SpanStatusCode.ERROR,
22
+ message: error instanceof Error ? error.message : String(error)
23
+ });
24
+ throw error;
25
+ } finally {
26
+ span.end();
27
+ }
28
+ });
29
+ }
30
+ function traceSync(name, fn, tracerName) {
31
+ const tracer = getTracer(tracerName);
32
+ return tracer.startActiveSpan(name, (span) => {
33
+ try {
34
+ const result = fn(span);
35
+ span.setStatus({ code: SpanStatusCode.OK });
36
+ return result;
37
+ } catch (error) {
38
+ span.recordException(error);
39
+ span.setStatus({
40
+ code: SpanStatusCode.ERROR,
41
+ message: error instanceof Error ? error.message : String(error)
42
+ });
43
+ throw error;
44
+ } finally {
45
+ span.end();
46
+ }
47
+ });
48
+ }
49
+ export {
50
+ traceSync,
51
+ traceAsync,
52
+ getTracer
53
+ };
@@ -1,5 +1,2 @@
1
- import { type Span, type Tracer } from '@opentelemetry/api';
1
+ export { getTracer, traceAsync, traceSync } from './core';
2
2
  export * from './model-selection.span';
3
- export declare function getTracer(name?: string): Tracer;
4
- export declare function traceAsync<T>(name: string, fn: (span: Span) => Promise<T>, tracerName?: string): Promise<T>;
5
- export declare function traceSync<T>(name: string, fn: (span: Span) => T, tracerName?: string): T;
@@ -0,0 +1,76 @@
1
+ // @bun
2
+ // src/tracing/core.ts
3
+ import {
4
+ SpanStatusCode,
5
+ trace
6
+ } from "@opentelemetry/api";
7
+ var DEFAULT_TRACER_NAME = "@contractspec/lib.observability";
8
+ function getTracer(name = DEFAULT_TRACER_NAME) {
9
+ return trace.getTracer(name);
10
+ }
11
+ async function traceAsync(name, fn, tracerName) {
12
+ const tracer = getTracer(tracerName);
13
+ return tracer.startActiveSpan(name, async (span) => {
14
+ try {
15
+ const result = await fn(span);
16
+ span.setStatus({ code: SpanStatusCode.OK });
17
+ return result;
18
+ } catch (error) {
19
+ span.recordException(error);
20
+ span.setStatus({
21
+ code: SpanStatusCode.ERROR,
22
+ message: error instanceof Error ? error.message : String(error)
23
+ });
24
+ throw error;
25
+ } finally {
26
+ span.end();
27
+ }
28
+ });
29
+ }
30
+ function traceSync(name, fn, tracerName) {
31
+ const tracer = getTracer(tracerName);
32
+ return tracer.startActiveSpan(name, (span) => {
33
+ try {
34
+ const result = fn(span);
35
+ span.setStatus({ code: SpanStatusCode.OK });
36
+ return result;
37
+ } catch (error) {
38
+ span.recordException(error);
39
+ span.setStatus({
40
+ code: SpanStatusCode.ERROR,
41
+ message: error instanceof Error ? error.message : String(error)
42
+ });
43
+ throw error;
44
+ } finally {
45
+ span.end();
46
+ }
47
+ });
48
+ }
49
+
50
+ // src/tracing/model-selection.span.ts
51
+ async function traceModelSelection(fn, input) {
52
+ const startMs = performance.now();
53
+ return traceAsync("model.selection", async (span) => {
54
+ const result = await fn();
55
+ const durationMs = performance.now() - startMs;
56
+ span.setAttribute("model.selected", input.modelId);
57
+ span.setAttribute("model.provider", input.providerKey);
58
+ span.setAttribute("model.score", input.score);
59
+ span.setAttribute("model.alternatives_count", input.alternativesCount);
60
+ span.setAttribute("model.selection_duration_ms", durationMs);
61
+ span.setAttribute("model.reason", input.reason);
62
+ if (input.dimension) {
63
+ span.setAttribute("model.dimension", input.dimension);
64
+ }
65
+ if (input.constraints) {
66
+ span.setAttribute("model.constraints", JSON.stringify(input.constraints));
67
+ }
68
+ return result;
69
+ });
70
+ }
71
+ export {
72
+ traceSync,
73
+ traceModelSelection,
74
+ traceAsync,
75
+ getTracer
76
+ };
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- // src/tracing/index.ts
2
+ // src/tracing/core.ts
3
3
  import {
4
4
  SpanStatusCode,
5
5
  trace
@@ -68,7 +68,6 @@ async function traceModelSelection(fn, input) {
68
68
  return result;
69
69
  });
70
70
  }
71
-
72
71
  // src/metrics/index.ts
73
72
  import {
74
73
  metrics
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- // src/tracing/index.ts
2
+ // src/tracing/core.ts
3
3
  import {
4
4
  SpanStatusCode,
5
5
  trace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/lib.observability",
3
- "version": "3.4.0",
3
+ "version": "3.4.2",
4
4
  "description": "OpenTelemetry-based observability primitives",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -27,17 +27,17 @@
27
27
  "typecheck": "tsc --noEmit"
28
28
  },
29
29
  "dependencies": {
30
- "@contractspec/lib.lifecycle": "3.4.0",
31
- "@contractspec/lib.contracts-spec": "3.4.0",
32
- "@contractspec/lib.contracts-integrations": "3.4.0"
30
+ "@contractspec/lib.lifecycle": "3.4.2",
31
+ "@contractspec/lib.contracts-spec": "3.4.2",
32
+ "@contractspec/lib.contracts-integrations": "3.4.2"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@opentelemetry/api": "*"
36
36
  },
37
37
  "devDependencies": {
38
- "@contractspec/tool.typescript": "3.4.0",
38
+ "@contractspec/tool.typescript": "3.4.2",
39
39
  "typescript": "^5.9.3",
40
- "@contractspec/tool.bun": "3.4.0"
40
+ "@contractspec/tool.bun": "3.4.2"
41
41
  },
42
42
  "exports": {
43
43
  ".": {
@@ -142,6 +142,12 @@
142
142
  "node": "./dist/node/tracing/index.js",
143
143
  "default": "./dist/tracing/index.js"
144
144
  },
145
+ "./tracing/core": {
146
+ "types": "./dist/tracing/core.d.ts",
147
+ "bun": "./dist/tracing/core.js",
148
+ "node": "./dist/node/tracing/core.js",
149
+ "default": "./dist/tracing/core.js"
150
+ },
145
151
  "./tracing/index": {
146
152
  "types": "./dist/tracing/index.d.ts",
147
153
  "bun": "./dist/tracing/index.js",
@@ -266,6 +272,12 @@
266
272
  "node": "./dist/node/tracing/index.js",
267
273
  "default": "./dist/tracing/index.js"
268
274
  },
275
+ "./tracing/core": {
276
+ "types": "./dist/tracing/core.d.ts",
277
+ "bun": "./dist/tracing/core.js",
278
+ "node": "./dist/node/tracing/core.js",
279
+ "default": "./dist/tracing/core.js"
280
+ },
269
281
  "./tracing/index": {
270
282
  "types": "./dist/tracing/index.d.ts",
271
283
  "bun": "./dist/tracing/index.js",