@uselemma/tracing 3.0.2 → 3.0.3

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.
@@ -4,6 +4,8 @@
4
4
  * Use this for any internal function you want to appear in the trace — tool
5
5
  * implementations, retrieval calls, preprocessing steps, etc.
6
6
  *
7
+ * Input and output are automatically captured as span attributes.
8
+ *
7
9
  * @param name - Span name shown in the Lemma trace view.
8
10
  * @param fn - Function to wrap. Receives the same input as the returned wrapper.
9
11
  *
@@ -18,6 +20,7 @@
18
20
  export declare function trace<Input = unknown, Output = unknown>(name: string, fn: (input: Input) => Output | Promise<Output>): (input: Input) => Promise<Output>;
19
21
  /**
20
22
  * Wraps a tool function with a child span. Sets `span.type = "tool"`.
23
+ * Input and output are automatically captured as `input.value` / `output.value`.
21
24
  *
22
25
  * @example
23
26
  * const lookupOrder = tool("lookup-order", async (orderId: string) => {
@@ -27,6 +30,7 @@ export declare function trace<Input = unknown, Output = unknown>(name: string, f
27
30
  export declare function tool<Input = unknown, Output = unknown>(name: string, fn: (input: Input) => Output | Promise<Output>): (input: Input) => Promise<Output>;
28
31
  /**
29
32
  * Wraps an LLM call with a child span. Sets `span.type = "generation"`.
33
+ * Input and output are automatically captured as `input.value` / `output.value`.
30
34
  *
31
35
  * Prefer provider instrumentation (OpenInference) for automatic LLM spans
32
36
  * with prompt/completion/token attributes. Use this helper for custom or
@@ -40,6 +44,7 @@ export declare function tool<Input = unknown, Output = unknown>(name: string, fn
40
44
  export declare function llm<Input = unknown, Output = unknown>(name: string, fn: (input: Input) => Output | Promise<Output>): (input: Input) => Promise<Output>;
41
45
  /**
42
46
  * Wraps a retrieval function with a child span. Sets `span.type = "retriever"`.
47
+ * Input and output are automatically captured as `input.value` / `output.value`.
43
48
  *
44
49
  * @example
45
50
  * const search = retrieval("vector-search", async (query: string) => {
@@ -1 +1 @@
1
- {"version":3,"file":"span-helpers.d.ts","sourceRoot":"","sources":["../src/span-helpers.ts"],"names":[],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AAE,MAAM,GAAG,OAAO,EACrD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAC7C,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,CAAC,CAEnC;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EACpD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAC7C,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,CAAC,CAEnC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EACnD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAC7C,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,CAAC,CAEnC;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EACzD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAC7C,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,CAAC,CAEnC"}
@@ -12,7 +12,8 @@ const api_1 = require("@opentelemetry/api");
12
12
  * is currently active.
13
13
  *
14
14
  * The span ends when the function returns (or throws). Return values are
15
- * passed through unchanged.
15
+ * passed through unchanged. Input and output are automatically recorded as
16
+ * `input.value` and `output.value` span attributes.
16
17
  */
17
18
  function spanHelper(spanName, fn, spanType) {
18
19
  return async function (input) {
@@ -21,8 +22,10 @@ function spanHelper(spanName, fn, spanType) {
21
22
  if (spanType) {
22
23
  span.setAttribute("span.type", spanType);
23
24
  }
25
+ span.setAttribute("input.value", JSON.stringify(input) ?? "null");
24
26
  try {
25
27
  const result = await fn(input);
28
+ span.setAttribute("output.value", JSON.stringify(result) ?? "null");
26
29
  span.end();
27
30
  return result;
28
31
  }
@@ -41,6 +44,8 @@ function spanHelper(spanName, fn, spanType) {
41
44
  * Use this for any internal function you want to appear in the trace — tool
42
45
  * implementations, retrieval calls, preprocessing steps, etc.
43
46
  *
47
+ * Input and output are automatically captured as span attributes.
48
+ *
44
49
  * @param name - Span name shown in the Lemma trace view.
45
50
  * @param fn - Function to wrap. Receives the same input as the returned wrapper.
46
51
  *
@@ -57,6 +62,7 @@ function trace(name, fn) {
57
62
  }
58
63
  /**
59
64
  * Wraps a tool function with a child span. Sets `span.type = "tool"`.
65
+ * Input and output are automatically captured as `input.value` / `output.value`.
60
66
  *
61
67
  * @example
62
68
  * const lookupOrder = tool("lookup-order", async (orderId: string) => {
@@ -68,6 +74,7 @@ function tool(name, fn) {
68
74
  }
69
75
  /**
70
76
  * Wraps an LLM call with a child span. Sets `span.type = "generation"`.
77
+ * Input and output are automatically captured as `input.value` / `output.value`.
71
78
  *
72
79
  * Prefer provider instrumentation (OpenInference) for automatic LLM spans
73
80
  * with prompt/completion/token attributes. Use this helper for custom or
@@ -83,6 +90,7 @@ function llm(name, fn) {
83
90
  }
84
91
  /**
85
92
  * Wraps a retrieval function with a child span. Sets `span.type = "retriever"`.
93
+ * Input and output are automatically captured as `input.value` / `output.value`.
86
94
  *
87
95
  * @example
88
96
  * const search = retrieval("vector-search", async (query: string) => {
@@ -1 +1 @@
1
- {"version":3,"file":"span-helpers.js","sourceRoot":"","sources":["../src/span-helpers.ts"],"names":[],"mappings":";;AAsDA,sBAKC;AAUD,oBAKC;AAcD,kBAKC;AAUD,8BAKC;AA5GD,4CAAwD;AAGxD;;;;;;;;GAQG;AACH,SAAS,UAAU,CACj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IACL,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,KAAK,CACnB,IAAY,EACZ,EAA8C;IAE9C,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,IAAI,CAClB,IAAY,EACZ,EAA8C;IAE9C,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,GAAG,CACjB,IAAY,EACZ,EAA8C;IAE9C,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CACvB,IAAY,EACZ,EAA8C;IAE9C,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uselemma/tracing",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "OpenTelemetry-based tracing module for Lemma",
5
5
  "license": "MIT",
6
6
  "author": "Lemma",