@traceroot-ai/traceroot 0.1.0-alpha.2 → 0.1.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/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +35 -4
- package/dist/context.js.map +1 -1
- package/dist/git_context.d.ts +21 -0
- package/dist/git_context.d.ts.map +1 -0
- package/dist/git_context.js +95 -0
- package/dist/git_context.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/observe.d.ts.map +1 -1
- package/dist/observe.js +31 -0
- package/dist/observe.js.map +1 -1
- package/dist/processor.d.ts +10 -2
- package/dist/processor.d.ts.map +1 -1
- package/dist/processor.js +19 -2
- package/dist/processor.js.map +1 -1
- package/dist/traceroot.d.ts.map +1 -1
- package/dist/traceroot.js +23 -1
- package/dist/traceroot.js.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/usingAttributes.d.ts +29 -0
- package/dist/usingAttributes.d.ts.map +1 -0
- package/dist/usingAttributes.js +40 -0
- package/dist/usingAttributes.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,4BAA4B,CAAC;AACvD,eAAO,MAAM,SAAS,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SPAN_TAGS = exports.SPAN_METADATA = void 0;
|
|
4
|
+
// src/constants.ts — TraceRoot-specific span attribute keys
|
|
5
|
+
exports.SPAN_METADATA = 'traceroot.span.metadata';
|
|
6
|
+
exports.SPAN_TAGS = 'traceroot.span.tags';
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC/C,QAAA,aAAa,GAAG,yBAAyB,CAAC;AAC1C,QAAA,SAAS,GAAG,qBAAqB,CAAC"}
|
package/dist/context.d.ts
CHANGED
|
@@ -16,4 +16,12 @@ export declare function updateCurrentTrace(attrs: {
|
|
|
16
16
|
sessionId?: string;
|
|
17
17
|
tags?: string[];
|
|
18
18
|
}): void;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the trace ID of the currently active span, or undefined if no span is active.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getCurrentTraceId(): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the span ID of the currently active span, or undefined if no span is active.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCurrentSpanId(): string | undefined;
|
|
19
27
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,IAAI,CAaP;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB,GAAG,IAAI,CAaP;AAOD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAEtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAErD"}
|
package/dist/context.js
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateCurrentSpan = updateCurrentSpan;
|
|
4
4
|
exports.updateCurrentTrace = updateCurrentTrace;
|
|
5
|
+
exports.getCurrentTraceId = getCurrentTraceId;
|
|
6
|
+
exports.getCurrentSpanId = getCurrentSpanId;
|
|
5
7
|
// src/context.ts
|
|
6
8
|
const api_1 = require("@opentelemetry/api");
|
|
7
9
|
const openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
8
11
|
/**
|
|
9
12
|
* Sets input, output, or metadata attributes on the currently active span.
|
|
10
13
|
* No-op when called outside an active span.
|
|
@@ -14,13 +17,22 @@ function updateCurrentSpan(attrs) {
|
|
|
14
17
|
if (!span)
|
|
15
18
|
return;
|
|
16
19
|
if (attrs.input !== undefined) {
|
|
17
|
-
|
|
20
|
+
try {
|
|
21
|
+
span.setAttribute(openinference_semantic_conventions_1.INPUT_VALUE, JSON.stringify(attrs.input));
|
|
22
|
+
}
|
|
23
|
+
catch { /* non-serializable */ }
|
|
18
24
|
}
|
|
19
25
|
if (attrs.output !== undefined) {
|
|
20
|
-
|
|
26
|
+
try {
|
|
27
|
+
span.setAttribute(openinference_semantic_conventions_1.OUTPUT_VALUE, JSON.stringify(attrs.output));
|
|
28
|
+
}
|
|
29
|
+
catch { /* non-serializable */ }
|
|
21
30
|
}
|
|
22
31
|
if (attrs.metadata !== undefined) {
|
|
23
|
-
|
|
32
|
+
try {
|
|
33
|
+
span.setAttribute(constants_1.SPAN_METADATA, JSON.stringify(attrs.metadata));
|
|
34
|
+
}
|
|
35
|
+
catch { /* non-serializable */ }
|
|
24
36
|
}
|
|
25
37
|
}
|
|
26
38
|
/**
|
|
@@ -38,7 +50,26 @@ function updateCurrentTrace(attrs) {
|
|
|
38
50
|
span.setAttribute(openinference_semantic_conventions_1.SESSION_ID, attrs.sessionId);
|
|
39
51
|
}
|
|
40
52
|
if (attrs.tags !== undefined) {
|
|
41
|
-
|
|
53
|
+
try {
|
|
54
|
+
span.setAttribute(constants_1.SPAN_TAGS, JSON.stringify(attrs.tags));
|
|
55
|
+
}
|
|
56
|
+
catch { /* non-serializable */ }
|
|
42
57
|
}
|
|
43
58
|
}
|
|
59
|
+
function activeSpanContext() {
|
|
60
|
+
const span = api_1.trace.getActiveSpan();
|
|
61
|
+
return span ? span.spanContext() : undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the trace ID of the currently active span, or undefined if no span is active.
|
|
65
|
+
*/
|
|
66
|
+
function getCurrentTraceId() {
|
|
67
|
+
return activeSpanContext()?.traceId;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the span ID of the currently active span, or undefined if no span is active.
|
|
71
|
+
*/
|
|
72
|
+
function getCurrentSpanId() {
|
|
73
|
+
return activeSpanContext()?.spanId;
|
|
74
|
+
}
|
|
44
75
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;AAcA,8CAiBC;AAMD,gDAiBC;AAUD,8CAEC;AAKD,4CAEC;AAzED,iBAAiB;AACjB,4CAA2C;AAC3C,oGAKqD;AACrD,2CAAuD;AAEvD;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,KAIjC;IACC,MAAM,IAAI,GAAG,WAAK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AI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC;YAAC,IAAI,CAAC,YAAY,CAAC,qBAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC;IACpG,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,IAAI,GAAG,WAAK,CAAC,aAAa,EAAE,CAAC;IACnC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,iBAAiB,EAAE,EAAE,OAAO,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,iBAAiB,EAAE,EAAE,MAAM,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function getGitRoot(): string | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Auto-detects git repo (as "owner/repo") and current commit ref.
|
|
4
|
+
* Returns an empty object if git is unavailable or any command fails.
|
|
5
|
+
*/
|
|
6
|
+
export declare function autoDetectGitContext(): {
|
|
7
|
+
gitRepo?: string;
|
|
8
|
+
gitRef?: string;
|
|
9
|
+
};
|
|
10
|
+
/** @internal — reset cached git root between tests */
|
|
11
|
+
export declare function _resetGitContextCache(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Captures the call-site source location by inspecting the JS call stack.
|
|
14
|
+
* Skips SDK-internal frames and node_modules. Returns path relative to git root.
|
|
15
|
+
*/
|
|
16
|
+
export declare function captureSourceLocation(): {
|
|
17
|
+
file?: string;
|
|
18
|
+
line?: number;
|
|
19
|
+
functionName?: string;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=git_context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git_context.d.ts","sourceRoot":"","sources":["../src/git_context.ts"],"names":[],"mappings":"AAKA,wBAAgB,UAAU,IAAI,MAAM,GAAG,SAAS,CAW/C;AAWD;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CA8B5E;AAED,sDAAsD;AACtD,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAsB/F"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGitRoot = getGitRoot;
|
|
4
|
+
exports.autoDetectGitContext = autoDetectGitContext;
|
|
5
|
+
exports._resetGitContextCache = _resetGitContextCache;
|
|
6
|
+
exports.captureSourceLocation = captureSourceLocation;
|
|
7
|
+
// src/git_context.ts
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
let _gitRootCache = null; // null = not yet detected, '' = failed
|
|
10
|
+
function getGitRoot() {
|
|
11
|
+
if (_gitRootCache !== null)
|
|
12
|
+
return _gitRootCache || undefined;
|
|
13
|
+
try {
|
|
14
|
+
_gitRootCache = (0, node_child_process_1.execSync)('git rev-parse --show-toplevel', {
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
17
|
+
}).trim();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
_gitRootCache = '';
|
|
21
|
+
}
|
|
22
|
+
return _gitRootCache || undefined;
|
|
23
|
+
}
|
|
24
|
+
function relativePath(filepath) {
|
|
25
|
+
const gitRoot = getGitRoot();
|
|
26
|
+
if (gitRoot && filepath.startsWith(gitRoot)) {
|
|
27
|
+
return filepath.slice(gitRoot.length).replace(/^[/\\]/, '');
|
|
28
|
+
}
|
|
29
|
+
// If we can't make the path relative, don't stamp it — avoid leaking absolute paths.
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Auto-detects git repo (as "owner/repo") and current commit ref.
|
|
34
|
+
* Returns an empty object if git is unavailable or any command fails.
|
|
35
|
+
*/
|
|
36
|
+
function autoDetectGitContext() {
|
|
37
|
+
let gitRepo;
|
|
38
|
+
let gitRef;
|
|
39
|
+
try {
|
|
40
|
+
const remote = (0, node_child_process_1.execSync)('git remote get-url origin', {
|
|
41
|
+
encoding: 'utf8',
|
|
42
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
43
|
+
}).trim();
|
|
44
|
+
// Normalize to "owner/repo" — handles https, git@, ssh:// formats
|
|
45
|
+
const match = remote.match(/(?:https?:\/\/|ssh:\/\/git@|git@)github\.com[:/](.+?)(?:\.git)?$/);
|
|
46
|
+
if (match) {
|
|
47
|
+
gitRepo = match[1].replace(/\/$/, '');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch { /* git unavailable */ }
|
|
51
|
+
try {
|
|
52
|
+
gitRef = (0, node_child_process_1.execSync)('git rev-parse HEAD', {
|
|
53
|
+
encoding: 'utf8',
|
|
54
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
55
|
+
}).trim() || undefined;
|
|
56
|
+
}
|
|
57
|
+
catch { /* git unavailable */ }
|
|
58
|
+
// Warm the git root cache now so the first observe() call doesn't shell out.
|
|
59
|
+
getGitRoot();
|
|
60
|
+
return { gitRepo, gitRef };
|
|
61
|
+
}
|
|
62
|
+
/** @internal — reset cached git root between tests */
|
|
63
|
+
function _resetGitContextCache() {
|
|
64
|
+
_gitRootCache = null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Captures the call-site source location by inspecting the JS call stack.
|
|
68
|
+
* Skips SDK-internal frames and node_modules. Returns path relative to git root.
|
|
69
|
+
*/
|
|
70
|
+
function captureSourceLocation() {
|
|
71
|
+
const stack = new Error().stack;
|
|
72
|
+
if (!stack)
|
|
73
|
+
return {};
|
|
74
|
+
const lines = stack.split('\n').slice(1); // remove "Error" header line
|
|
75
|
+
for (const line of lines) {
|
|
76
|
+
if (line.includes('/packages/traceroot/src/'))
|
|
77
|
+
continue;
|
|
78
|
+
if (line.includes('/node_modules/'))
|
|
79
|
+
continue;
|
|
80
|
+
if (line.includes('(node:'))
|
|
81
|
+
continue; // skip Node.js built-in frames (e.g. node:internal/async_local_storage)
|
|
82
|
+
// Parse " at functionName (file:line:col)" or " at file:line:col"
|
|
83
|
+
const match = line.match(/^\s+at (?:(.+?) \()?(.+?):(\d+):\d+\)?$/);
|
|
84
|
+
if (!match)
|
|
85
|
+
continue;
|
|
86
|
+
const [, fnName, file, lineStr] = match;
|
|
87
|
+
return {
|
|
88
|
+
file: relativePath(file),
|
|
89
|
+
line: parseInt(lineStr, 10),
|
|
90
|
+
functionName: fnName || undefined,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=git_context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git_context.js","sourceRoot":"","sources":["../src/git_context.ts"],"names":[],"mappings":";;AAKA,gCAWC;AAeD,oDA8BC;AAGD,sDAEC;AAMD,sDAsBC;AA9FD,qBAAqB;AACrB,2DAA8C;AAE9C,IAAI,aAAa,GAAkB,IAAI,CAAC,CAAC,uCAAuC;AAEhF,SAAgB,UAAU;IACxB,IAAI,aAAa,KAAK,IAAI;QAAE,OAAO,aAAa,IAAI,SAAS,CAAC;IAC9D,IAAI,CAAC;QACH,aAAa,GAAG,IAAA,6BAAQ,EAAC,+BAA+B,EAAE;YACxD,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,CAAC,MAAM,EA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
|
export { TraceRoot } from './traceroot';
|
|
2
2
|
export { observe } from './observe';
|
|
3
|
-
export { updateCurrentSpan, updateCurrentTrace } from './context';
|
|
3
|
+
export { updateCurrentSpan, updateCurrentTrace, getCurrentTraceId, getCurrentSpanId } from './context';
|
|
4
|
+
export { usingAttributes } from './usingAttributes';
|
|
4
5
|
export type { SpanType, ObserveOptions, InitializeOptions } from './types';
|
|
6
|
+
export type { UsingAttributesOptions } from './usingAttributes';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACvG,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC3E,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateCurrentTrace = exports.updateCurrentSpan = exports.observe = exports.TraceRoot = void 0;
|
|
3
|
+
exports.usingAttributes = exports.getCurrentSpanId = exports.getCurrentTraceId = exports.updateCurrentTrace = exports.updateCurrentSpan = exports.observe = exports.TraceRoot = void 0;
|
|
4
4
|
// src/index.ts
|
|
5
5
|
var traceroot_1 = require("./traceroot");
|
|
6
6
|
Object.defineProperty(exports, "TraceRoot", { enumerable: true, get: function () { return traceroot_1.TraceRoot; } });
|
|
@@ -9,4 +9,8 @@ Object.defineProperty(exports, "observe", { enumerable: true, get: function () {
|
|
|
9
9
|
var context_1 = require("./context");
|
|
10
10
|
Object.defineProperty(exports, "updateCurrentSpan", { enumerable: true, get: function () { return context_1.updateCurrentSpan; } });
|
|
11
11
|
Object.defineProperty(exports, "updateCurrentTrace", { enumerable: true, get: function () { return context_1.updateCurrentTrace; } });
|
|
12
|
+
Object.defineProperty(exports, "getCurrentTraceId", { enumerable: true, get: function () { return context_1.getCurrentTraceId; } });
|
|
13
|
+
Object.defineProperty(exports, "getCurrentSpanId", { enumerable: true, get: function () { return context_1.getCurrentSpanId; } });
|
|
14
|
+
var usingAttributes_1 = require("./usingAttributes");
|
|
15
|
+
Object.defineProperty(exports, "usingAttributes", { enumerable: true, get: function () { return usingAttributes_1.usingAttributes; } });
|
|
12
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,qCAAuG;AAA9F,4GAAA,iBAAiB,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AACnF,qDAAoD;AAA3C,kHAAA,eAAe,OAAA"}
|
package/dist/observe.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../src/observe.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAY,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../src/observe.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAY,MAAM,SAAS,CAAC;AAgBnD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAyEZ;AAED,mDAAmD;AACnD,wBAAgB,kBAAkB,IAAI,IAAI,CAGzC"}
|
package/dist/observe.js
CHANGED
|
@@ -4,7 +4,10 @@ exports.observe = observe;
|
|
|
4
4
|
exports._resetObserveState = _resetObserveState;
|
|
5
5
|
// src/observe.ts
|
|
6
6
|
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const openinference_core_1 = require("@arizeai/openinference-core");
|
|
7
8
|
const openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const git_context_1 = require("./git_context");
|
|
8
11
|
const OPENINFERENCE_SPAN_KIND = openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND;
|
|
9
12
|
const SPAN_KIND_MAP = {
|
|
10
13
|
agent: 'AGENT',
|
|
@@ -42,6 +45,11 @@ async function observe(options, fn) {
|
|
|
42
45
|
}
|
|
43
46
|
try {
|
|
44
47
|
span.setAttribute(OPENINFERENCE_SPAN_KIND, SPAN_KIND_MAP[options.type ?? 'span']);
|
|
48
|
+
// Propagate any ambient attributes set by usingAttributes() in the call stack.
|
|
49
|
+
const ctxAttrs = (0, openinference_core_1.getAttributesFromContext)(api_1.context.active());
|
|
50
|
+
if (ctxAttrs && Object.keys(ctxAttrs).length > 0) {
|
|
51
|
+
span.setAttributes(ctxAttrs);
|
|
52
|
+
}
|
|
45
53
|
if (options.input !== undefined) {
|
|
46
54
|
try {
|
|
47
55
|
span.setAttribute(openinference_semantic_conventions_1.INPUT_VALUE, JSON.stringify(options.input));
|
|
@@ -50,6 +58,29 @@ async function observe(options, fn) {
|
|
|
50
58
|
// Non-serializable input — skip attribute
|
|
51
59
|
}
|
|
52
60
|
}
|
|
61
|
+
if (options.metadata !== undefined) {
|
|
62
|
+
try {
|
|
63
|
+
span.setAttribute(constants_1.SPAN_METADATA, JSON.stringify(options.metadata));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Non-serializable metadata — skip
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (options.tags !== undefined) {
|
|
70
|
+
try {
|
|
71
|
+
span.setAttribute(constants_1.SPAN_TAGS, JSON.stringify(options.tags));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Non-serializable tags — skip
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const loc = (0, git_context_1.captureSourceLocation)();
|
|
78
|
+
if (loc.file !== undefined)
|
|
79
|
+
span.setAttribute('traceroot.git.source_file', loc.file);
|
|
80
|
+
if (loc.line !== undefined)
|
|
81
|
+
span.setAttribute('traceroot.git.source_line', loc.line);
|
|
82
|
+
if (loc.functionName !== undefined)
|
|
83
|
+
span.setAttribute('traceroot.git.source_function', loc.functionName);
|
|
53
84
|
const result = await fn();
|
|
54
85
|
try {
|
|
55
86
|
span.setAttribute(openinference_semantic_conventions_1.OUTPUT_VALUE, JSON.stringify(result));
|
package/dist/observe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe.js","sourceRoot":"","sources":["../src/observe.ts"],"names":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I,CAAC,YAAY,CAAC,2BAA2B,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;YACrF,IAAI,GAAG,CAAC,YAAY,KAAK,SAAS;gBAAE,IAAI,CAAC,YAAY,CAAC,+BAA+B,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;YAEzG,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;YAE1B,IAAI,CAAC;gBACH,IAAI,CAAC,YAAY,CAAC,iDAAY,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YAC1D,CAAC;YAAC,MAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,eAAe,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC1E,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,oBAAc,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/C,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,mDAAmD;AACnD,SAAgB,kBAAkB;IAChC,OAAO,GAAG,SAAS,CAAC;IACpB,gBAAgB,GAAG,KAAK,CAAC;AAC3B,CAAC"}
|
package/dist/processor.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Context, Span } from '@opentelemetry/api';
|
|
2
2
|
import { BatchSpanProcessor, ReadableSpan, SimpleSpanProcessor, SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
3
3
|
export declare const SDK_NAME = "traceroot-ts";
|
|
4
|
-
export declare const SDK_VERSION
|
|
4
|
+
export declare const SDK_VERSION: string;
|
|
5
|
+
export interface TraceRootSpanProcessorOptions {
|
|
6
|
+
environment?: string;
|
|
7
|
+
gitRepo?: string;
|
|
8
|
+
gitRef?: string;
|
|
9
|
+
}
|
|
5
10
|
/**
|
|
6
11
|
* Wraps an inner SpanProcessor (Batch or Simple) and injects TraceRoot SDK
|
|
7
12
|
* metadata attributes on every span start. This is the only processor TraceRoot
|
|
@@ -9,7 +14,10 @@ export declare const SDK_VERSION = "0.1.0";
|
|
|
9
14
|
*/
|
|
10
15
|
export declare class TraceRootSpanProcessor implements SpanProcessor {
|
|
11
16
|
private readonly inner;
|
|
12
|
-
|
|
17
|
+
private readonly _environment;
|
|
18
|
+
private readonly _gitRepo;
|
|
19
|
+
private readonly _gitRef;
|
|
20
|
+
constructor(inner: BatchSpanProcessor | SimpleSpanProcessor, opts?: TraceRootSpanProcessorOptions);
|
|
13
21
|
onStart(span: Span, parentContext: Context): void;
|
|
14
22
|
onEnd(span: ReadableSpan): void;
|
|
15
23
|
forceFlush(): Promise<void>;
|
package/dist/processor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,+BAA+B,CAAC;AAKvC,eAAO,MAAM,QAAQ,iBAAiB,CAAC;AACvC,eAAO,MAAM,WAAW,QAAU,CAAC;AAEnC,MAAM,WAAW,6BAA6B;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2C;IACjE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;gBAG3C,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,EAC/C,IAAI,GAAE,6BAAkC;IAQ1C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI;IAoBjD,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAI/B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAG1B"}
|
package/dist/processor.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TraceRootSpanProcessor = exports.SDK_VERSION = exports.SDK_NAME = void 0;
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
5
|
+
const { version } = require('../package.json');
|
|
4
6
|
exports.SDK_NAME = 'traceroot-ts';
|
|
5
|
-
exports.SDK_VERSION =
|
|
7
|
+
exports.SDK_VERSION = version;
|
|
6
8
|
/**
|
|
7
9
|
* Wraps an inner SpanProcessor (Batch or Simple) and injects TraceRoot SDK
|
|
8
10
|
* metadata attributes on every span start. This is the only processor TraceRoot
|
|
@@ -10,14 +12,29 @@ exports.SDK_VERSION = '0.1.0';
|
|
|
10
12
|
*/
|
|
11
13
|
class TraceRootSpanProcessor {
|
|
12
14
|
inner;
|
|
13
|
-
|
|
15
|
+
_environment;
|
|
16
|
+
_gitRepo;
|
|
17
|
+
_gitRef;
|
|
18
|
+
constructor(inner, opts = {}) {
|
|
14
19
|
this.inner = inner;
|
|
20
|
+
this._environment = opts.environment;
|
|
21
|
+
this._gitRepo = opts.gitRepo;
|
|
22
|
+
this._gitRef = opts.gitRef;
|
|
15
23
|
}
|
|
16
24
|
onStart(span, parentContext) {
|
|
17
25
|
span.setAttributes({
|
|
18
26
|
'traceroot.sdk.name': exports.SDK_NAME,
|
|
19
27
|
'traceroot.sdk.version': exports.SDK_VERSION,
|
|
20
28
|
});
|
|
29
|
+
if (this._environment !== undefined) {
|
|
30
|
+
span.setAttribute('deployment.environment', this._environment);
|
|
31
|
+
}
|
|
32
|
+
if (this._gitRepo !== undefined) {
|
|
33
|
+
span.setAttribute('traceroot.git.repo', this._gitRepo);
|
|
34
|
+
}
|
|
35
|
+
if (this._gitRef !== undefined) {
|
|
36
|
+
span.setAttribute('traceroot.git.ref', this._gitRef);
|
|
37
|
+
}
|
|
21
38
|
// Cast required: inner processor expects the internal sdk-trace-base Span,
|
|
22
39
|
// but the SpanProcessor interface uses the public @opentelemetry/api Span.
|
|
23
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/processor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";;;AASA,iEAAiE;AACjE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAEzD,QAAA,QAAQ,GAAG,cAAc,CAAC;AAC1B,QAAA,WAAW,GAAG,OAAO,CAAC;AAQnC;;;;GAIG;AACH,MAAa,sBAAsB;IAChB,KAAK,CAA2C;IAChD,YAAY,CAAqB;IACjC,QAAQ,CAAqB;IAC7B,OAAO,CAAqB;IAE7C,YACE,KAA+C,EAC/C,OAAsC,EAA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1 @@
|
|
|
1
|
-
{"version":3,"file":"traceroot.d.ts","sourceRoot":"","sources":["../src/traceroot.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"traceroot.d.ts","sourceRoot":"","sources":["../src/traceroot.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAW5C,qBAAa,SAAS;IACpB,OAAO;IAEP,MAAM,CAAC,aAAa,IAAI,OAAO;IAI/B,MAAM,CAAC,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI;WA2E3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;WAItB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAMvC;AAED,gBAAgB;AAChB,wBAAgB,gBAAgB,IAAI,IAAI,CAQvC"}
|
package/dist/traceroot.js
CHANGED
|
@@ -10,6 +10,7 @@ const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
|
10
10
|
const processor_1 = require("./processor");
|
|
11
11
|
const instrumentation_1 = require("./instrumentation");
|
|
12
12
|
const observe_1 = require("./observe");
|
|
13
|
+
const git_context_1 = require("./git_context");
|
|
13
14
|
const DEFAULT_BASE_URL = 'https://app.traceroot.ai';
|
|
14
15
|
let _isInitialized = false;
|
|
15
16
|
let _provider;
|
|
@@ -19,6 +20,10 @@ class TraceRoot {
|
|
|
19
20
|
return _isInitialized;
|
|
20
21
|
}
|
|
21
22
|
static initialize(options = {}) {
|
|
23
|
+
const enabled = options.enabled ?? (process.env['TRACEROOT_ENABLED'] !== 'false');
|
|
24
|
+
if (!enabled) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
22
27
|
if (_isInitialized) {
|
|
23
28
|
console.warn('[TraceRoot] Already initialized. Skipping duplicate initialize() call.');
|
|
24
29
|
return;
|
|
@@ -49,14 +54,30 @@ class TraceRoot {
|
|
|
49
54
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
55
|
compression: 'gzip',
|
|
51
56
|
});
|
|
57
|
+
const environment = options.environment ?? process.env['TRACEROOT_ENVIRONMENT'];
|
|
58
|
+
const gitRepoOverride = options.gitRepo ?? process.env['TRACEROOT_GIT_REPO'];
|
|
59
|
+
const gitRefOverride = options.gitRef ?? process.env['TRACEROOT_GIT_REF'];
|
|
60
|
+
let gitRepo = gitRepoOverride;
|
|
61
|
+
let gitRef = gitRefOverride;
|
|
62
|
+
if (gitRepo === undefined || gitRef === undefined) {
|
|
63
|
+
const autoGit = (0, git_context_1.autoDetectGitContext)(); // also warms the git root cache
|
|
64
|
+
gitRepo ??= autoGit.gitRepo;
|
|
65
|
+
gitRef ??= autoGit.gitRef;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
(0, git_context_1.getGitRoot)(); // warm git root cache for captureSourceLocation without shelling out for repo/ref
|
|
69
|
+
}
|
|
52
70
|
const innerProcessor = options.disableBatch
|
|
53
71
|
? new sdk_trace_base_1.SimpleSpanProcessor(exporter)
|
|
54
72
|
: new sdk_trace_base_1.BatchSpanProcessor(exporter);
|
|
55
73
|
_provider = new sdk_trace_node_1.NodeTracerProvider();
|
|
56
|
-
_provider.addSpanProcessor(new processor_1.TraceRootSpanProcessor(innerProcessor));
|
|
74
|
+
_provider.addSpanProcessor(new processor_1.TraceRootSpanProcessor(innerProcessor, { environment, gitRepo, gitRef }));
|
|
57
75
|
_provider.register();
|
|
58
76
|
(0, instrumentation_1.wireInstrumentations)(options.instrumentModules);
|
|
59
77
|
_isInitialized = true;
|
|
78
|
+
// forceFlush() is async and keeps the event loop alive via its HTTP export request,
|
|
79
|
+
// so beforeExit + forceFlush() is sufficient — no keepAlive timer needed.
|
|
80
|
+
process.once('beforeExit', () => { void _provider?.forceFlush(); });
|
|
60
81
|
}
|
|
61
82
|
static async flush() {
|
|
62
83
|
await _provider?.forceFlush();
|
|
@@ -74,6 +95,7 @@ function _resetForTesting() {
|
|
|
74
95
|
_isInitialized = false;
|
|
75
96
|
_provider = undefined;
|
|
76
97
|
(0, observe_1._resetObserveState)();
|
|
98
|
+
(0, git_context_1._resetGitContextCache)();
|
|
77
99
|
api_1.trace.disable();
|
|
78
100
|
api_1.context.disable();
|
|
79
101
|
api_1.propagation.disable();
|
package/dist/traceroot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traceroot.js","sourceRoot":"","sources":["../src/traceroot.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"traceroot.js","sourceRoot":"","sources":["../src/traceroot.ts"],"names":[],"mappings":";;;AA+GA,4CAQC;AAvHD,mBAAmB;AACnB,4CAAwG;AACxG,wFAA6E;AAC7E,kEAAwF;AACxF,kEAAmE;AAEnE,2CAA4E;AAC5E,uDAAyD;AACzD,uCAA+C;AAC/C,+CAAwF;AAExF,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,SAAyC,CAAC;AAE9C,MAAa,SAAS;IACpB,gBAAuB,CAAC;IAExB,MAAM,CAAC,aAAa;QAClB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,UAA6B,EAAE;QAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,KAAK,OAAO,CAAC,CAAC;QAClF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QAED,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,wEAAwE,CAAC,CAAC;YACvF,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAClE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,CACV,iGAAiG;gBACj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IAC9B,cAAc,GAAG,KAAK,CAAC;IACvB,SAAS,GAAG,SAAS,CAAC;IACtB,IAAA,4BAAkB,GAAE,CAAC;IACrB,IAAA,mCAAqB,GAAE,CAAC;IACxB,WAAK,CAAC,OAAO,EAAE,CAAC;IAChB,aAAO,CAAC,OAAO,EAAE,CAAC;IAClB,iBAAW,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export interface ObserveOptions {
|
|
|
6
6
|
type?: SpanType;
|
|
7
7
|
/** Input to record on the span. Explicitly passed — no auto-inference. */
|
|
8
8
|
input?: unknown;
|
|
9
|
+
/** Arbitrary metadata to attach to this span. */
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
/** Tags to attach to this span. */
|
|
12
|
+
tags?: string[];
|
|
9
13
|
}
|
|
10
14
|
export interface InitializeOptions {
|
|
11
15
|
/** API key for TraceRoot. Falls back to TRACEROOT_API_KEY env var. */
|
|
@@ -32,5 +36,26 @@ export interface InitializeOptions {
|
|
|
32
36
|
disableBatch?: boolean;
|
|
33
37
|
/** OTel diagnostic log level. Defaults to 'error'. */
|
|
34
38
|
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
39
|
+
/**
|
|
40
|
+
* Disable all tracing. Falls back to TRACEROOT_ENABLED env var ('false' disables).
|
|
41
|
+
* When false, initialize() is a no-op and no spans are recorded.
|
|
42
|
+
*/
|
|
43
|
+
enabled?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Deployment environment tag (e.g. 'production', 'staging').
|
|
46
|
+
* Falls back to TRACEROOT_ENVIRONMENT env var.
|
|
47
|
+
* Stamped on every span as 'deployment.environment'.
|
|
48
|
+
*/
|
|
49
|
+
environment?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Git repository in normalized 'owner/repo' form (e.g. 'acme/my-service').
|
|
52
|
+
* Falls back to TRACEROOT_GIT_REPO env var, then auto-detected via `git remote get-url origin`.
|
|
53
|
+
*/
|
|
54
|
+
gitRepo?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Git commit SHA (typically a 40-character hash). Falls back to TRACEROOT_GIT_REF env var,
|
|
57
|
+
* then auto-detected via `git rev-parse HEAD`.
|
|
58
|
+
*/
|
|
59
|
+
gitRef?: string;
|
|
35
60
|
}
|
|
36
61
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE;QAClB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,uFAAuF;IACvF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE;QAClB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,uFAAuF;IACvF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface UsingAttributesOptions {
|
|
2
|
+
/** Associate all spans in this block with a session / conversation ID. */
|
|
3
|
+
sessionId?: string;
|
|
4
|
+
/** Associate all spans in this block with a user. */
|
|
5
|
+
userId?: string;
|
|
6
|
+
/** Tag all spans in this block. */
|
|
7
|
+
tags?: string[];
|
|
8
|
+
/** Attach arbitrary metadata to all spans in this block. */
|
|
9
|
+
metadata?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Runs `fn` in an OpenTelemetry context that carries the given OpenInference
|
|
13
|
+
* attributes. Every span created inside `fn` — including those produced by
|
|
14
|
+
* auto-instrumented libraries (OpenAI, Anthropic, LangChain, …) — inherits
|
|
15
|
+
* sessionId, userId, tags, and metadata automatically.
|
|
16
|
+
*
|
|
17
|
+
* Spans created *before* entering this call are not retroactively updated.
|
|
18
|
+
* `usingAttributes` calls can be nested; the innermost value for each field wins.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const answer = await usingAttributes(
|
|
23
|
+
* { sessionId: 'conv-123', userId: 'u-456', tags: ['prod'] },
|
|
24
|
+
* () => myPipeline.run(userMessage),
|
|
25
|
+
* );
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function usingAttributes<T>(attrs: UsingAttributesOptions, fn: () => T | Promise<T>): Promise<T>;
|
|
29
|
+
//# sourceMappingURL=usingAttributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usingAttributes.d.ts","sourceRoot":"","sources":["../src/usingAttributes.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,sBAAsB;IACrC,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,KAAK,EAAE,sBAAsB,EAC7B,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usingAttributes = usingAttributes;
|
|
4
|
+
// src/usingAttributes.ts
|
|
5
|
+
const api_1 = require("@opentelemetry/api");
|
|
6
|
+
const openinference_core_1 = require("@arizeai/openinference-core");
|
|
7
|
+
/**
|
|
8
|
+
* Runs `fn` in an OpenTelemetry context that carries the given OpenInference
|
|
9
|
+
* attributes. Every span created inside `fn` — including those produced by
|
|
10
|
+
* auto-instrumented libraries (OpenAI, Anthropic, LangChain, …) — inherits
|
|
11
|
+
* sessionId, userId, tags, and metadata automatically.
|
|
12
|
+
*
|
|
13
|
+
* Spans created *before* entering this call are not retroactively updated.
|
|
14
|
+
* `usingAttributes` calls can be nested; the innermost value for each field wins.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const answer = await usingAttributes(
|
|
19
|
+
* { sessionId: 'conv-123', userId: 'u-456', tags: ['prod'] },
|
|
20
|
+
* () => myPipeline.run(userMessage),
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
async function usingAttributes(attrs, fn) {
|
|
25
|
+
let ctx = api_1.context.active();
|
|
26
|
+
if (attrs.sessionId !== undefined) {
|
|
27
|
+
ctx = (0, openinference_core_1.setSession)(ctx, { sessionId: attrs.sessionId });
|
|
28
|
+
}
|
|
29
|
+
if (attrs.userId !== undefined) {
|
|
30
|
+
ctx = (0, openinference_core_1.setUser)(ctx, { userId: attrs.userId });
|
|
31
|
+
}
|
|
32
|
+
if (attrs.tags !== undefined) {
|
|
33
|
+
ctx = (0, openinference_core_1.setTags)(ctx, attrs.tags);
|
|
34
|
+
}
|
|
35
|
+
if (attrs.metadata !== undefined) {
|
|
36
|
+
ctx = (0, openinference_core_1.setMetadata)(ctx, attrs.metadata);
|
|
37
|
+
}
|
|
38
|
+
return api_1.context.with(ctx, () => Promise.resolve(fn()));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=usingAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usingAttributes.js","sourceRoot":"","sources":["../src/usingAttributes.ts"],"names":[],"mappings":";;AAgCA,0CAoBC;AApDD,yBAAyB;AACzB,4CAA6C;AAC7C,oEAAwF;AAaxF;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,eAAe,CACnC,KAA6B,EAC7B,EAAwB;IAExB,IAAI,GAAG,GAAG,aAAO,CAAC,MAAM,EAAE,CAAC;IAE3B,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAClC,GAAG,GAAG,IAAA,+BAAU,EAAC,GAAG,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC/B,GAAG,GAAG,IAAA,4BAAO,EAAC,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC7B,GAAG,GAAG,IAAA,4BAAO,EAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACjC,GAAG,GAAG,IAAA,gCAAW,EAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,aAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traceroot-ai/traceroot",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "TraceRoot TypeScript SDK for AI observability",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"traceroot",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@arizeai/openinference-core": "^2.0.5",
|
|
38
39
|
"@arizeai/openinference-instrumentation-anthropic": "^0.1.7",
|
|
39
40
|
"@arizeai/openinference-instrumentation-bedrock": "^0.4.8",
|
|
40
41
|
"@arizeai/openinference-instrumentation-claude-agent-sdk": "^0.2.0",
|