@introspection-sdk/introspection-pi 0.12.0 → 0.14.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/README.md +63 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/instrument-session.d.ts +69 -0
- package/dist/instrument-session.d.ts.map +1 -0
- package/dist/instrument-session.js +48 -0
- package/dist/instrument-session.js.map +1 -0
- package/dist/instrument-stream.d.ts +2 -0
- package/dist/instrument-stream.d.ts.map +1 -1
- package/dist/instrument-stream.js.map +1 -1
- package/dist/scrubbing.d.ts +69 -0
- package/dist/scrubbing.d.ts.map +1 -0
- package/dist/scrubbing.js +60 -0
- package/dist/scrubbing.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,6 +16,42 @@ npm install @introspection-sdk/introspection-pi \
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
+
### One-call session attach
|
|
20
|
+
|
|
21
|
+
Hosts holding a live coding-agent session (an object exposing `agent` and
|
|
22
|
+
`sessionManager`) attach everything at once — chat spans through the
|
|
23
|
+
wrapped stream function, `execute_tool` spans per tool call, one
|
|
24
|
+
`invoke_agent` span per run that the others nest under, and structural
|
|
25
|
+
compaction detection from the session tree:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { trace } from "@opentelemetry/api";
|
|
29
|
+
import { instrumentSession } from "@introspection-sdk/introspection-pi";
|
|
30
|
+
|
|
31
|
+
const handle = instrumentSession(session, {
|
|
32
|
+
tracer: trace.getTracer("my-app"),
|
|
33
|
+
meta: { conversationId, agentId, agentName },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Later, on shutdown — restores the stream function, finalizes open spans:
|
|
37
|
+
handle.detach();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Hosts that already create their own turn/run spans keep their topology:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
instrumentSession(session, {
|
|
44
|
+
tracer,
|
|
45
|
+
meta,
|
|
46
|
+
runSpans: false,
|
|
47
|
+
getParentContext: () => currentTurnContext,
|
|
48
|
+
abortTerminationReason: () => (userRequestedStop ? "cancelled" : null),
|
|
49
|
+
extraAttributes: () => ({ "tenant.id": tenantId }),
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Composing the pieces yourself
|
|
54
|
+
|
|
19
55
|
```ts
|
|
20
56
|
import { trace } from "@opentelemetry/api";
|
|
21
57
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
@@ -121,6 +157,33 @@ For each tool call (`execute_tool ${tool_name}` span):
|
|
|
121
157
|
requested abort are marked with `introspection.termination_reason =
|
|
122
158
|
"cancelled"` and are not marked as errors.
|
|
123
159
|
|
|
160
|
+
## Content scrubbing
|
|
161
|
+
|
|
162
|
+
gen_ai spans carry full conversation content. Hosts that export one span
|
|
163
|
+
stream to two backends with different data policies — whole spans to a
|
|
164
|
+
conversation store, structure-only to infrastructure observability — wrap
|
|
165
|
+
the second backend's exporter:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { GenAiContentScrubbingExporter } from "@introspection-sdk/introspection-pi";
|
|
169
|
+
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
170
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
171
|
+
|
|
172
|
+
new BatchSpanProcessor(
|
|
173
|
+
new GenAiContentScrubbingExporter(new OTLPTraceExporter()),
|
|
174
|
+
);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The wrapper strips the content-bearing attributes (input/output messages,
|
|
178
|
+
system instructions, tool definitions/arguments/results, and the
|
|
179
|
+
`gen_ai_encrypted.*` mirror) while keeping the structural signal
|
|
180
|
+
(operation, provider, model, usage, timing, tool names). Scrubbing is
|
|
181
|
+
decided per attribute on every span — content keys only exist on gen_ai
|
|
182
|
+
spans, so no scope configuration is needed and none can fail open — and
|
|
183
|
+
the original span object is never mutated, so a second processor on the
|
|
184
|
+
same stream still sees it whole. `isGenAiContentAttribute(key)` exposes
|
|
185
|
+
the predicate for hosts that scrub in their own pipeline.
|
|
186
|
+
|
|
124
187
|
## License
|
|
125
188
|
|
|
126
189
|
Apache-2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -11,16 +11,27 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
+
* import { instrumentSession } from "@introspection-sdk/introspection-pi";
|
|
15
|
+
*
|
|
16
|
+
* // One-call attach for a live coding-agent session:
|
|
17
|
+
* const handle = instrumentSession(session, { tracer, meta });
|
|
18
|
+
* // later: handle.detach();
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
14
23
|
* import { instrumentAgent, instrumentStream } from "@introspection-sdk/introspection-pi";
|
|
15
24
|
*
|
|
25
|
+
* // Or compose the pieces yourself:
|
|
16
26
|
* agent.streamFn = instrumentStream(agent.streamFn, { tracer, meta });
|
|
17
27
|
* const tools = instrumentAgent(agent, { tracer, meta });
|
|
18
|
-
*
|
|
19
28
|
* // later: tools.stop();
|
|
20
29
|
* ```
|
|
21
30
|
*/
|
|
22
31
|
export { instrumentStream, type InstrumentStreamOptions, } from "./instrument-stream.js";
|
|
23
32
|
export { instrumentAgent, type AgentInstrumentation, type InstrumentAgentOptions, } from "./instrument-agent.js";
|
|
33
|
+
export { instrumentSession, type InstrumentableAgentSession, type InstrumentSessionOptions, type SessionInstrumentation, } from "./instrument-session.js";
|
|
34
|
+
export { GenAiContentScrubbingExporter, isGenAiContentAttribute, scrubGenAiContent, type ScrubbableSpan, type SpanExporterLike, } from "./scrubbing.js";
|
|
24
35
|
export { chatRequestAttributes, chatResponseAttributes, executeToolAttributes, executeToolResultAttribute, invokeAgentAttributes, serverAttributes, type AgentMeta, } from "./attributes.js";
|
|
25
36
|
export { genAiMetrics, type GenAiMetrics } from "./metrics.js";
|
|
26
37
|
export { assistantToOutputMessages, inputMessagesToMessages, messagesToInputMessages, semconvFinishReason, systemPromptToInstructions, type ConvertOptions, } from "./convert.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,GAC5B,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAK/D,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,0BAA0B,EAC1B,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,WAAW,EACX,WAAW,EACX,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,GACb,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,17 +11,30 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
+
* import { instrumentSession } from "@introspection-sdk/introspection-pi";
|
|
15
|
+
*
|
|
16
|
+
* // One-call attach for a live coding-agent session:
|
|
17
|
+
* const handle = instrumentSession(session, { tracer, meta });
|
|
18
|
+
* // later: handle.detach();
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
14
23
|
* import { instrumentAgent, instrumentStream } from "@introspection-sdk/introspection-pi";
|
|
15
24
|
*
|
|
25
|
+
* // Or compose the pieces yourself:
|
|
16
26
|
* agent.streamFn = instrumentStream(agent.streamFn, { tracer, meta });
|
|
17
27
|
* const tools = instrumentAgent(agent, { tracer, meta });
|
|
18
|
-
*
|
|
19
28
|
* // later: tools.stop();
|
|
20
29
|
* ```
|
|
21
30
|
*/
|
|
22
31
|
// Instrumentation
|
|
23
32
|
export { instrumentStream, } from "./instrument-stream.js";
|
|
24
33
|
export { instrumentAgent, } from "./instrument-agent.js";
|
|
34
|
+
export { instrumentSession, } from "./instrument-session.js";
|
|
35
|
+
// Content scrubbing — for hosts exporting one span stream to two backends
|
|
36
|
+
// with different data policies (whole spans vs structure-only)
|
|
37
|
+
export { GenAiContentScrubbingExporter, isGenAiContentAttribute, scrubGenAiContent, } from "./scrubbing.js";
|
|
25
38
|
// Attribute builders — exposed for callers that want to compose their own spans
|
|
26
39
|
export { chatRequestAttributes, chatResponseAttributes, executeToolAttributes, executeToolResultAttribute, invokeAgentAttributes, serverAttributes, } from "./attributes.js";
|
|
27
40
|
// Metric instruments — exposed for callers that record their own measurements
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,kBAAkB;AAClB,OAAO,EACL,gBAAgB,GAEjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,GAGhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,GAIlB,MAAM,yBAAyB,CAAC;AAEjC,0EAA0E;AAC1E,+DAA+D;AAC/D,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,iBAAiB,GAGlB,MAAM,gBAAgB,CAAC;AAExB,gFAAgF;AAChF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,iBAAiB,CAAC;AAEzB,8EAA8E;AAC9E,OAAO,EAAE,YAAY,EAAqB,MAAM,cAAc,CAAC;AAE/D,6EAA6E;AAC7E,0EAA0E;AAC1E,kBAAkB;AAClB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,0BAA0B,GAE3B,MAAM,cAAc,CAAC;AAiBtB,OAAO,EACL,KAAK,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,GACb,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-call session attach: wrap a live Pi agent session so it emits the full
|
|
3
|
+
* GenAI semconv span set — `chat {model}` spans via the wrapped stream
|
|
4
|
+
* function, `execute_tool` spans via the agent subscription, and (by
|
|
5
|
+
* default) one `invoke_agent` span per run that the others nest under.
|
|
6
|
+
*
|
|
7
|
+
* This is the seam every host shares. Hosts that create their own turn/run
|
|
8
|
+
* spans pass `runSpans: false` plus `getParentContext` (and optionally
|
|
9
|
+
* `abortTerminationReason` / `extraAttributes`) so chat and tool spans nest
|
|
10
|
+
* under the host's spans instead of a package-created run span.
|
|
11
|
+
*
|
|
12
|
+
* Compaction summaries are sourced structurally from the session tree
|
|
13
|
+
* (`sessionManager.getEntries()` filtered to `type === "compaction"`), so
|
|
14
|
+
* detection does not depend on the prose wrapper pi renders around them —
|
|
15
|
+
* callers no longer wire `getCompactionSummaries` by hand.
|
|
16
|
+
*/
|
|
17
|
+
import { type Attributes, type Context as OtelContext, type Meter, type Tracer } from "@opentelemetry/api";
|
|
18
|
+
import type { Agent } from "@earendil-works/pi-agent-core";
|
|
19
|
+
import { type AbortTerminationReason } from "@introspection-sdk/types";
|
|
20
|
+
import { type AgentMeta } from "./attributes.js";
|
|
21
|
+
/**
|
|
22
|
+
* The structural slice of a pi coding-agent `AgentSession` this attach
|
|
23
|
+
* needs: the agent (stream function + event subscription) and the session
|
|
24
|
+
* tree (compaction summaries). Typed structurally so the package keeps no
|
|
25
|
+
* dependency on the session host package.
|
|
26
|
+
*/
|
|
27
|
+
export interface InstrumentableAgentSession {
|
|
28
|
+
agent: Agent;
|
|
29
|
+
sessionManager: {
|
|
30
|
+
getEntries(): readonly unknown[];
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface InstrumentSessionOptions {
|
|
34
|
+
/** Tracer the gen_ai spans are started on. */
|
|
35
|
+
tracer: Tracer;
|
|
36
|
+
/** Span identity for this session. */
|
|
37
|
+
meta: AgentMeta;
|
|
38
|
+
/** Optional meter for the GenAI client metrics. */
|
|
39
|
+
meter?: Meter;
|
|
40
|
+
/**
|
|
41
|
+
* Emit one `invoke_agent` span per run and nest chat/tool spans under it.
|
|
42
|
+
* Hosts that create their own turn/run spans set false and supply
|
|
43
|
+
* `getParentContext` instead. Default: true.
|
|
44
|
+
*/
|
|
45
|
+
runSpans?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Parent context for chat and tool spans. Default: the active run span
|
|
48
|
+
* (when `runSpans` is on), else the active OTel context.
|
|
49
|
+
*/
|
|
50
|
+
getParentContext?: () => OtelContext | null | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Classify a chat stream that ended via the caller's AbortSignal:
|
|
53
|
+
* `"cancelled"` / `"awaiting_user"` end the span cleanly, `null` keeps
|
|
54
|
+
* the abort classified as an error. Default: aborts are `"cancelled"`.
|
|
55
|
+
*/
|
|
56
|
+
abortTerminationReason?: () => AbortTerminationReason | null;
|
|
57
|
+
/** Host attributes (tenant labels, correlation ids) added to every span. */
|
|
58
|
+
extraAttributes?: () => Attributes;
|
|
59
|
+
}
|
|
60
|
+
export interface SessionInstrumentation {
|
|
61
|
+
/** Restore the original stream function and finalize any open spans. */
|
|
62
|
+
detach: () => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Attach the GenAI instrumentation to a live session. Returns a handle
|
|
66
|
+
* whose `detach()` restores the stream function and finalizes open spans.
|
|
67
|
+
*/
|
|
68
|
+
export declare function instrumentSession(session: InstrumentableAgentSession, opts: InstrumentSessionOptions): SessionInstrumentation;
|
|
69
|
+
//# sourceMappingURL=instrument-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument-session.d.ts","sourceRoot":"","sources":["../src/instrument-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,IAAI,WAAW,EAC3B,KAAK,KAAK,EACV,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAY,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,KAAK,CAAC;IACb,cAAc,EAAE;QAAE,UAAU,IAAI,SAAS,OAAO,EAAE,CAAA;KAAE,CAAC;CACtD;AAED,MAAM,WAAW,wBAAwB;IACvC,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,IAAI,EAAE,SAAS,CAAC;IAChB,mDAAmD;IACnD,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACxD;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,MAAM,sBAAsB,GAAG,IAAI,CAAC;IAC7D,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,UAAU,CAAC;CACpC;AAED,MAAM,WAAW,sBAAsB;IACrC,wEAAwE;IACxE,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AA6BD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,0BAA0B,EACnC,IAAI,EAAE,wBAAwB,GAC7B,sBAAsB,CAoCxB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { instrumentAgent } from "./instrument-agent.js";
|
|
2
|
+
import { instrumentStream } from "./instrument-stream.js";
|
|
3
|
+
function streamFnKey(agent) {
|
|
4
|
+
return "streamFunction" in agent ? "streamFunction" : "streamFn";
|
|
5
|
+
}
|
|
6
|
+
function compactionSummaries(session) {
|
|
7
|
+
return session.sessionManager.getEntries()
|
|
8
|
+
.filter((entry) => entry.type === "compaction" && typeof entry.summary === "string")
|
|
9
|
+
.map((entry) => entry.summary);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Attach the GenAI instrumentation to a live session. Returns a handle
|
|
13
|
+
* whose `detach()` restores the stream function and finalizes open spans.
|
|
14
|
+
*/
|
|
15
|
+
export function instrumentSession(session, opts) {
|
|
16
|
+
const agent = session.agent;
|
|
17
|
+
const key = streamFnKey(session.agent);
|
|
18
|
+
const original = agent[key];
|
|
19
|
+
const extraAttributes = opts.extraAttributes;
|
|
20
|
+
const agentInstrumentation = instrumentAgent(session.agent, {
|
|
21
|
+
tracer: opts.tracer,
|
|
22
|
+
meta: opts.meta,
|
|
23
|
+
...(opts.meter ? { meter: opts.meter } : {}),
|
|
24
|
+
runSpans: opts.runSpans ?? true,
|
|
25
|
+
...(opts.getParentContext
|
|
26
|
+
? { getParentContext: opts.getParentContext }
|
|
27
|
+
: {}),
|
|
28
|
+
...(extraAttributes ? { extraAttributes: () => extraAttributes() } : {}),
|
|
29
|
+
});
|
|
30
|
+
agent[key] = instrumentStream(original, {
|
|
31
|
+
tracer: opts.tracer,
|
|
32
|
+
meta: opts.meta,
|
|
33
|
+
...(opts.meter ? { meter: opts.meter } : {}),
|
|
34
|
+
getParentContext: opts.getParentContext ?? (() => agentInstrumentation.getRunContext()),
|
|
35
|
+
...(opts.abortTerminationReason
|
|
36
|
+
? { abortTerminationReason: opts.abortTerminationReason }
|
|
37
|
+
: {}),
|
|
38
|
+
...(extraAttributes ? { extraAttributes: () => extraAttributes() } : {}),
|
|
39
|
+
getCompactionSummaries: () => compactionSummaries(session),
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
detach: () => {
|
|
43
|
+
agent[key] = original;
|
|
44
|
+
agentInstrumentation.stop();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=instrument-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument-session.js","sourceRoot":"","sources":["../src/instrument-session.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAqD1D,SAAS,WAAW,CAAC,KAAY;IAC/B,OAAO,gBAAgB,IAAI,KAAK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AC;KACzE,CAAC,CAAC;IAEH,KAAK,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,QAAQ,EAAE;QACtC,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,gBAAgB,EACd,IAAI,CAAC,gBAAgB,IAAI,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,aAAa,EAAE,CAAC;QACvE,GAAG,CAAC,IAAI,CAAC,sBAAsB;YAC7B,CAAC,CAAC,EAAE,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,EAAE;YACzD,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,sBAAsB,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC;KAC3D,CAAC,CAAC;IAEH,OAAO;QACL,MAAM,EAAE,GAAG,EAAE;YACX,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;YACtB,oBAAoB,CAAC,IAAI,EAAE,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -38,6 +38,8 @@ export interface InstrumentStreamOptions {
|
|
|
38
38
|
* `session.sessionManager.getEntries()` filtered to
|
|
39
39
|
* `type === "compaction"`, mapped to `summary` — so detection does not
|
|
40
40
|
* depend on the prose wrapper pi renders around the summary.
|
|
41
|
+
* (`instrumentSession` wires exactly this; prefer it when you hold a
|
|
42
|
+
* session rather than a bare stream function.)
|
|
41
43
|
*/
|
|
42
44
|
getCompactionSummaries?: () => readonly string[];
|
|
43
45
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrument-stream.d.ts","sourceRoot":"","sources":["../src/instrument-stream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAKL,KAAK,UAAU,EACf,KAAK,OAAO,IAAI,WAAW,EAC3B,KAAK,KAAK,EAEV,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKL,KAAK,GAAG,EACR,KAAK,OAAO,EACZ,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAIL,KAAK,sBAAsB,EAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,iBAAiB,CAAC;AAIzB,MAAM,WAAW,uBAAuB;IACtC,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,IAAI,EAAE,SAAS,CAAC;IAChB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACxD;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,UAAU,CAAC;IACtE,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IAC3D
|
|
1
|
+
{"version":3,"file":"instrument-stream.d.ts","sourceRoot":"","sources":["../src/instrument-stream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAKL,KAAK,UAAU,EACf,KAAK,OAAO,IAAI,WAAW,EAC3B,KAAK,KAAK,EAEV,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKL,KAAK,GAAG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AC;YACd,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;SACrE;QACD,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO;QACzC,YAAY;QACZ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content scrubbing for gen_ai spans: strip the attributes that carry
|
|
3
|
+
* conversation content while keeping the structural signal (operation,
|
|
4
|
+
* provider, model, usage, timing, tool names).
|
|
5
|
+
*
|
|
6
|
+
* For hosts that export one span stream to two backends with different data
|
|
7
|
+
* policies — e.g. whole spans to a conversation store, scrubbed spans to
|
|
8
|
+
* infrastructure observability — wrap the second backend's exporter:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* new BatchSpanProcessor(
|
|
12
|
+
* new GenAiContentScrubbingExporter(new OTLPTraceExporter()),
|
|
13
|
+
* )
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Scrubbing is decided per attribute, on every span, regardless of
|
|
17
|
+
* instrumentation scope: content-bearing keys only exist on gen_ai spans,
|
|
18
|
+
* so a scope filter adds no precision — only a way to fail open. Spans with
|
|
19
|
+
* no content attributes pass through untouched (same object).
|
|
20
|
+
*
|
|
21
|
+
* This lives beside the span producers on purpose: the list of
|
|
22
|
+
* content-bearing attributes must change in the same commit as the span
|
|
23
|
+
* shape that emits them.
|
|
24
|
+
*/
|
|
25
|
+
import type { Attributes } from "@opentelemetry/api";
|
|
26
|
+
/** True for a gen_ai attribute key that carries conversation content. */
|
|
27
|
+
export declare function isGenAiContentAttribute(key: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The structural slice of an SDK `ReadableSpan` scrubbing needs. Typed
|
|
30
|
+
* structurally so this package needs no dependency on
|
|
31
|
+
* `@opentelemetry/sdk-trace-base`; the real span types are assignable.
|
|
32
|
+
*/
|
|
33
|
+
export interface ScrubbableSpan {
|
|
34
|
+
attributes: Attributes;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The structural shape of an SDK `SpanExporter`, generic over the span type
|
|
38
|
+
* so wrapping a concrete exporter preserves it.
|
|
39
|
+
*/
|
|
40
|
+
export interface SpanExporterLike<S extends ScrubbableSpan = ScrubbableSpan> {
|
|
41
|
+
export(spans: S[], resultCallback: (result: {
|
|
42
|
+
code: number;
|
|
43
|
+
error?: Error;
|
|
44
|
+
}) => void): void;
|
|
45
|
+
shutdown(): Promise<void>;
|
|
46
|
+
forceFlush?(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return the span with content attributes removed, or the span itself when
|
|
50
|
+
* it has none. The copy is a per-span attribute view behind a Proxy — the
|
|
51
|
+
* original span object is never mutated, so a second processor exporting
|
|
52
|
+
* the same span still sees it whole.
|
|
53
|
+
*/
|
|
54
|
+
export declare function scrubGenAiContent<S extends ScrubbableSpan>(span: S): S;
|
|
55
|
+
/**
|
|
56
|
+
* Exporter wrapper: every span reaches the delegate with its conversation
|
|
57
|
+
* content stripped; spans without content attributes pass through untouched.
|
|
58
|
+
*/
|
|
59
|
+
export declare class GenAiContentScrubbingExporter<S extends ScrubbableSpan = ScrubbableSpan> implements SpanExporterLike<S> {
|
|
60
|
+
private readonly delegate;
|
|
61
|
+
constructor(delegate: SpanExporterLike<S>);
|
|
62
|
+
export(spans: S[], resultCallback: (result: {
|
|
63
|
+
code: number;
|
|
64
|
+
error?: Error;
|
|
65
|
+
}) => void): void;
|
|
66
|
+
shutdown(): Promise<void>;
|
|
67
|
+
forceFlush(): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=scrubbing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrubb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G5B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gen_ai attribute prefixes that carry conversation content, not structure:
|
|
3
|
+
* the plaintext message, system-instruction, and tool-definition/call
|
|
4
|
+
* sub-trees, plus the entire encrypted mirror (`gen_ai_encrypted.*`), which
|
|
5
|
+
* duplicates the content. Everything else under gen_ai (operation, provider,
|
|
6
|
+
* request/response model, usage, cost, agent, conversation, tool.name/type)
|
|
7
|
+
* is structural and is kept.
|
|
8
|
+
*/
|
|
9
|
+
const GENAI_CONTENT_PREFIXES = [
|
|
10
|
+
"gen_ai.input.",
|
|
11
|
+
"gen_ai.output.",
|
|
12
|
+
"gen_ai.system_instructions",
|
|
13
|
+
"gen_ai.tool.definitions",
|
|
14
|
+
"gen_ai.tool.call.arguments",
|
|
15
|
+
"gen_ai.tool.call.result",
|
|
16
|
+
"gen_ai_encrypted.",
|
|
17
|
+
];
|
|
18
|
+
/** True for a gen_ai attribute key that carries conversation content. */
|
|
19
|
+
export function isGenAiContentAttribute(key) {
|
|
20
|
+
return GENAI_CONTENT_PREFIXES.some((p) => key === p || key.startsWith(p));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Return the span with content attributes removed, or the span itself when
|
|
24
|
+
* it has none. The copy is a per-span attribute view behind a Proxy — the
|
|
25
|
+
* original span object is never mutated, so a second processor exporting
|
|
26
|
+
* the same span still sees it whole.
|
|
27
|
+
*/
|
|
28
|
+
export function scrubGenAiContent(span) {
|
|
29
|
+
if (!Object.keys(span.attributes).some(isGenAiContentAttribute)) {
|
|
30
|
+
return span;
|
|
31
|
+
}
|
|
32
|
+
const kept = {};
|
|
33
|
+
for (const [key, value] of Object.entries(span.attributes)) {
|
|
34
|
+
if (!isGenAiContentAttribute(key))
|
|
35
|
+
kept[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return new Proxy(span, {
|
|
38
|
+
get: (target, prop) => prop === "attributes" ? kept : Reflect.get(target, prop),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Exporter wrapper: every span reaches the delegate with its conversation
|
|
43
|
+
* content stripped; spans without content attributes pass through untouched.
|
|
44
|
+
*/
|
|
45
|
+
export class GenAiContentScrubbingExporter {
|
|
46
|
+
delegate;
|
|
47
|
+
constructor(delegate) {
|
|
48
|
+
this.delegate = delegate;
|
|
49
|
+
}
|
|
50
|
+
export(spans, resultCallback) {
|
|
51
|
+
this.delegate.export(spans.map((span) => scrubGenAiContent(span)), resultCallback);
|
|
52
|
+
}
|
|
53
|
+
shutdown() {
|
|
54
|
+
return this.delegate.shutdown();
|
|
55
|
+
}
|
|
56
|
+
forceFlush() {
|
|
57
|
+
return this.delegate.forceFlush?.() ?? Promise.resolve();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=scrubbing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrubbing.js","sourceRoot":"","sources":["../src/scrubbing.ts"],"names":[],"mappings":"AA0BA;;;;;;;GAOG;AACH,MAAM,sBAAsB,GAAG;IAC7B,eAAe;IACf,gBAAgB;IAChB,4BAA4B;IAC5B,yBAAyB;IACzB,4BAA4B;IAC5B,yBAAyB;IACzB,mBAAmB;CACX,CAAC;AAEX,yEAAyE;AACzE,MAAM,UAAU,uBAAuB,CAAC,GAAW;IACjD,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC;AAwBD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAA2B,IAAO;IACjE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAAC;QAChE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,GAAe,EAAE,CAAC;IAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3D,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;QACrB,GAAG,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CACpB,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;KAC3D,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,6BAA6B;IAGX;IAA7B,YAA6B,QAA6B;QAA7B,aAAQ,GAAR,QAAQ,CAAqB;IAAG,CAAC;IAE9D,MAAM,CACJ,KAAU,EACV,cAAiE;QAEjE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAClB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,EAC5C,cAAc,CACf,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3D,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@introspection-sdk/introspection-pi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Introspection observability extension for the Pi Agent SDK — OTEL GenAI semantic-convention spans for chat completions and tool execution",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@opentelemetry/api": "^1.9.1",
|
|
20
|
-
"@introspection-sdk/types": "0.
|
|
20
|
+
"@introspection-sdk/types": "0.14.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@earendil-works/pi-agent-core": ">=0.75.0",
|