@uselemma/tracing 3.0.1 → 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
  *
@@ -17,7 +19,8 @@
17
19
  */
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
- * Wraps a tool function with a child span named `tool.<name>`.
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) => {
@@ -26,7 +29,8 @@ export declare function trace<Input = unknown, Output = unknown>(name: string, f
26
29
  */
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
- * Wraps an LLM call with a child span named `llm.<name>`.
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
@@ -39,7 +43,8 @@ export declare function tool<Input = unknown, Output = unknown>(name: string, fn
39
43
  */
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
- * Wraps a retrieval function with a child span named `retrieval.<name>`.
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":[],"mappings":"AAiCA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,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;;;;;;;GAOG;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;;;;;;;;;;;GAWG;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;;;;;;;GAOG;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"}
1
+ {"version":3,"file":"span-helpers.d.ts","sourceRoot":"","sources":["../src/span-helpers.ts"],"names":[],"mappings":"AAwCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,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,14 +12,20 @@ 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
- function spanHelper(spanName, fn) {
18
+ function spanHelper(spanName, fn, spanType) {
18
19
  return async function (input) {
19
20
  const tracer = api_1.trace.getTracer("lemma");
20
21
  return tracer.startActiveSpan(spanName, async (span) => {
22
+ if (spanType) {
23
+ span.setAttribute("span.type", spanType);
24
+ }
25
+ span.setAttribute("input.value", JSON.stringify(input) ?? "null");
21
26
  try {
22
27
  const result = await fn(input);
28
+ span.setAttribute("output.value", JSON.stringify(result) ?? "null");
23
29
  span.end();
24
30
  return result;
25
31
  }
@@ -38,6 +44,8 @@ function spanHelper(spanName, fn) {
38
44
  * Use this for any internal function you want to appear in the trace — tool
39
45
  * implementations, retrieval calls, preprocessing steps, etc.
40
46
  *
47
+ * Input and output are automatically captured as span attributes.
48
+ *
41
49
  * @param name - Span name shown in the Lemma trace view.
42
50
  * @param fn - Function to wrap. Receives the same input as the returned wrapper.
43
51
  *
@@ -53,7 +61,8 @@ function trace(name, fn) {
53
61
  return spanHelper(name, fn);
54
62
  }
55
63
  /**
56
- * Wraps a tool function with a child span named `tool.<name>`.
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`.
57
66
  *
58
67
  * @example
59
68
  * const lookupOrder = tool("lookup-order", async (orderId: string) => {
@@ -61,10 +70,11 @@ function trace(name, fn) {
61
70
  * });
62
71
  */
63
72
  function tool(name, fn) {
64
- return spanHelper(`tool.${name}`, fn);
73
+ return spanHelper(name, fn, "tool");
65
74
  }
66
75
  /**
67
- * Wraps an LLM call with a child span named `llm.<name>`.
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`.
68
78
  *
69
79
  * Prefer provider instrumentation (OpenInference) for automatic LLM spans
70
80
  * with prompt/completion/token attributes. Use this helper for custom or
@@ -76,10 +86,11 @@ function tool(name, fn) {
76
86
  * });
77
87
  */
78
88
  function llm(name, fn) {
79
- return spanHelper(`llm.${name}`, fn);
89
+ return spanHelper(name, fn, "generation");
80
90
  }
81
91
  /**
82
- * Wraps a retrieval function with a child span named `retrieval.<name>`.
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`.
83
94
  *
84
95
  * @example
85
96
  * const search = retrieval("vector-search", async (query: string) => {
@@ -87,6 +98,6 @@ function llm(name, fn) {
87
98
  * });
88
99
  */
89
100
  function retrieval(name, fn) {
90
- return spanHelper(`retrieval.${name}`, fn);
101
+ return spanHelper(name, fn, "retriever");
91
102
  }
92
103
  //# sourceMappingURL=span-helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"span-helpers.js","sourceRoot":"","sources":["../src/span-helpers.ts"],"names":[],"mappings":";;AAkDA,sBAKC;AAUD,oBAKC;AAcD,kBAKC;AAUD,8BAKC;AAxGD,4CAAwD;AAGxD;;;;;;;;GAQG;AACH,SAAS,UAAU,CACjB,QAAgB,EAChB,EAA8C;IAE9C,OAAO,KAAK,WAAW,KAAY;QACjC,MAAM,MAAM,GAAG,WAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAU,EAAE,EAAE;YAC3D,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,eAAe,CAAC,GAAY,CAAC,CAAC;gBACnC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,uBAAuB;gBACpD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,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"OpenTelemetry-based tracing module for Lemma",
5
5
  "license": "MIT",
6
6
  "author": "Lemma",