@coalex-ai/sdk 0.4.5 → 0.5.1
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/dist/auto-instrument.d.ts +14 -0
- package/dist/auto-instrument.d.ts.map +1 -0
- package/dist/auto-instrument.js +129 -0
- package/dist/auto-instrument.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +52 -0
- package/dist/context.js.map +1 -0
- package/dist/evaluate.d.ts +14 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +45 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/ext/base.d.ts +3 -0
- package/dist/ext/base.d.ts.map +1 -0
- package/dist/ext/base.js +5 -0
- package/dist/ext/base.js.map +1 -0
- package/dist/ext/embedding.d.ts +16 -0
- package/dist/ext/embedding.d.ts.map +1 -0
- package/dist/ext/embedding.js +62 -0
- package/dist/ext/embedding.js.map +1 -0
- package/dist/ext/guardrail.d.ts +6 -0
- package/dist/ext/guardrail.d.ts.map +1 -0
- package/dist/ext/guardrail.js +32 -0
- package/dist/ext/guardrail.js.map +1 -0
- package/dist/ext/index.d.ts +12 -0
- package/dist/ext/index.d.ts.map +1 -0
- package/dist/ext/index.js +7 -0
- package/dist/ext/index.js.map +1 -0
- package/dist/ext/reranker.d.ts +20 -0
- package/dist/ext/reranker.d.ts.map +1 -0
- package/dist/ext/reranker.js +72 -0
- package/dist/ext/reranker.js.map +1 -0
- package/dist/ext/retrieval.d.ts +22 -0
- package/dist/ext/retrieval.d.ts.map +1 -0
- package/dist/ext/retrieval.js +79 -0
- package/dist/ext/retrieval.js.map +1 -0
- package/dist/ext/tool.d.ts +6 -0
- package/dist/ext/tool.d.ts.map +1 -0
- package/dist/ext/tool.js +28 -0
- package/dist/ext/tool.js.map +1 -0
- package/dist/filtering-exporter.d.ts +18 -0
- package/dist/filtering-exporter.d.ts.map +1 -0
- package/dist/filtering-exporter.js +59 -0
- package/dist/filtering-exporter.js.map +1 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -26
- package/dist/index.js.map +1 -0
- package/dist/resolve.d.ts +21 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +42 -0
- package/dist/resolve.js.map +1 -0
- package/dist/safe-exporter.d.ts +17 -0
- package/dist/safe-exporter.d.ts.map +1 -0
- package/dist/safe-exporter.js +64 -0
- package/dist/safe-exporter.js.map +1 -0
- package/dist/span-processor.d.ts +9 -0
- package/dist/span-processor.d.ts.map +1 -0
- package/dist/span-processor.js +31 -0
- package/dist/span-processor.js.map +1 -0
- package/package.json +44 -32
- package/LICENSE +0 -21
- package/README.md +0 -263
- package/dist/approve.d.ts +0 -95
- package/dist/approve.js +0 -170
- package/dist/metrics.d.ts +0 -101
- package/dist/metrics.js +0 -192
- package/dist/otel/register.d.ts +0 -98
- package/dist/otel/register.js +0 -200
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Document {
|
|
2
|
+
content: string;
|
|
3
|
+
id?: string;
|
|
4
|
+
score?: number;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare function encodeDocuments(docs: Document[]): string;
|
|
8
|
+
export interface RetrievalSpanOptions {
|
|
9
|
+
name?: string;
|
|
10
|
+
queryArg?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function retrievalSpan<A extends unknown[], R>(options: RetrievalSpanOptions, fn: (...args: A) => R | Promise<R>): (...args: A) => Promise<R>;
|
|
13
|
+
export declare class RetrievalSpan {
|
|
14
|
+
private readonly spanName;
|
|
15
|
+
private span;
|
|
16
|
+
constructor(name?: string);
|
|
17
|
+
start(): void;
|
|
18
|
+
setQuery(query: string): void;
|
|
19
|
+
setDocuments(docs: Document[]): void;
|
|
20
|
+
end(): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieval.d.ts","sourceRoot":"","sources":["../../src/ext/retrieval.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAYD,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,CAExD;AAWD,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAClD,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACjC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CA6B5B;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,IAAI,CAAqB;gBAErB,IAAI,SAAc;IAI9B,KAAK,IAAI,IAAI;IAMb,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI;IAKpC,GAAG,IAAI,IAAI;CAIZ"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
2
|
+
import { getTracer } from "./base.js";
|
|
3
|
+
function toOpenInferenceDict(doc) {
|
|
4
|
+
const d = { "document.content": doc.content };
|
|
5
|
+
if (doc.id !== undefined)
|
|
6
|
+
d["document.id"] = doc.id;
|
|
7
|
+
if (doc.score !== undefined)
|
|
8
|
+
d["document.score"] = doc.score;
|
|
9
|
+
if (doc.metadata && Object.keys(doc.metadata).length > 0) {
|
|
10
|
+
d["document.metadata"] = JSON.stringify(doc.metadata);
|
|
11
|
+
}
|
|
12
|
+
return d;
|
|
13
|
+
}
|
|
14
|
+
export function encodeDocuments(docs) {
|
|
15
|
+
return JSON.stringify(docs.map(toOpenInferenceDict));
|
|
16
|
+
}
|
|
17
|
+
function documentSummary(docs) {
|
|
18
|
+
let summary = `Retrieved ${docs.length} document(s)`;
|
|
19
|
+
const ids = docs.filter((d) => d.id).map((d) => d.id);
|
|
20
|
+
if (ids.length > 0) {
|
|
21
|
+
summary += `: [${ids.join(", ")}]`;
|
|
22
|
+
}
|
|
23
|
+
return summary;
|
|
24
|
+
}
|
|
25
|
+
export function retrievalSpan(options, fn) {
|
|
26
|
+
const spanName = options.name ?? "retrieval";
|
|
27
|
+
return async (...args) => {
|
|
28
|
+
const tracer = getTracer();
|
|
29
|
+
return tracer.startActiveSpan(spanName, async (span) => {
|
|
30
|
+
try {
|
|
31
|
+
span.setAttribute("openinference.span.kind", "RETRIEVER");
|
|
32
|
+
const query = args.find((a) => typeof a === "string");
|
|
33
|
+
if (typeof query === "string") {
|
|
34
|
+
span.setAttribute("input.value", query);
|
|
35
|
+
}
|
|
36
|
+
const result = await fn(...args);
|
|
37
|
+
if (Array.isArray(result) && result.length > 0 && result[0]?.content !== undefined) {
|
|
38
|
+
const docs = result;
|
|
39
|
+
span.setAttribute("retrieval.documents", encodeDocuments(docs));
|
|
40
|
+
span.setAttribute("output.value", documentSummary(docs));
|
|
41
|
+
}
|
|
42
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: String(e) });
|
|
47
|
+
span.recordException(e instanceof Error ? e : new Error(String(e)));
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
span.end();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export class RetrievalSpan {
|
|
57
|
+
spanName;
|
|
58
|
+
span = null;
|
|
59
|
+
constructor(name = "retrieval") {
|
|
60
|
+
this.spanName = name;
|
|
61
|
+
}
|
|
62
|
+
start() {
|
|
63
|
+
const tracer = getTracer();
|
|
64
|
+
this.span = tracer.startSpan(this.spanName);
|
|
65
|
+
this.span.setAttribute("openinference.span.kind", "RETRIEVER");
|
|
66
|
+
}
|
|
67
|
+
setQuery(query) {
|
|
68
|
+
this.span?.setAttribute("input.value", query);
|
|
69
|
+
}
|
|
70
|
+
setDocuments(docs) {
|
|
71
|
+
this.span?.setAttribute("retrieval.documents", encodeDocuments(docs));
|
|
72
|
+
this.span?.setAttribute("output.value", documentSummary(docs));
|
|
73
|
+
}
|
|
74
|
+
end() {
|
|
75
|
+
this.span?.setStatus({ code: SpanStatusCode.OK });
|
|
76
|
+
this.span?.end();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=retrieval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieval.js","sourceRoot":"","sources":["../../src/ext/retrieval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAa,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAStC,SAAS,mBAAmB,CAAC,GAAa;IACxC,MAAM,CAAC,GAA4B,EAAE,kBAAkB,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IACvE,IAAI,GAAG,CAAC,EAAE,KAAK,SAAS;QAAE,CAAC,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;IACpD,IAAI,GAAG,CAAC,KAAK,KAAK,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AO,EAAE,eAAe,EACxB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACjC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAuB5B"}
|
package/dist/ext/tool.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getTracer } from "./base.js";
|
|
2
|
+
export function toolSpan(options, fn) {
|
|
3
|
+
return async (...args) => {
|
|
4
|
+
const tracer = getTracer();
|
|
5
|
+
return tracer.startActiveSpan(options.name, async (span) => {
|
|
6
|
+
try {
|
|
7
|
+
span.setAttribute("openinference.span.kind", "TOOL");
|
|
8
|
+
span.setAttribute("tool.name", options.name);
|
|
9
|
+
if (options.description) {
|
|
10
|
+
span.setAttribute("tool.description", options.description);
|
|
11
|
+
}
|
|
12
|
+
if (args.length > 0) {
|
|
13
|
+
try {
|
|
14
|
+
span.setAttribute("tool.parameters", JSON.stringify(args));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// ignore serialization errors
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return await fn(...args);
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
span.end();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/ext/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC,MAAM,UAAU,QAAQ,CACtB,OAAwB,EACxB,EAAkC;IAElC,OAAO,KAAK,EAAE,GAAG,IAAO,EAAc,EAAE;QACtC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACzD,IAAI,CAAC;gBACH,IAAI,CAAC,YAAY,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;gBACrD,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBAC7C,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;oBACxB,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;gBAC7D,CAAC;gBACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACpB,IAAI,CAAC;wBACH,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC7D,CAAC;oBAAC,MAAM,CAAC;wBACP,8BAA8B;oBAChC,CAAC;gBACH,CAAC;gBACD,OAAO,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YAC3B,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
interface ExportResult {
|
|
3
|
+
code: number;
|
|
4
|
+
error?: Error;
|
|
5
|
+
}
|
|
6
|
+
export declare class FilteringSpanExporter implements SpanExporter {
|
|
7
|
+
private readonly wrappedExporter;
|
|
8
|
+
private readonly enabled;
|
|
9
|
+
private filteredCount;
|
|
10
|
+
private exportedCount;
|
|
11
|
+
constructor(wrappedExporter: SpanExporter, enabled?: boolean);
|
|
12
|
+
private shouldExport;
|
|
13
|
+
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
14
|
+
shutdown(): Promise<void>;
|
|
15
|
+
forceFlush(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=filtering-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering-exporter.d.ts","sourceRoot":"","sources":["../src/filtering-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEhF,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAeD,qBAAa,qBAAsB,YAAW,YAAY;IACxD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAe;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAK;gBAEd,eAAe,EAAE,YAAY,EAAE,OAAO,UAAO;IAKzD,OAAO,CAAC,YAAY;IAmBpB,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI;IAiBnF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const ExportResultCode = { SUCCESS: 0, FAILED: 1 };
|
|
2
|
+
const OPENINFERENCE_SPAN_KINDS = new Set([
|
|
3
|
+
"LLM",
|
|
4
|
+
"EMBEDDING",
|
|
5
|
+
"TOOL",
|
|
6
|
+
"CHAIN",
|
|
7
|
+
"AGENT",
|
|
8
|
+
"RETRIEVER",
|
|
9
|
+
"RERANKER",
|
|
10
|
+
]);
|
|
11
|
+
const AI_ATTRIBUTE_PREFIXES = ["openinference.", "gen_ai.", "llm.", "coalex."];
|
|
12
|
+
export class FilteringSpanExporter {
|
|
13
|
+
wrappedExporter;
|
|
14
|
+
enabled;
|
|
15
|
+
filteredCount = 0;
|
|
16
|
+
exportedCount = 0;
|
|
17
|
+
constructor(wrappedExporter, enabled = true) {
|
|
18
|
+
this.wrappedExporter = wrappedExporter;
|
|
19
|
+
this.enabled = enabled;
|
|
20
|
+
}
|
|
21
|
+
shouldExport(span) {
|
|
22
|
+
if (!this.enabled)
|
|
23
|
+
return true;
|
|
24
|
+
const attributes = span.attributes;
|
|
25
|
+
const spanKind = attributes["openinference.span.kind"];
|
|
26
|
+
if (typeof spanKind === "string" && OPENINFERENCE_SPAN_KINDS.has(spanKind)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
for (const attrName of Object.keys(attributes)) {
|
|
30
|
+
for (const prefix of AI_ATTRIBUTE_PREFIXES) {
|
|
31
|
+
if (attrName.startsWith(prefix))
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
export(spans, resultCallback) {
|
|
38
|
+
if (!this.enabled) {
|
|
39
|
+
this.wrappedExporter.export(spans, resultCallback);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const filtered = spans.filter((s) => this.shouldExport(s));
|
|
43
|
+
this.filteredCount += spans.length - filtered.length;
|
|
44
|
+
this.exportedCount += filtered.length;
|
|
45
|
+
if (filtered.length > 0) {
|
|
46
|
+
this.wrappedExporter.export(filtered, resultCallback);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
shutdown() {
|
|
53
|
+
return this.wrappedExporter.shutdown();
|
|
54
|
+
}
|
|
55
|
+
forceFlush() {
|
|
56
|
+
return this.wrappedExporter.forceFlush?.() ?? Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=filtering-exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering-exporter.js","sourceRoot":"","sources":["../src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AA8C;QAC1E,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YACnD,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3D,IAAI,CAAC,aAAa,IAAI,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QACrD,IAAI,CAAC,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC;QAEtC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;IACzC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAClE,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export
|
|
1
|
+
import type { CoalexConfig } from "./config.js";
|
|
2
|
+
export type { CoalexConfig } from "./config.js";
|
|
3
|
+
export { coalexContext, coalexContextSync } from "./context.js";
|
|
4
|
+
export type { CoalexContextOptions } from "./context.js";
|
|
5
|
+
export { evaluate, KNOWN_METRICS } from "./evaluate.js";
|
|
6
|
+
export type { EvaluateOptions, EvaluationDecision } from "./evaluate.js";
|
|
7
|
+
export { resolve, VALID_DECISIONS } from "./resolve.js";
|
|
8
|
+
export type { ResolveOptions, ResolutionResult, MetricResult } from "./resolve.js";
|
|
9
|
+
export { autoInstrument, instrumentOpenAI, instrumentLangChain, instrumentAnthropic } from "./auto-instrument.js";
|
|
10
|
+
export type { AutoInstrumentOptions, InstrumentationStatus } from "./auto-instrument.js";
|
|
11
|
+
export declare function getConfig(): CoalexConfig;
|
|
12
|
+
export declare function getApiKey(): string;
|
|
13
|
+
export interface RegisterOptions {
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
serviceName?: string;
|
|
17
|
+
filterNonAiSpans?: boolean;
|
|
18
|
+
suppressExportErrors?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function register(options?: RegisterOptions): void;
|
|
21
|
+
/** Reset SDK state — for testing only. */
|
|
22
|
+
export declare function _resetForTesting(): void;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAClH,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAKzF,wBAAgB,SAAS,IAAI,YAAY,CAKxC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAKlC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CA0BxD;AAED,0CAA0C;AAC1C,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import { Resource } from "@opentelemetry/resources";
|
|
2
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
3
|
+
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
4
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
|
+
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
6
|
+
import { SafeOTLPSpanExporter } from "./safe-exporter.js";
|
|
7
|
+
import { FilteringSpanExporter } from "./filtering-exporter.js";
|
|
8
|
+
import { CoalexAttributePropagator } from "./span-processor.js";
|
|
9
|
+
export { coalexContext, coalexContextSync } from "./context.js";
|
|
10
|
+
export { evaluate, KNOWN_METRICS } from "./evaluate.js";
|
|
11
|
+
export { resolve, VALID_DECISIONS } from "./resolve.js";
|
|
12
|
+
export { autoInstrument, instrumentOpenAI, instrumentLangChain, instrumentAnthropic } from "./auto-instrument.js";
|
|
13
|
+
let _config = null;
|
|
14
|
+
let _apiKey = null;
|
|
15
|
+
export function getConfig() {
|
|
16
|
+
if (!_config) {
|
|
17
|
+
throw new Error("register() must be called before using the Coalex SDK");
|
|
18
|
+
}
|
|
19
|
+
return _config;
|
|
20
|
+
}
|
|
21
|
+
export function getApiKey() {
|
|
22
|
+
if (!_apiKey) {
|
|
23
|
+
throw new Error("register() must be called before using the Coalex SDK");
|
|
24
|
+
}
|
|
25
|
+
return _apiKey;
|
|
26
|
+
}
|
|
27
|
+
export function register(options) {
|
|
28
|
+
const endpoint = options?.endpoint ?? "https://collect.coalex.ai";
|
|
29
|
+
const apiKey = options?.apiKey ?? "dev";
|
|
30
|
+
const serviceName = options?.serviceName ?? "coalex-sdk-typescript";
|
|
31
|
+
const filterNonAiSpans = options?.filterNonAiSpans ?? false;
|
|
32
|
+
const suppressExportErrors = options?.suppressExportErrors ?? true;
|
|
33
|
+
_config = { endpoint, serviceName };
|
|
34
|
+
_apiKey = apiKey;
|
|
35
|
+
const resource = new Resource({ [ATTR_SERVICE_NAME]: serviceName });
|
|
36
|
+
const baseExporter = new OTLPTraceExporter({
|
|
37
|
+
url: `${endpoint}/v1/traces`,
|
|
38
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
39
|
+
});
|
|
40
|
+
const safeExporter = new SafeOTLPSpanExporter(baseExporter, suppressExportErrors);
|
|
41
|
+
const finalExporter = filterNonAiSpans
|
|
42
|
+
? new FilteringSpanExporter(safeExporter)
|
|
43
|
+
: safeExporter;
|
|
44
|
+
const provider = new NodeTracerProvider({ resource });
|
|
45
|
+
provider.addSpanProcessor(new CoalexAttributePropagator());
|
|
46
|
+
provider.addSpanProcessor(new BatchSpanProcessor(finalExporter));
|
|
47
|
+
provider.register();
|
|
48
|
+
}
|
|
49
|
+
/** Reset SDK state — for testing only. */
|
|
50
|
+
export function _resetForTesting() {
|
|
51
|
+
_config = null;
|
|
52
|
+
_apiKey = null;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAGxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGlH,IAAI,OAAO,GAAwB,IAAI,CAAC;AACxC,IAAI,OAAO,GAAkB,IAAI,CAAC;AAElC,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,OAAO,E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AAC,CAAC;IACtD,QAAQ,CAAC,gBAAgB,CAAC,IAAI,yBAAyB,EAAE,CAAC,CAAC;IAC3D,QAAQ,CAAC,gBAAgB,CAAC,IAAI,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC;IACjE,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACtB,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,gBAAgB;IAC9B,OAAO,GAAG,IAAI,CAAC;IACf,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const VALID_DECISIONS: Set<"approved" | "rejected" | "corrected">;
|
|
2
|
+
export interface MetricResult {
|
|
3
|
+
readonly field: string;
|
|
4
|
+
readonly metrics: Record<string, number>;
|
|
5
|
+
}
|
|
6
|
+
export interface ResolutionResult {
|
|
7
|
+
readonly escalationId: string;
|
|
8
|
+
readonly status: string;
|
|
9
|
+
readonly metrics: MetricResult[];
|
|
10
|
+
readonly resolvedAt: string;
|
|
11
|
+
readonly resolvedBy?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ResolveOptions {
|
|
14
|
+
escalationId: string;
|
|
15
|
+
decision: "approved" | "rejected" | "corrected";
|
|
16
|
+
corrections?: Record<string, unknown>;
|
|
17
|
+
reviewer?: string;
|
|
18
|
+
reason?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function resolve(options: ResolveOptions): Promise<ResolutionResult>;
|
|
21
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,4CAA0D,CAAC;AAEvF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAwDhF"}
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getConfig, getApiKey } from "./index.js";
|
|
2
|
+
export const VALID_DECISIONS = new Set(["approved", "rejected", "corrected"]);
|
|
3
|
+
export async function resolve(options) {
|
|
4
|
+
const config = getConfig();
|
|
5
|
+
const apiKey = getApiKey();
|
|
6
|
+
if (!VALID_DECISIONS.has(options.decision)) {
|
|
7
|
+
throw new Error(`decision must be one of ${[...VALID_DECISIONS].join(", ")}, got '${options.decision}'`);
|
|
8
|
+
}
|
|
9
|
+
if (options.decision === "corrected" && !options.corrections) {
|
|
10
|
+
throw new Error("corrections required when decision is 'corrected'");
|
|
11
|
+
}
|
|
12
|
+
const payload = { decision: options.decision };
|
|
13
|
+
if (options.corrections !== undefined)
|
|
14
|
+
payload.corrections = options.corrections;
|
|
15
|
+
if (options.reviewer !== undefined)
|
|
16
|
+
payload.reviewer = options.reviewer;
|
|
17
|
+
if (options.reason !== undefined)
|
|
18
|
+
payload.reason = options.reason;
|
|
19
|
+
const resp = await fetch(`${config.endpoint}/api/v1/escalations/${options.escalationId}/resolve`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
Authorization: `Bearer ${apiKey}`,
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify(payload),
|
|
26
|
+
});
|
|
27
|
+
if (!resp.ok) {
|
|
28
|
+
throw new Error(`resolve() failed: ${resp.status} ${resp.statusText}`);
|
|
29
|
+
}
|
|
30
|
+
const data = await resp.json();
|
|
31
|
+
return {
|
|
32
|
+
escalationId: data.escalation_id,
|
|
33
|
+
status: data.status,
|
|
34
|
+
metrics: (data.metrics ?? []).map((m) => ({
|
|
35
|
+
field: m.field,
|
|
36
|
+
metrics: m.metrics,
|
|
37
|
+
})),
|
|
38
|
+
resolvedAt: data.resolved_at,
|
|
39
|
+
resolvedBy: data.resolved_by,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,CAAU,CAAC,CAAC;AAuBvF,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAuB;IACnD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,2BAA2B,CAAC,GAAG,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,OAAO,CAAC,QAAQ,GAA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C,CAAC;YACxC,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB,CAAC,CAAC;QACH,UAAU,EAAE,IAAI,CAAC,WAAW;QAC5B,UAAU,EAAE,IAAI,CAAC,WAAW;KAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
interface ExportResult {
|
|
3
|
+
code: number;
|
|
4
|
+
error?: Error;
|
|
5
|
+
}
|
|
6
|
+
export declare class SafeOTLPSpanExporter implements SpanExporter {
|
|
7
|
+
private readonly wrappedExporter;
|
|
8
|
+
private readonly suppressErrors;
|
|
9
|
+
private errorCount;
|
|
10
|
+
private readonly maxLoggedErrors;
|
|
11
|
+
constructor(wrappedExporter: SpanExporter, suppressErrors?: boolean);
|
|
12
|
+
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
13
|
+
shutdown(): Promise<void>;
|
|
14
|
+
forceFlush(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=safe-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-exporter.d.ts","sourceRoot":"","sources":["../src/safe-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEhF,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAGD,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAe;IAC/C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IACzC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAK;gBAEzB,eAAe,EAAE,YAAY,EAAE,cAAc,UAAO;IAKhE,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI;IAuCnF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IASzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const ExportResultCode = { SUCCESS: 0, FAILED: 1 };
|
|
2
|
+
export class SafeOTLPSpanExporter {
|
|
3
|
+
wrappedExporter;
|
|
4
|
+
suppressErrors;
|
|
5
|
+
errorCount = 0;
|
|
6
|
+
maxLoggedErrors = 3;
|
|
7
|
+
constructor(wrappedExporter, suppressErrors = true) {
|
|
8
|
+
this.wrappedExporter = wrappedExporter;
|
|
9
|
+
this.suppressErrors = suppressErrors;
|
|
10
|
+
}
|
|
11
|
+
export(spans, resultCallback) {
|
|
12
|
+
try {
|
|
13
|
+
this.wrappedExporter.export(spans, (result) => {
|
|
14
|
+
if (result.code === ExportResultCode.FAILED && this.suppressErrors) {
|
|
15
|
+
this.errorCount++;
|
|
16
|
+
if (this.errorCount <= this.maxLoggedErrors) {
|
|
17
|
+
console.warn(`[coalex] Failed to export ${spans.length} spans (error #${this.errorCount}): ${result.error?.message ?? "unknown error"}`);
|
|
18
|
+
if (this.errorCount === this.maxLoggedErrors) {
|
|
19
|
+
console.warn(`[coalex] Suppressing further span export errors (total so far: ${this.errorCount}).`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
resultCallback(result);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (!this.suppressErrors)
|
|
31
|
+
throw e;
|
|
32
|
+
this.errorCount++;
|
|
33
|
+
if (this.errorCount <= this.maxLoggedErrors) {
|
|
34
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
35
|
+
console.warn(`[coalex] Failed to export ${spans.length} spans (error #${this.errorCount}): ${msg}`);
|
|
36
|
+
if (this.errorCount === this.maxLoggedErrors) {
|
|
37
|
+
console.warn(`[coalex] Suppressing further span export errors (total so far: ${this.errorCount}).`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
shutdown() {
|
|
44
|
+
try {
|
|
45
|
+
return this.wrappedExporter.shutdown();
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
if (!this.suppressErrors)
|
|
49
|
+
throw e;
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
forceFlush() {
|
|
54
|
+
try {
|
|
55
|
+
return this.wrappedExporter.forceFlush?.() ?? Promise.resolve();
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
if (!this.suppressErrors)
|
|
59
|
+
throw e;
|
|
60
|
+
return Promise.resolve();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=safe-exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-exporter.js","sourceRoot":"","sources":["../src/safe-exporter.ts"],"names":[],"mappings":"AAMA,MAAM,gBAAgB,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAW,CAAC;AAE5D,MAAM,OAAO,oBAAoB;IACd,eAAe,CAAe;IAC9B,cAAc,CAAU;IACjC,UAAU,GAAG,CAAC,CAAC;IACN,eAAe,GAAG,CAAC,CAAC;IAErC,YAAY,eAA6B,EAAE,cAAc,GAAG,IAAI;QAC9D,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED,MAAM,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AAM,GAAG,EAAE,CACtF,CAAC;gBACF,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,eAAe,EAAE,CAAC;oBAC7C,OAAO,CAAC,IAAI,CACV,kEAAkE,IAAI,CAAC,UAAU,IAAI,CACtF,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,QAAQ;QACN,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;QACzC,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,cAAc;gBAAE,MAAM,CAAC,CAAC;YAClC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,UAAU;QACR,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAClE,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,cAAc;gBAAE,MAAM,CAAC,CAAC;YAClC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from "@opentelemetry/api";
|
|
2
|
+
import type { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
export declare class CoalexAttributePropagator implements SpanProcessor {
|
|
4
|
+
onStart(span: Span, parentContext: Context): void;
|
|
5
|
+
onEnd(_span: ReadableSpan): void;
|
|
6
|
+
shutdown(): Promise<void>;
|
|
7
|
+
forceFlush(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=span-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-processor.d.ts","sourceRoot":"","sources":["../src/span-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAQvF,qBAAa,yBAA0B,YAAW,aAAa;IAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI;IAgBjD,KAAK,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAChC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAGzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { trace } from "@opentelemetry/api";
|
|
2
|
+
const ATTRIBUTES_TO_PROPAGATE = [
|
|
3
|
+
"coalex.agent_id",
|
|
4
|
+
"coalex.request_id",
|
|
5
|
+
"coalex.agent_version",
|
|
6
|
+
];
|
|
7
|
+
export class CoalexAttributePropagator {
|
|
8
|
+
onStart(span, parentContext) {
|
|
9
|
+
const parentSpan = trace.getSpan(parentContext);
|
|
10
|
+
if (!parentSpan)
|
|
11
|
+
return;
|
|
12
|
+
const parentReadable = parentSpan;
|
|
13
|
+
const parentAttrs = parentReadable.attributes;
|
|
14
|
+
if (!parentAttrs)
|
|
15
|
+
return;
|
|
16
|
+
for (const attrName of ATTRIBUTES_TO_PROPAGATE) {
|
|
17
|
+
const parentValue = parentAttrs[attrName];
|
|
18
|
+
if (parentValue !== undefined) {
|
|
19
|
+
span.setAttribute(attrName, parentValue);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
onEnd(_span) { }
|
|
24
|
+
shutdown() {
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
forceFlush() {
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=span-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-processor.js","sourceRoot":"","sources":["../src/span-processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,MAAM,uBAAuB,GAAG;IAC9B,iBAAiB;IACjB,mBAAmB;IACnB,sBAAsB;CACd,CAAC;AAEX,MAAM,OAAO,yBAAyB;IACpC,OAAO,CAAC,IAAU,EAAE,aAAsB;QACxC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAChD,IAAI,CAAC,UAAU;YAAE,OAAO;QAExB,MAAM,cAAc,GAAG,UAAqC,CAAC;QAC7D,MAAM,WAAW,GAAG,cAAc,CAAC,UAAU,CAAC;QAC9C,IAAI,CAAC,WAAW;YAAE,OAAO;QAEzB,KAAK,MAAM,QAAQ,IAAI,uBAAuB,EAAE,CAAC;YAC/C,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;YAC1C,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9B,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAmB,IAAS,CAAC;IACnC,QAAQ;QACN,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,UAAU;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF"}
|