@respan/tracing 1.0.45
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/README.md +860 -0
- package/dist/constants/index.d.ts +8 -0
- package/dist/constants/index.js +9 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/contexts/index.d.ts +1 -0
- package/dist/contexts/index.js +2 -0
- package/dist/contexts/index.js.map +1 -0
- package/dist/contexts/span.d.ts +9 -0
- package/dist/contexts/span.js +39 -0
- package/dist/contexts/span.js.map +1 -0
- package/dist/decorators/base.d.ts +32 -0
- package/dist/decorators/base.js +242 -0
- package/dist/decorators/base.js.map +1 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +2 -0
- package/dist/instrumentation/index.js +3 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/loader.d.ts +5 -0
- package/dist/instrumentation/loader.js +104 -0
- package/dist/instrumentation/loader.js.map +1 -0
- package/dist/instrumentation/manager.d.ts +29 -0
- package/dist/instrumentation/manager.js +564 -0
- package/dist/instrumentation/manager.js.map +1 -0
- package/dist/main.d.ts +162 -0
- package/dist/main.js +212 -0
- package/dist/main.js.map +1 -0
- package/dist/processor/composite.d.ts +29 -0
- package/dist/processor/composite.js +106 -0
- package/dist/processor/composite.js.map +1 -0
- package/dist/processor/filtering.d.ts +19 -0
- package/dist/processor/filtering.js +78 -0
- package/dist/processor/filtering.js.map +1 -0
- package/dist/processor/index.d.ts +3 -0
- package/dist/processor/index.js +4 -0
- package/dist/processor/index.js.map +1 -0
- package/dist/processor/manager.d.ts +61 -0
- package/dist/processor/manager.js +111 -0
- package/dist/processor/manager.js.map +1 -0
- package/dist/types/clientTypes.d.ts +188 -0
- package/dist/types/clientTypes.js +22 -0
- package/dist/types/clientTypes.js.map +1 -0
- package/dist/types/decoratorTypes.d.ts +6 -0
- package/dist/types/decoratorTypes.js +2 -0
- package/dist/types/decoratorTypes.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/instrumentationTypes.d.ts +25 -0
- package/dist/types/instrumentationTypes.js +82 -0
- package/dist/types/instrumentationTypes.js.map +1 -0
- package/dist/utils/client.d.ts +168 -0
- package/dist/utils/client.js +151 -0
- package/dist/utils/client.js.map +1 -0
- package/dist/utils/context.d.ts +28 -0
- package/dist/utils/context.js +44 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/span.d.ts +65 -0
- package/dist/utils/span.js +269 -0
- package/dist/utils/span.js.map +1 -0
- package/dist/utils/spanBuffer.d.ts +94 -0
- package/dist/utils/spanBuffer.js +147 -0
- package/dist/utils/spanBuffer.js.map +1 -0
- package/dist/utils/tracing.d.ts +31 -0
- package/dist/utils/tracing.js +239 -0
- package/dist/utils/tracing.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Context } from "@opentelemetry/api";
|
|
2
|
+
import { SpanProcessor, ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for a processor
|
|
5
|
+
*/
|
|
6
|
+
export interface ProcessorConfig {
|
|
7
|
+
/** The span exporter to use */
|
|
8
|
+
exporter: SpanExporter;
|
|
9
|
+
/** Name identifier for this processor (used for routing) */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Optional custom filter function for spans */
|
|
12
|
+
filter?: (span: ReadableSpan) => boolean;
|
|
13
|
+
/** Optional priority (higher = processed first) */
|
|
14
|
+
priority?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Manager for multiple span processors with routing capabilities.
|
|
18
|
+
*
|
|
19
|
+
* This allows you to route spans to different destinations based on:
|
|
20
|
+
* - Processor name matching (from decorator `processors` parameter)
|
|
21
|
+
* - Custom filter functions
|
|
22
|
+
* - Priority ordering
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const manager = new MultiProcessorManager();
|
|
27
|
+
*
|
|
28
|
+
* // Add debug processor (only receives spans with processors="debug")
|
|
29
|
+
* manager.addProcessor({
|
|
30
|
+
* exporter: new FileExporter("./debug.json"),
|
|
31
|
+
* name: "debug"
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Add production processor with custom filter
|
|
35
|
+
* manager.addProcessor({
|
|
36
|
+
* exporter: new RespanSpanExporter({...}),
|
|
37
|
+
* name: "production",
|
|
38
|
+
* filter: (span) => !span.name.includes("test")
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class MultiProcessorManager implements SpanProcessor {
|
|
43
|
+
private processors;
|
|
44
|
+
/**
|
|
45
|
+
* Add a new processor with routing configuration
|
|
46
|
+
* @param config - Processor configuration
|
|
47
|
+
*/
|
|
48
|
+
addProcessor(config: ProcessorConfig): void;
|
|
49
|
+
/**
|
|
50
|
+
* Get all configured processors
|
|
51
|
+
*/
|
|
52
|
+
getProcessors(): ProcessorConfig[];
|
|
53
|
+
/**
|
|
54
|
+
* Check if a span should be sent to a specific processor
|
|
55
|
+
*/
|
|
56
|
+
private shouldSendToProcessor;
|
|
57
|
+
onStart(span: ReadableSpan, parentContext: Context): void;
|
|
58
|
+
onEnd(span: ReadableSpan): void;
|
|
59
|
+
shutdown(): Promise<void>;
|
|
60
|
+
forceFlush(): Promise<void>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BatchSpanProcessor, } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
/**
|
|
3
|
+
* Manager for multiple span processors with routing capabilities.
|
|
4
|
+
*
|
|
5
|
+
* This allows you to route spans to different destinations based on:
|
|
6
|
+
* - Processor name matching (from decorator `processors` parameter)
|
|
7
|
+
* - Custom filter functions
|
|
8
|
+
* - Priority ordering
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const manager = new MultiProcessorManager();
|
|
13
|
+
*
|
|
14
|
+
* // Add debug processor (only receives spans with processors="debug")
|
|
15
|
+
* manager.addProcessor({
|
|
16
|
+
* exporter: new FileExporter("./debug.json"),
|
|
17
|
+
* name: "debug"
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Add production processor with custom filter
|
|
21
|
+
* manager.addProcessor({
|
|
22
|
+
* exporter: new RespanSpanExporter({...}),
|
|
23
|
+
* name: "production",
|
|
24
|
+
* filter: (span) => !span.name.includes("test")
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export class MultiProcessorManager {
|
|
29
|
+
processors = [];
|
|
30
|
+
/**
|
|
31
|
+
* Add a new processor with routing configuration
|
|
32
|
+
* @param config - Processor configuration
|
|
33
|
+
*/
|
|
34
|
+
addProcessor(config) {
|
|
35
|
+
const processor = new BatchSpanProcessor(config.exporter);
|
|
36
|
+
// Insert in priority order (higher priority first)
|
|
37
|
+
const priority = config.priority ?? 0;
|
|
38
|
+
const insertIndex = this.processors.findIndex((p) => (p.config.priority ?? 0) < priority);
|
|
39
|
+
if (insertIndex === -1) {
|
|
40
|
+
this.processors.push({ processor, config });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.processors.splice(insertIndex, 0, { processor, config });
|
|
44
|
+
}
|
|
45
|
+
console.debug(`[Respan] Added processor "${config.name}" with priority ${priority}`);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get all configured processors
|
|
49
|
+
*/
|
|
50
|
+
getProcessors() {
|
|
51
|
+
return this.processors.map((p) => p.config);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if a span should be sent to a specific processor
|
|
55
|
+
*/
|
|
56
|
+
shouldSendToProcessor(span, config) {
|
|
57
|
+
// Check if span has processors attribute
|
|
58
|
+
const spanProcessors = span.attributes["respan.processors"];
|
|
59
|
+
if (spanProcessors) {
|
|
60
|
+
// Parse processors attribute (could be string or array)
|
|
61
|
+
let processorsList = [];
|
|
62
|
+
if (typeof spanProcessors === "string") {
|
|
63
|
+
processorsList = [spanProcessors];
|
|
64
|
+
}
|
|
65
|
+
else if (Array.isArray(spanProcessors)) {
|
|
66
|
+
// Filter out null/undefined values and ensure all are strings
|
|
67
|
+
processorsList = spanProcessors.filter((p) => typeof p === "string");
|
|
68
|
+
}
|
|
69
|
+
// Check if this processor's name is in the list
|
|
70
|
+
const matchesName = processorsList.includes(config.name);
|
|
71
|
+
// If there's a custom filter, both must match
|
|
72
|
+
if (config.filter) {
|
|
73
|
+
return matchesName && config.filter(span);
|
|
74
|
+
}
|
|
75
|
+
return matchesName;
|
|
76
|
+
}
|
|
77
|
+
// If no processors attribute, only send if there's a custom filter that matches
|
|
78
|
+
if (config.filter) {
|
|
79
|
+
return config.filter(span);
|
|
80
|
+
}
|
|
81
|
+
// If no processors attribute and no custom filter:
|
|
82
|
+
// - Send to "default" processor (backward compatibility)
|
|
83
|
+
// - Don't send to other named processors (they need explicit routing)
|
|
84
|
+
return config.name === "default";
|
|
85
|
+
}
|
|
86
|
+
onStart(span, parentContext) {
|
|
87
|
+
// Forward to all processors (they'll decide whether to process in onEnd)
|
|
88
|
+
for (const { processor } of this.processors) {
|
|
89
|
+
processor.onStart(span, parentContext);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
onEnd(span) {
|
|
93
|
+
// Check each processor to see if it should receive this span
|
|
94
|
+
for (const { processor, config } of this.processors) {
|
|
95
|
+
if (this.shouldSendToProcessor(span, config)) {
|
|
96
|
+
console.debug(`[Respan] Sending span "${span.name}" to processor "${config.name}"`);
|
|
97
|
+
processor.onEnd(span);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.debug(`[Respan] Skipping span "${span.name}" for processor "${config.name}"`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async shutdown() {
|
|
105
|
+
await Promise.all(this.processors.map(({ processor }) => processor.shutdown()));
|
|
106
|
+
}
|
|
107
|
+
async forceFlush() {
|
|
108
|
+
await Promise.all(this.processors.map(({ processor }) => processor.forceFlush()));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/processor/manager.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAgBvC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,qBAAqB;IACxB,UAAU,GAGb,EAAE,CAAC;IAER;;;OAGG;IACH,YAAY,CAAC,MAAuB;QAClC,MAAM,SAAS,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAE1D,mDAAmD;QACnD,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;QACtC,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAC3C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,QAAQ,CAC3C,CAAC;QAEF,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;QAChE,CA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{ TextMapPropagator, ContextManager } from "@opentelemetry/api";
|
|
3
|
+
/**
|
|
4
|
+
* Available instrumentation names for consistent camelCase naming.
|
|
5
|
+
* Abbreviations like AI, API, DB are kept uppercase.
|
|
6
|
+
*/
|
|
7
|
+
export type InstrumentationName = 'http' | 'openAI' | 'anthropic' | 'azureOpenAI' | 'cohere' | 'bedrock' | 'googleVertexAI' | 'googleAIPlatform' | 'pinecone' | 'together' | 'langChain' | 'llamaIndex' | 'chromaDB' | 'qdrant';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for a span processor with routing capabilities
|
|
10
|
+
*/
|
|
11
|
+
export interface ProcessorConfig {
|
|
12
|
+
/** The span exporter to use */
|
|
13
|
+
exporter: SpanExporter;
|
|
14
|
+
/** Name identifier for this processor (used for routing) */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Optional custom filter function for spans */
|
|
17
|
+
filter?: (span: any) => boolean;
|
|
18
|
+
/** Optional priority (higher = processed first) */
|
|
19
|
+
priority?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for initializing the Respan SDK.
|
|
23
|
+
*/
|
|
24
|
+
export interface RespanOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The app name to be used when reporting traces. Optional.
|
|
27
|
+
* Defaults to the package name.
|
|
28
|
+
*/
|
|
29
|
+
appName?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The API Key for sending traces data. Optional.
|
|
32
|
+
* Defaults to the RESPAN_API_KEY environment variable.
|
|
33
|
+
*/
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The OTLP endpoint for sending traces data. Optional.
|
|
37
|
+
* Defaults to RESPAN_BASE_URL environment variable or https://api.respan.co/
|
|
38
|
+
*/
|
|
39
|
+
baseURL?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Sends traces and spans without batching, for local development. Optional.
|
|
42
|
+
* Defaults to false.
|
|
43
|
+
*/
|
|
44
|
+
disableBatch?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Defines default log level for SDK and all instrumentations. Optional.
|
|
47
|
+
* Defaults to error.
|
|
48
|
+
*/
|
|
49
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
50
|
+
/**
|
|
51
|
+
* Whether to log prompts, completions and embeddings on traces. Optional.
|
|
52
|
+
* Defaults to true.
|
|
53
|
+
*/
|
|
54
|
+
traceContent?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The OpenTelemetry SpanExporter to be used for sending traces data. Optional.
|
|
57
|
+
* Defaults to the OTLP exporter.
|
|
58
|
+
*/
|
|
59
|
+
exporter?: SpanExporter;
|
|
60
|
+
/**
|
|
61
|
+
* The headers to be sent with the traces data. Optional.
|
|
62
|
+
*/
|
|
63
|
+
headers?: Record<string, string>;
|
|
64
|
+
/**
|
|
65
|
+
* The OpenTelemetry SpanProcessor to be used for processing traces data. Optional.
|
|
66
|
+
* Defaults to the BatchSpanProcessor.
|
|
67
|
+
*/
|
|
68
|
+
processor?: SpanProcessor;
|
|
69
|
+
/**
|
|
70
|
+
* The OpenTelemetry Propagator to use. Optional.
|
|
71
|
+
* Defaults to OpenTelemetry SDK defaults.
|
|
72
|
+
*/
|
|
73
|
+
propagator?: TextMapPropagator;
|
|
74
|
+
/**
|
|
75
|
+
* The OpenTelemetry ContextManager to use. Optional.
|
|
76
|
+
* Defaults to OpenTelemetry SDK defaults.
|
|
77
|
+
*/
|
|
78
|
+
contextManager?: ContextManager;
|
|
79
|
+
/**
|
|
80
|
+
* Whether to silence the initialization message. Optional.
|
|
81
|
+
* Defaults to false.
|
|
82
|
+
*/
|
|
83
|
+
silenceInitializationMessage?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether to enable tracing. Optional.
|
|
86
|
+
* Defaults to true.
|
|
87
|
+
*/
|
|
88
|
+
tracingEnabled?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Additional resource attributes to attach to all spans. Optional.
|
|
91
|
+
* Useful for adding environment, version, region, etc.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* resourceAttributes: {
|
|
96
|
+
* environment: 'production',
|
|
97
|
+
* version: '1.0.0',
|
|
98
|
+
* region: 'us-east-1'
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
resourceAttributes?: Record<string, string>;
|
|
103
|
+
/**
|
|
104
|
+
* Optional callback function to process spans before export.
|
|
105
|
+
* This is called for each span before it's sent to the exporter.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* spanPostprocessCallback: (span) => {
|
|
110
|
+
* // Add custom processing
|
|
111
|
+
* console.log('Processing span:', span.name);
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
spanPostprocessCallback?: (span: any) => void;
|
|
116
|
+
/**
|
|
117
|
+
* Explicitly specify modules to instrument. Optional.
|
|
118
|
+
* This is a workaround specific to Next.js and other environments where
|
|
119
|
+
* dynamic imports might not work properly.
|
|
120
|
+
*
|
|
121
|
+
* Usage example:
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import OpenAI from 'openai';
|
|
124
|
+
* import Anthropic from '@anthropic-ai/sdk';
|
|
125
|
+
*
|
|
126
|
+
* const respan = new RespanTelemetry({
|
|
127
|
+
* instrumentModules: {
|
|
128
|
+
* openAI: OpenAI,
|
|
129
|
+
* anthropic: Anthropic,
|
|
130
|
+
* }
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
instrumentModules?: {
|
|
135
|
+
openAI?: any;
|
|
136
|
+
anthropic?: any;
|
|
137
|
+
azureOpenAI?: any;
|
|
138
|
+
cohere?: any;
|
|
139
|
+
bedrock?: any;
|
|
140
|
+
googleVertexAI?: any;
|
|
141
|
+
googleAIPlatform?: any;
|
|
142
|
+
pinecone?: any;
|
|
143
|
+
together?: any;
|
|
144
|
+
langChain?: {
|
|
145
|
+
chainsModule?: any;
|
|
146
|
+
agentsModule?: any;
|
|
147
|
+
toolsModule?: any;
|
|
148
|
+
runnablesModule?: any;
|
|
149
|
+
vectorStoreModule?: any;
|
|
150
|
+
};
|
|
151
|
+
llamaIndex?: any;
|
|
152
|
+
chromaDB?: any;
|
|
153
|
+
qdrant?: any;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* List of instrumentation modules to disable. Optional.
|
|
157
|
+
* Useful for preventing certain instrumentations from being loaded.
|
|
158
|
+
* Uses consistent camelCase naming with abbreviations kept uppercase.
|
|
159
|
+
*
|
|
160
|
+
* Usage example:
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const respan = new RespanTelemetry({
|
|
163
|
+
* disabledInstrumentations: ['bedrock', 'chromaDB', 'qdrant']
|
|
164
|
+
* });
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
disabledInstrumentations?: InstrumentationName[];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The main client options for Respan.
|
|
171
|
+
*/
|
|
172
|
+
export interface RespanClientOptions {
|
|
173
|
+
apiKey: string;
|
|
174
|
+
appName: string;
|
|
175
|
+
baseURL?: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Base class for all Respan errors.
|
|
179
|
+
*/
|
|
180
|
+
export declare class RespanError extends Error {
|
|
181
|
+
constructor(message: string);
|
|
182
|
+
}
|
|
183
|
+
export declare class InitializationError extends RespanError {
|
|
184
|
+
constructor(message?: string);
|
|
185
|
+
}
|
|
186
|
+
export declare class NotInitializedError extends RespanError {
|
|
187
|
+
constructor();
|
|
188
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all Respan errors.
|
|
3
|
+
*/
|
|
4
|
+
export class RespanError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'RespanError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class InitializationError extends RespanError {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message || 'Failed to initialize Respan');
|
|
13
|
+
this.name = 'InitializationError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class NotInitializedError extends RespanError {
|
|
17
|
+
constructor() {
|
|
18
|
+
super('Respan has not been initialized');
|
|
19
|
+
this.name = 'NotInitializedError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=clientTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientTypes.js","sourceRoot":"","sources":["../../src/types/clientTypes.ts"],"names":[],"mappings":"AAmNA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAClC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC9B,CAAC;CACJ;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAChD,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,IAAI,6BAA6B,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAChD;QACI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DecoratorConfig } from "../decorators/base.js";
|
|
2
|
+
export type WithFunctionType = <A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A) => ReturnType<F>;
|
|
3
|
+
export type WithAgentType = WithFunctionType;
|
|
4
|
+
export type WithTaskType = WithFunctionType;
|
|
5
|
+
export type WithWorkflowType = WithFunctionType;
|
|
6
|
+
export type WithToolType = WithFunctionType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoratorTypes.js","sourceRoot":"","sources":["../../src/types/decoratorTypes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { InstrumentationName } from "./clientTypes.js";
|
|
2
|
+
export interface InstrumentationInfo {
|
|
3
|
+
packageName: string;
|
|
4
|
+
importPackage: string;
|
|
5
|
+
description: string;
|
|
6
|
+
installCommand: string;
|
|
7
|
+
}
|
|
8
|
+
export interface InstrumentationLoadResult {
|
|
9
|
+
name: string;
|
|
10
|
+
status: "success" | "failed" | "disabled" | "not-provided";
|
|
11
|
+
description: string;
|
|
12
|
+
error?: any;
|
|
13
|
+
}
|
|
14
|
+
export interface InstrumentationConfig {
|
|
15
|
+
name: InstrumentationName;
|
|
16
|
+
description: string;
|
|
17
|
+
loadFunction: () => Promise<any>;
|
|
18
|
+
}
|
|
19
|
+
export interface ManualInstrumentationConfig {
|
|
20
|
+
name: InstrumentationName;
|
|
21
|
+
description: string;
|
|
22
|
+
moduleKey: string;
|
|
23
|
+
initFunction: (module: any) => Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
export declare const INSTRUMENTATION_INFO: Record<string, InstrumentationInfo>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Instrumentation metadata for installation hints
|
|
2
|
+
export const INSTRUMENTATION_INFO = {
|
|
3
|
+
openAI: {
|
|
4
|
+
packageName: "@traceloop/instrumentation-openai",
|
|
5
|
+
importPackage: "@traceloop/instrumentation-openai",
|
|
6
|
+
description: "OpenAI API instrumentation",
|
|
7
|
+
installCommand: "npm install @traceloop/instrumentation-openai",
|
|
8
|
+
},
|
|
9
|
+
anthropic: {
|
|
10
|
+
packageName: "@traceloop/instrumentation-anthropic",
|
|
11
|
+
importPackage: "@traceloop/instrumentation-anthropic",
|
|
12
|
+
description: "Anthropic API instrumentation",
|
|
13
|
+
installCommand: "npm install @traceloop/instrumentation-anthropic",
|
|
14
|
+
},
|
|
15
|
+
azureOpenAI: {
|
|
16
|
+
packageName: "@traceloop/instrumentation-azure",
|
|
17
|
+
importPackage: "@traceloop/instrumentation-azure",
|
|
18
|
+
description: "Azure OpenAI instrumentation",
|
|
19
|
+
installCommand: "npm install @traceloop/instrumentation-azure",
|
|
20
|
+
},
|
|
21
|
+
bedrock: {
|
|
22
|
+
packageName: "@traceloop/instrumentation-bedrock",
|
|
23
|
+
importPackage: "@traceloop/instrumentation-bedrock",
|
|
24
|
+
description: "AWS Bedrock instrumentation",
|
|
25
|
+
installCommand: "npm install @traceloop/instrumentation-bedrock",
|
|
26
|
+
},
|
|
27
|
+
cohere: {
|
|
28
|
+
packageName: "@traceloop/instrumentation-cohere",
|
|
29
|
+
importPackage: "@traceloop/instrumentation-cohere",
|
|
30
|
+
description: "Cohere API instrumentation",
|
|
31
|
+
installCommand: "npm install @traceloop/instrumentation-cohere",
|
|
32
|
+
},
|
|
33
|
+
langChain: {
|
|
34
|
+
packageName: "@traceloop/instrumentation-langchain",
|
|
35
|
+
importPackage: "@traceloop/instrumentation-langchain",
|
|
36
|
+
description: "LangChain framework instrumentation",
|
|
37
|
+
installCommand: "npm install @traceloop/instrumentation-langchain",
|
|
38
|
+
},
|
|
39
|
+
llamaIndex: {
|
|
40
|
+
packageName: "@traceloop/instrumentation-llamaindex",
|
|
41
|
+
importPackage: "@traceloop/instrumentation-llamaindex",
|
|
42
|
+
description: "LlamaIndex framework instrumentation",
|
|
43
|
+
installCommand: "npm install @traceloop/instrumentation-llamaindex",
|
|
44
|
+
},
|
|
45
|
+
pinecone: {
|
|
46
|
+
packageName: "@traceloop/instrumentation-pinecone",
|
|
47
|
+
importPackage: "@traceloop/instrumentation-pinecone",
|
|
48
|
+
description: "Pinecone vector database instrumentation",
|
|
49
|
+
installCommand: "npm install @traceloop/instrumentation-pinecone",
|
|
50
|
+
},
|
|
51
|
+
chromaDB: {
|
|
52
|
+
packageName: "@traceloop/instrumentation-chromadb",
|
|
53
|
+
importPackage: "@traceloop/instrumentation-chromadb",
|
|
54
|
+
description: "ChromaDB vector database instrumentation",
|
|
55
|
+
installCommand: "npm install @traceloop/instrumentation-chromadb",
|
|
56
|
+
},
|
|
57
|
+
qdrant: {
|
|
58
|
+
packageName: "@traceloop/instrumentation-qdrant",
|
|
59
|
+
importPackage: "@traceloop/instrumentation-qdrant",
|
|
60
|
+
description: "Qdrant vector database instrumentation",
|
|
61
|
+
installCommand: "npm install @traceloop/instrumentation-qdrant",
|
|
62
|
+
},
|
|
63
|
+
together: {
|
|
64
|
+
packageName: "@traceloop/instrumentation-together",
|
|
65
|
+
importPackage: "@traceloop/instrumentation-together",
|
|
66
|
+
description: "Together AI instrumentation",
|
|
67
|
+
installCommand: "npm install @traceloop/instrumentation-together",
|
|
68
|
+
},
|
|
69
|
+
googleVertexAI: {
|
|
70
|
+
packageName: "@traceloop/instrumentation-vertexai",
|
|
71
|
+
importPackage: "@traceloop/instrumentation-vertexai",
|
|
72
|
+
description: "Google Vertex AI instrumentation",
|
|
73
|
+
installCommand: "npm install @traceloop/instrumentation-vertexai",
|
|
74
|
+
},
|
|
75
|
+
googleAIPlatform: {
|
|
76
|
+
packageName: "@traceloop/instrumentation-vertexai",
|
|
77
|
+
importPackage: "@traceloop/instrumentation-vertexai",
|
|
78
|
+
description: "Google AI Platform instrumentation",
|
|
79
|
+
installCommand: "npm install @traceloop/instrumentation-vertexai",
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=instrumentationTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentationTypes.js","sourceRoot":"","sources":["../../src/types/instrumentationTypes.ts"],"names":[],"mappings":"AA6BA,kDAAkD;AAClD,MAAM,CAAC,MAAM,oBAAoB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