@traceroot-ai/traceroot 0.1.0-alpha.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/LICENSE +201 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +44 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.d.ts +12 -0
- package/dist/instrumentation.d.ts.map +1 -0
- package/dist/instrumentation.js +66 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/observe.d.ts +13 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/observe.js +77 -0
- package/dist/observe.js.map +1 -0
- package/dist/processor.d.ts +18 -0
- package/dist/processor.d.ts.map +1 -0
- package/dist/processor.js +37 -0
- package/dist/processor.js.map +1 -0
- package/dist/traceroot.d.ts +11 -0
- package/dist/traceroot.d.ts.map +1 -0
- package/dist/traceroot.js +81 -0
- package/dist/traceroot.js.map +1 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 @ TraceRoot.AI
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets input, output, or metadata attributes on the currently active span.
|
|
3
|
+
* No-op when called outside an active span.
|
|
4
|
+
*/
|
|
5
|
+
export declare function updateCurrentSpan(attrs: {
|
|
6
|
+
input?: unknown;
|
|
7
|
+
output?: unknown;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
}): void;
|
|
10
|
+
/**
|
|
11
|
+
* Sets trace-level association attributes (user, session, tags) on the
|
|
12
|
+
* currently active span. No-op when called outside an active span.
|
|
13
|
+
*/
|
|
14
|
+
export declare function updateCurrentTrace(attrs: {
|
|
15
|
+
userId?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
tags?: string[];
|
|
18
|
+
}): void;
|
|
19
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAWA;;;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"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateCurrentSpan = updateCurrentSpan;
|
|
4
|
+
exports.updateCurrentTrace = updateCurrentTrace;
|
|
5
|
+
// src/context.ts
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
|
|
8
|
+
/**
|
|
9
|
+
* Sets input, output, or metadata attributes on the currently active span.
|
|
10
|
+
* No-op when called outside an active span.
|
|
11
|
+
*/
|
|
12
|
+
function updateCurrentSpan(attrs) {
|
|
13
|
+
const span = api_1.trace.getActiveSpan();
|
|
14
|
+
if (!span)
|
|
15
|
+
return;
|
|
16
|
+
if (attrs.input !== undefined) {
|
|
17
|
+
span.setAttribute(openinference_semantic_conventions_1.INPUT_VALUE, JSON.stringify(attrs.input));
|
|
18
|
+
}
|
|
19
|
+
if (attrs.output !== undefined) {
|
|
20
|
+
span.setAttribute(openinference_semantic_conventions_1.OUTPUT_VALUE, JSON.stringify(attrs.output));
|
|
21
|
+
}
|
|
22
|
+
if (attrs.metadata !== undefined) {
|
|
23
|
+
span.setAttribute(openinference_semantic_conventions_1.METADATA, JSON.stringify(attrs.metadata));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets trace-level association attributes (user, session, tags) on the
|
|
28
|
+
* currently active span. No-op when called outside an active span.
|
|
29
|
+
*/
|
|
30
|
+
function updateCurrentTrace(attrs) {
|
|
31
|
+
const span = api_1.trace.getActiveSpan();
|
|
32
|
+
if (!span)
|
|
33
|
+
return;
|
|
34
|
+
if (attrs.userId !== undefined) {
|
|
35
|
+
span.setAttribute(openinference_semantic_conventions_1.USER_ID, attrs.userId);
|
|
36
|
+
}
|
|
37
|
+
if (attrs.sessionId !== undefined) {
|
|
38
|
+
span.setAttribute(openinference_semantic_conventions_1.SESSION_ID, attrs.sessionId);
|
|
39
|
+
}
|
|
40
|
+
if (attrs.tags !== undefined) {
|
|
41
|
+
span.setAttribute(openinference_semantic_conventions_1.TAG_TAGS, JSON.stringify(attrs.tags));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;AAeA,8CAiBC;AAMD,gDAiBC;AAvDD,iBAAiB;AACjB,4CAA2C;AA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,CAAC,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +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;AAClE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateCurrentTrace = exports.updateCurrentSpan = exports.observe = exports.TraceRoot = void 0;
|
|
4
|
+
// src/index.ts
|
|
5
|
+
var traceroot_1 = require("./traceroot");
|
|
6
|
+
Object.defineProperty(exports, "TraceRoot", { enumerable: true, get: function () { return traceroot_1.TraceRoot; } });
|
|
7
|
+
var observe_1 = require("./observe");
|
|
8
|
+
Object.defineProperty(exports, "observe", { enumerable: true, get: function () { return observe_1.observe; } });
|
|
9
|
+
var context_1 = require("./context");
|
|
10
|
+
Object.defineProperty(exports, "updateCurrentSpan", { enumerable: true, get: function () { return context_1.updateCurrentSpan; } });
|
|
11
|
+
Object.defineProperty(exports, "updateCurrentTrace", { enumerable: true, get: function () { return context_1.updateCurrentTrace; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,qCAAkE;AAAzD,4GAAA,iBAAiB,OAAA;AAAE,6GAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InitializeOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Wires OpenInference instrumentations based on the instrumentModules option:
|
|
4
|
+
*
|
|
5
|
+
* - undefined → RITM auto-instrumentation for all supported modules (CJS only)
|
|
6
|
+
* - {} → no instrumentation
|
|
7
|
+
* - { openAI } → manual patch only the provided module refs
|
|
8
|
+
*
|
|
9
|
+
* Called once by TraceRoot.initialize().
|
|
10
|
+
*/
|
|
11
|
+
export declare function wireInstrumentations(instrumentModules: InitializeOptions['instrumentModules']): void;
|
|
12
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../src/instrumentation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG5C;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,iBAAiB,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,GACxD,IAAI,CAsDN"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wireInstrumentations = wireInstrumentations;
|
|
4
|
+
// src/instrumentation.ts
|
|
5
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
6
|
+
const openinference_instrumentation_anthropic_1 = require("@arizeai/openinference-instrumentation-anthropic");
|
|
7
|
+
const openinference_instrumentation_bedrock_1 = require("@arizeai/openinference-instrumentation-bedrock");
|
|
8
|
+
const openinference_instrumentation_claude_agent_sdk_1 = require("@arizeai/openinference-instrumentation-claude-agent-sdk");
|
|
9
|
+
const openinference_instrumentation_langchain_1 = require("@arizeai/openinference-instrumentation-langchain");
|
|
10
|
+
const openinference_instrumentation_openai_1 = require("@arizeai/openinference-instrumentation-openai");
|
|
11
|
+
/**
|
|
12
|
+
* Wires OpenInference instrumentations based on the instrumentModules option:
|
|
13
|
+
*
|
|
14
|
+
* - undefined → RITM auto-instrumentation for all supported modules (CJS only)
|
|
15
|
+
* - {} → no instrumentation
|
|
16
|
+
* - { openAI } → manual patch only the provided module refs
|
|
17
|
+
*
|
|
18
|
+
* Called once by TraceRoot.initialize().
|
|
19
|
+
*/
|
|
20
|
+
function wireInstrumentations(instrumentModules) {
|
|
21
|
+
if (instrumentModules === undefined) {
|
|
22
|
+
// Auto-instrumentation via require-in-the-middle (CJS only).
|
|
23
|
+
// ESM users must pass explicit module refs.
|
|
24
|
+
(0, instrumentation_1.registerInstrumentations)({
|
|
25
|
+
instrumentations: [
|
|
26
|
+
new openinference_instrumentation_openai_1.OpenAIInstrumentation(),
|
|
27
|
+
new openinference_instrumentation_anthropic_1.AnthropicInstrumentation(),
|
|
28
|
+
new openinference_instrumentation_langchain_1.LangChainInstrumentation(),
|
|
29
|
+
new openinference_instrumentation_claude_agent_sdk_1.ClaudeAgentSDKInstrumentation(),
|
|
30
|
+
new openinference_instrumentation_bedrock_1.BedrockInstrumentation(),
|
|
31
|
+
],
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const instrs = [];
|
|
36
|
+
if (instrumentModules.openAI) {
|
|
37
|
+
const instr = new openinference_instrumentation_openai_1.OpenAIInstrumentation();
|
|
38
|
+
instrs.push(instr);
|
|
39
|
+
instr.manuallyInstrument(instrumentModules.openAI);
|
|
40
|
+
}
|
|
41
|
+
if (instrumentModules.anthropic) {
|
|
42
|
+
const instr = new openinference_instrumentation_anthropic_1.AnthropicInstrumentation();
|
|
43
|
+
instrs.push(instr);
|
|
44
|
+
instr.manuallyInstrument(instrumentModules.anthropic);
|
|
45
|
+
}
|
|
46
|
+
if (instrumentModules.langchain) {
|
|
47
|
+
// langchain must be: import * as lcCallbackManager from '@langchain/core/callbacks/manager'
|
|
48
|
+
const instr = new openinference_instrumentation_langchain_1.LangChainInstrumentation();
|
|
49
|
+
instrs.push(instr);
|
|
50
|
+
instr.manuallyInstrument(instrumentModules.langchain);
|
|
51
|
+
}
|
|
52
|
+
if (instrumentModules.claudeAgentSDK) {
|
|
53
|
+
const instr = new openinference_instrumentation_claude_agent_sdk_1.ClaudeAgentSDKInstrumentation();
|
|
54
|
+
instrs.push(instr);
|
|
55
|
+
instr.manuallyInstrument(instrumentModules.claudeAgentSDK);
|
|
56
|
+
}
|
|
57
|
+
if (instrumentModules.bedrock) {
|
|
58
|
+
const instr = new openinference_instrumentation_bedrock_1.BedrockInstrumentation();
|
|
59
|
+
instrs.push(instr);
|
|
60
|
+
instr.manuallyInstrument(instrumentModules.bedrock);
|
|
61
|
+
}
|
|
62
|
+
if (instrs.length > 0) {
|
|
63
|
+
(0, instrumentation_1.registerInstrumentations)({ instrumentations: instrs });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../src/instrumentation.ts"],"names":[],"mappings":";;AAmBA,oDAwDC;AA3ED,yBAAyB;AACzB,oEAA0E;AAC1E,8GAA4F;AAC5F,0GAAwF;AACxF,4HAAwG;AACxG,8GAA4F;AAC5F,wGAAsF;AAItF;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAClC,iBAAyD;IAEzD,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,6DAA6D;QAC7D,4CAA4C;QAC5C,IAAA,0CAAwB,EAAC;YACvB,gBAAgB,EAAE;gBAChB,IAAI,4DAAqB,EAAE;gBAC3B,IAAI,kEAAwB,EAAE;gBAC9B,IAAI,kEAAwB,EAAE;gBAC9B,IAAI,8EAA6B,EAAE;gBACnC,IAAI,8DAAsB,EAAE;aAC7B;SACF,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAMN,EAAE,CAAC;IAET,IAAI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C,CAAC;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ObserveOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps fn() in an OpenTelemetry span, capturing input/output using
|
|
4
|
+
* OpenInference semconv. Nested calls automatically become child spans
|
|
5
|
+
* via AsyncLocalStorage context propagation.
|
|
6
|
+
*
|
|
7
|
+
* Works as a no-op (calls fn() untraced) if no OTel TracerProvider is registered.
|
|
8
|
+
* Warns once to console in that case.
|
|
9
|
+
*/
|
|
10
|
+
export declare function observe<T>(options: ObserveOptions, fn: () => T | Promise<T>): Promise<T>;
|
|
11
|
+
/** @internal — reset module state between tests */
|
|
12
|
+
export declare function _resetObserveState(): void;
|
|
13
|
+
//# sourceMappingURL=observe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../src/observe.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAY,MAAM,SAAS,CAAC;AAanD;;;;;;;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,CA+CZ;AAED,mDAAmD;AACnD,wBAAgB,kBAAkB,IAAI,IAAI,CAGzC"}
|
package/dist/observe.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observe = observe;
|
|
4
|
+
exports._resetObserveState = _resetObserveState;
|
|
5
|
+
// src/observe.ts
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
|
|
8
|
+
const OPENINFERENCE_SPAN_KIND = openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND;
|
|
9
|
+
const SPAN_KIND_MAP = {
|
|
10
|
+
agent: 'AGENT',
|
|
11
|
+
tool: 'TOOL',
|
|
12
|
+
llm: 'LLM',
|
|
13
|
+
span: 'CHAIN',
|
|
14
|
+
};
|
|
15
|
+
// Cached once after the first call; the tracer name never changes.
|
|
16
|
+
let _tracer;
|
|
17
|
+
let _hasWarnedUninit = false;
|
|
18
|
+
/**
|
|
19
|
+
* Wraps fn() in an OpenTelemetry span, capturing input/output using
|
|
20
|
+
* OpenInference semconv. Nested calls automatically become child spans
|
|
21
|
+
* via AsyncLocalStorage context propagation.
|
|
22
|
+
*
|
|
23
|
+
* Works as a no-op (calls fn() untraced) if no OTel TracerProvider is registered.
|
|
24
|
+
* Warns once to console in that case.
|
|
25
|
+
*/
|
|
26
|
+
async function observe(options, fn) {
|
|
27
|
+
const name = options.name ?? (fn.name || 'anonymous');
|
|
28
|
+
_tracer ??= api_1.trace.getTracer('traceroot-ts');
|
|
29
|
+
return _tracer.startActiveSpan(name, async (span) => {
|
|
30
|
+
if (!span.isRecording()) {
|
|
31
|
+
if (!_hasWarnedUninit) {
|
|
32
|
+
_hasWarnedUninit = true;
|
|
33
|
+
console.warn('[TraceRoot] observe() called but TraceRoot.initialize() was not called. Spans will not be recorded.');
|
|
34
|
+
}
|
|
35
|
+
// No-op path: just run fn() and return.
|
|
36
|
+
try {
|
|
37
|
+
return await fn();
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
span.end();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
span.setAttribute(OPENINFERENCE_SPAN_KIND, SPAN_KIND_MAP[options.type ?? 'span']);
|
|
45
|
+
if (options.input !== undefined) {
|
|
46
|
+
try {
|
|
47
|
+
span.setAttribute(openinference_semantic_conventions_1.INPUT_VALUE, JSON.stringify(options.input));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Non-serializable input — skip attribute
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const result = await fn();
|
|
54
|
+
try {
|
|
55
|
+
span.setAttribute(openinference_semantic_conventions_1.OUTPUT_VALUE, JSON.stringify(result));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Non-serializable output — skip attribute
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
64
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR });
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
span.end();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** @internal — reset module state between tests */
|
|
73
|
+
function _resetObserveState() {
|
|
74
|
+
_tracer = undefined;
|
|
75
|
+
_hasWarnedUninit = false;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=observe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.js","sourceRoot":"","sources":["../src/observe.ts"],"names":[],"mappings":";;AA8BA,0BAkDC;AAGD,gDAGC;AAtFD,iBAAiB;AACjB,4CAA2D;AAC3D,oGAIqD;AAErD,MAAM,uBAAuB,GAAG,wDAAmB,CAAC,uBAAuB,CAAC;AAG5E,MAAM,aAAa,GAA6B;IAC9C,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,OAAO;CACd,CAAC;AAEF,mEAAmE;AACnE,IAAI,OAAuD,CAAC;AAC5D,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAE7B;;;;;;;GAOG;AACI,KAAK,UAAU,OAAO,CAC3B,OAAuB,EACvB,EAAwB;IAExB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC;IACtD,OAAO,KAAK,WAAK,CAAC,SAA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,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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Context, Span } from '@opentelemetry/api';
|
|
2
|
+
import { BatchSpanProcessor, ReadableSpan, SimpleSpanProcessor, SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
3
|
+
export declare const SDK_NAME = "traceroot-ts";
|
|
4
|
+
export declare const SDK_VERSION = "0.1.0";
|
|
5
|
+
/**
|
|
6
|
+
* Wraps an inner SpanProcessor (Batch or Simple) and injects TraceRoot SDK
|
|
7
|
+
* metadata attributes on every span start. This is the only processor TraceRoot
|
|
8
|
+
* registers; the inner processor handles actual export batching.
|
|
9
|
+
*/
|
|
10
|
+
export declare class TraceRootSpanProcessor implements SpanProcessor {
|
|
11
|
+
private readonly inner;
|
|
12
|
+
constructor(inner: BatchSpanProcessor | SimpleSpanProcessor);
|
|
13
|
+
onStart(span: Span, parentContext: Context): void;
|
|
14
|
+
onEnd(span: ReadableSpan): void;
|
|
15
|
+
forceFlush(): Promise<void>;
|
|
16
|
+
shutdown(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=processor.d.ts.map
|
|
@@ -0,0 +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;AAEvC,eAAO,MAAM,QAAQ,iBAAiB,CAAC;AACvC,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2C;gBAErD,KAAK,EAAE,kBAAkB,GAAG,mBAAmB;IAI3D,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI;IAWjD,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAI/B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAG1B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraceRootSpanProcessor = exports.SDK_VERSION = exports.SDK_NAME = void 0;
|
|
4
|
+
exports.SDK_NAME = 'traceroot-ts';
|
|
5
|
+
exports.SDK_VERSION = '0.1.0';
|
|
6
|
+
/**
|
|
7
|
+
* Wraps an inner SpanProcessor (Batch or Simple) and injects TraceRoot SDK
|
|
8
|
+
* metadata attributes on every span start. This is the only processor TraceRoot
|
|
9
|
+
* registers; the inner processor handles actual export batching.
|
|
10
|
+
*/
|
|
11
|
+
class TraceRootSpanProcessor {
|
|
12
|
+
inner;
|
|
13
|
+
constructor(inner) {
|
|
14
|
+
this.inner = inner;
|
|
15
|
+
}
|
|
16
|
+
onStart(span, parentContext) {
|
|
17
|
+
span.setAttributes({
|
|
18
|
+
'traceroot.sdk.name': exports.SDK_NAME,
|
|
19
|
+
'traceroot.sdk.version': exports.SDK_VERSION,
|
|
20
|
+
});
|
|
21
|
+
// Cast required: inner processor expects the internal sdk-trace-base Span,
|
|
22
|
+
// but the SpanProcessor interface uses the public @opentelemetry/api Span.
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
this.inner.onStart(span, parentContext);
|
|
25
|
+
}
|
|
26
|
+
onEnd(span) {
|
|
27
|
+
this.inner.onEnd(span);
|
|
28
|
+
}
|
|
29
|
+
forceFlush() {
|
|
30
|
+
return this.inner.forceFlush();
|
|
31
|
+
}
|
|
32
|
+
shutdown() {
|
|
33
|
+
return this.inner.shutdown();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.TraceRootSpanProcessor = TraceRootSpanProcessor;
|
|
37
|
+
//# sourceMappingURL=processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";;;AASa,QAAA,QAAQ,GAAG,cAAc,CAAC;AAC1B,QAAA,WAAW,GAAG,OAAO,CAAC;AAEnC;;;;GAIG;AACH,MAAa,sBAAsB;IAChB,KAAK,CAA2C;IAEjE,YAAY,KAA+C;QACzD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,OAAO,CAAC,IAAU,EAAE,aAAsB;QACxC,IAAI,CAAC,aAAa,CAAC;YACjB,oBAAoB,EAAE,gBAAQ;YAC9B,uBAAuB,EAAE,mBAAW;SACrC,CAAC,CAAC;QACH,2EAA2E;QAC3E,2EAA2E;QAC3E,8DAA8D;QAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAW,EAAE,aAAa,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,IAAkB;QACtB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;IACjC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AA7BD,wDA6BC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InitializeOptions } from './types';
|
|
2
|
+
export declare class TraceRoot {
|
|
3
|
+
private constructor();
|
|
4
|
+
static isInitialized(): boolean;
|
|
5
|
+
static initialize(options?: InitializeOptions): void;
|
|
6
|
+
static flush(): Promise<void>;
|
|
7
|
+
static shutdown(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/** @internal */
|
|
10
|
+
export declare function _resetForTesting(): void;
|
|
11
|
+
//# sourceMappingURL=traceroot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceroot.d.ts","sourceRoot":"","sources":["../src/traceroot.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAU5C,qBAAa,SAAS;IACpB,OAAO;IAEP,MAAM,CAAC,aAAa,IAAI,OAAO;IAI/B,MAAM,CAAC,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI;WAqD3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;WAItB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAMvC;AAED,gBAAgB;AAChB,wBAAgB,gBAAgB,IAAI,IAAI,CAOvC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraceRoot = void 0;
|
|
4
|
+
exports._resetForTesting = _resetForTesting;
|
|
5
|
+
// src/traceroot.ts
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
8
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
9
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
10
|
+
const processor_1 = require("./processor");
|
|
11
|
+
const instrumentation_1 = require("./instrumentation");
|
|
12
|
+
const observe_1 = require("./observe");
|
|
13
|
+
const DEFAULT_BASE_URL = 'https://app.traceroot.ai';
|
|
14
|
+
let _isInitialized = false;
|
|
15
|
+
let _provider;
|
|
16
|
+
class TraceRoot {
|
|
17
|
+
constructor() { }
|
|
18
|
+
static isInitialized() {
|
|
19
|
+
return _isInitialized;
|
|
20
|
+
}
|
|
21
|
+
static initialize(options = {}) {
|
|
22
|
+
if (_isInitialized) {
|
|
23
|
+
console.warn('[TraceRoot] Already initialized. Skipping duplicate initialize() call.');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const apiKey = options.apiKey ?? process.env['TRACEROOT_API_KEY'];
|
|
27
|
+
if (!apiKey) {
|
|
28
|
+
console.warn('[TraceRoot] No API key provided. Set TRACEROOT_API_KEY env var or pass apiKey to initialize(). ' +
|
|
29
|
+
'Spans will be emitted but export will fail.');
|
|
30
|
+
}
|
|
31
|
+
const logLevelMap = {
|
|
32
|
+
debug: api_1.DiagLogLevel.DEBUG,
|
|
33
|
+
info: api_1.DiagLogLevel.INFO,
|
|
34
|
+
warn: api_1.DiagLogLevel.WARN,
|
|
35
|
+
error: api_1.DiagLogLevel.ERROR,
|
|
36
|
+
};
|
|
37
|
+
api_1.diag.setLogger(new api_1.DiagConsoleLogger(), logLevelMap[options.logLevel ?? 'error'] ?? api_1.DiagLogLevel.ERROR);
|
|
38
|
+
const baseUrl = (options.baseUrl ?? process.env['TRACEROOT_HOST_URL'] ?? DEFAULT_BASE_URL).replace(/\/$/, '');
|
|
39
|
+
const headers = {
|
|
40
|
+
'x-traceroot-sdk-name': processor_1.SDK_NAME,
|
|
41
|
+
'x-traceroot-sdk-version': processor_1.SDK_VERSION,
|
|
42
|
+
};
|
|
43
|
+
if (apiKey)
|
|
44
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
45
|
+
const exporter = new exporter_trace_otlp_proto_1.OTLPTraceExporter({
|
|
46
|
+
url: `${baseUrl}/api/v1/public/traces`,
|
|
47
|
+
headers,
|
|
48
|
+
// CompressionAlgorithm.GZIP = "gzip"; using string literal to avoid importing transitive dep
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
compression: 'gzip',
|
|
51
|
+
});
|
|
52
|
+
const innerProcessor = options.disableBatch
|
|
53
|
+
? new sdk_trace_base_1.SimpleSpanProcessor(exporter)
|
|
54
|
+
: new sdk_trace_base_1.BatchSpanProcessor(exporter);
|
|
55
|
+
_provider = new sdk_trace_node_1.NodeTracerProvider();
|
|
56
|
+
_provider.addSpanProcessor(new processor_1.TraceRootSpanProcessor(innerProcessor));
|
|
57
|
+
_provider.register();
|
|
58
|
+
(0, instrumentation_1.wireInstrumentations)(options.instrumentModules);
|
|
59
|
+
_isInitialized = true;
|
|
60
|
+
}
|
|
61
|
+
static async flush() {
|
|
62
|
+
await _provider?.forceFlush();
|
|
63
|
+
}
|
|
64
|
+
static async shutdown() {
|
|
65
|
+
await _provider?.shutdown();
|
|
66
|
+
_isInitialized = false;
|
|
67
|
+
_provider = undefined;
|
|
68
|
+
(0, observe_1._resetObserveState)();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.TraceRoot = TraceRoot;
|
|
72
|
+
/** @internal */
|
|
73
|
+
function _resetForTesting() {
|
|
74
|
+
_isInitialized = false;
|
|
75
|
+
_provider = undefined;
|
|
76
|
+
(0, observe_1._resetObserveState)();
|
|
77
|
+
api_1.trace.disable();
|
|
78
|
+
api_1.context.disable();
|
|
79
|
+
api_1.propagation.disable();
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=traceroot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceroot.js","sourceRoot":"","sources":["../src/traceroot.ts"],"names":[],"mappings":";;;AAwFA,4CAOC;AA/FD,mBAAmB;AACnB,4CAAwG;AACxG,wFAA6E;AAC7E,kEAAwF;AACxF,kEAAmE;AAEnE,2CAA4E;AAC5E,uDAAyD;AACzD,uCAA+C;AAE/C,MAAM,gBAAgB,GAAG,0BAA0B,CAAC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,GAAG,EAAE,GAAG,OAAO,uBAAuB;YACtC,OAAO;YACP,6FAA6F;YAC7F,8DAA8D;YAC9D,WAAW,EAAE,MAAa;SAC3B,CAAC,CAAC;QAEH,MAAM,cAAc,GAAG,OAAO,CAAC,YAAY;YACzC,CAAC,CAAC,IAAI,oCAAmB,CAAC,QAAQ,CAAC;YACnC,CAAC,CAAC,IAAI,mCAAkB,CAAC,QAAQ,CAAC,CAAC;QAErC,SAAS,GAAG,IAAI,mCAAkB,EAAE,CAAC;QACrC,SAAS,CAAC,gBAAgB,CAAC,IAAI,kCAAsB,CAAC,cAAc,CAAC,CAAC,CAAC;QACvE,SAAS,CAAC,QAAQ,EAAE,CAAC;QAErB,IAAA,sCAAoB,EAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAEhD,cAAc,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,MAAM,SAAS,EAAE,UAAU,EAAE,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,QAAQ;QACnB,MAAM,SAAS,EAAE,QAAQ,EAAE,CAAC;QAC5B,cAAc,GAAG,KAAK,CAAC;QACvB,SAAS,GAAG,SAAS,CAAC;QACtB,IAAA,4BAAkB,GAAE,CAAC;IACvB,CAAC;CACF;AAtED,8BAsEC;AAED,gBAAgB;AAChB,SAAgB,gBAAgB;IAC9B,cAAc,GAAG,KAAK,CAAC;IACvB,SAAS,GAAG,SAAS,CAAC;IACtB,IAAA,4BAAkB,GAAE,CAAC;IACrB,WAAK,CAAC,OAAO,EAAE,CAAC;IAChB,aAAO,CAAC,OAAO,EAAE,CAAC;IAClB,iBAAW,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type SpanType = 'span' | 'agent' | 'tool' | 'llm';
|
|
2
|
+
export interface ObserveOptions {
|
|
3
|
+
/** Span name. Defaults to fn.name, then 'anonymous'. */
|
|
4
|
+
name?: string;
|
|
5
|
+
/** Span kind. Defaults to 'span' → openinference.span.kind = 'CHAIN'. */
|
|
6
|
+
type?: SpanType;
|
|
7
|
+
/** Input to record on the span. Explicitly passed — no auto-inference. */
|
|
8
|
+
input?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface InitializeOptions {
|
|
11
|
+
/** API key for TraceRoot. Falls back to TRACEROOT_API_KEY env var. */
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
/** Base URL for the TraceRoot backend. Defaults to https://app.traceroot.ai */
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Modules to instrument.
|
|
17
|
+
* - undefined → auto-instrument all supported modules (CJS only, RITM hooks)
|
|
18
|
+
* - {} → disable all auto-instrumentation
|
|
19
|
+
* - { openAI: OpenAI } → instrument only the provided modules
|
|
20
|
+
*
|
|
21
|
+
* LangChain note: pass `import * as lcCallbackManager from '@langchain/core/callbacks/manager'`
|
|
22
|
+
* as the `langchain` value — NOT the LangChain class itself.
|
|
23
|
+
*/
|
|
24
|
+
instrumentModules?: {
|
|
25
|
+
openAI?: unknown;
|
|
26
|
+
anthropic?: unknown;
|
|
27
|
+
langchain?: unknown;
|
|
28
|
+
claudeAgentSDK?: unknown;
|
|
29
|
+
bedrock?: unknown;
|
|
30
|
+
};
|
|
31
|
+
/** Use SimpleSpanProcessor instead of BatchSpanProcessor. Useful for scripts/tests. */
|
|
32
|
+
disableBatch?: boolean;
|
|
33
|
+
/** OTel diagnostic log level. Defaults to 'error'. */
|
|
34
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;CAChD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,eAAe"}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@traceroot-ai/traceroot",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "TraceRoot TypeScript SDK for AI observability",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"require": "./dist/index.js",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/traceroot-ai/traceroot-ts.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://traceroot.ai",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/traceroot-ai/traceroot-ts/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@arizeai/openinference-instrumentation-anthropic": "^0.1.7",
|
|
34
|
+
"@arizeai/openinference-instrumentation-bedrock": "^0.4.8",
|
|
35
|
+
"@arizeai/openinference-instrumentation-claude-agent-sdk": "^0.2.0",
|
|
36
|
+
"@arizeai/openinference-instrumentation-langchain": "^4.0.6",
|
|
37
|
+
"@arizeai/openinference-instrumentation-openai": "^4.0.5",
|
|
38
|
+
"@arizeai/openinference-semantic-conventions": "^2.1.7",
|
|
39
|
+
"@opentelemetry/api": "^1.9.1",
|
|
40
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.57.2",
|
|
41
|
+
"@opentelemetry/instrumentation": "^0.46.0",
|
|
42
|
+
"@opentelemetry/resources": "^1.30.1",
|
|
43
|
+
"@opentelemetry/sdk-trace-base": "^1.30.1",
|
|
44
|
+
"@opentelemetry/sdk-trace-node": "^1.30.1",
|
|
45
|
+
"@opentelemetry/semantic-conventions": "^1.40.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@eslint/js": "^9.0.0",
|
|
49
|
+
"@types/node": "^20.0.0",
|
|
50
|
+
"eslint": "^9.0.0",
|
|
51
|
+
"tsx": "^4.19.0",
|
|
52
|
+
"typescript": "^5.5.0",
|
|
53
|
+
"typescript-eslint": "^8.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@anthropic-ai/sdk": ">=0.20.0",
|
|
57
|
+
"openai": ">=6.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"openai": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"@anthropic-ai/sdk": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsc",
|
|
69
|
+
"test": "tsx --test tests/*.test.ts",
|
|
70
|
+
"lint": "eslint src tests",
|
|
71
|
+
"typecheck": "tsc --noEmit",
|
|
72
|
+
"clean": "rm -rf dist"
|
|
73
|
+
}
|
|
74
|
+
}
|