@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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants used throughout the Respan tracing SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The name of this package, used as the instrumentation library name
|
|
6
|
+
* This should match the package.json name field
|
|
7
|
+
*/
|
|
8
|
+
export const RESPAN_PACKAGE_NAME = "@respan/tracing";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./span.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RespanParams } from '@respan/respan-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* A context manager for setting Respan-specific attributes on the current span
|
|
4
|
+
*
|
|
5
|
+
* @param fn - The function to execute within the context
|
|
6
|
+
* @param params - Dictionary of parameters to set as span attributes
|
|
7
|
+
* @returns The result of the function execution
|
|
8
|
+
*/
|
|
9
|
+
export declare function withRespanSpanAttributes<T>(fn: () => Promise<T> | T, params: Partial<RespanParams>): Promise<T>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { trace, context } from '@opentelemetry/api';
|
|
2
|
+
import { RESPAN_SPAN_ATTRIBUTES_MAP } from '@respan/respan-sdk';
|
|
3
|
+
/**
|
|
4
|
+
* A context manager for setting Respan-specific attributes on the current span
|
|
5
|
+
*
|
|
6
|
+
* @param fn - The function to execute within the context
|
|
7
|
+
* @param params - Dictionary of parameters to set as span attributes
|
|
8
|
+
* @returns The result of the function execution
|
|
9
|
+
*/
|
|
10
|
+
export async function withRespanSpanAttributes(fn, params) {
|
|
11
|
+
const currentSpan = trace.getSpan(context.active());
|
|
12
|
+
if (!currentSpan) {
|
|
13
|
+
console.warn("No active span found. Attributes will not be set.");
|
|
14
|
+
return fn();
|
|
15
|
+
}
|
|
16
|
+
// Set attributes first, but don't let errors block execution
|
|
17
|
+
try {
|
|
18
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
19
|
+
if (key in RESPAN_SPAN_ATTRIBUTES_MAP && key !== "metadata") {
|
|
20
|
+
try {
|
|
21
|
+
currentSpan.setAttribute(RESPAN_SPAN_ATTRIBUTES_MAP[key], value);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.warn(`Failed to set span attribute ${RESPAN_SPAN_ATTRIBUTES_MAP[key]}=${value}: ${e}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (params.metadata) {
|
|
29
|
+
Object.entries(params.metadata).forEach(([key, value]) => {
|
|
30
|
+
currentSpan.setAttribute(`${RESPAN_SPAN_ATTRIBUTES_MAP.metadata}.${key}`, JSON.stringify(value));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
console.warn(`Error setting span attributes: ${e}`);
|
|
36
|
+
}
|
|
37
|
+
return fn();
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=span.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span.js","sourceRoot":"","sources":["../../src/contexts/span.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAkB,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAgB,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC1C,EAAwB,EACxB,MAA6B;IAE7B,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEpD,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QAClE,OAAO,EAAE,EAAE,CAAC;IAChB,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5C,IAAI,GAAG,IAAI,0BAA0B,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC1D,IAAI,CAAC;oBACD,WAAW,CAAC,YAAY,CAAC,0BAA0B,CAAC,GAAG,CAAC,EAAE,KAAuB,CAAC,CAAC;gBACvF,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,OAAO,CAAC,IAAI,CAAC,gCAAgC,0BAA0B,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC,CAAC;gBACnG,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACrD,WAAW,CAAC,YAAY,CACpB,GAAG,0BAA0B,CAAC,QAAQ,IAAI,GAAG,EAAE,EAC/C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CACxB,CAAC;YACN,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,EAAE,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type DecoratorConfig = {
|
|
2
|
+
name: string;
|
|
3
|
+
version?: number;
|
|
4
|
+
associationProperties?: {
|
|
5
|
+
[name: string]: string;
|
|
6
|
+
};
|
|
7
|
+
traceContent?: boolean;
|
|
8
|
+
inputParameters?: unknown[];
|
|
9
|
+
suppressTracing?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Route this span to specific processors by name.
|
|
12
|
+
* Can be a single processor name or an array of names.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Single processor
|
|
17
|
+
* { processors: "debug" }
|
|
18
|
+
*
|
|
19
|
+
* // Multiple processors
|
|
20
|
+
* { processors: ["debug", "analytics"] }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
processors?: string | string[];
|
|
24
|
+
};
|
|
25
|
+
export declare function withWorkflow<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): ReturnType<F>;
|
|
26
|
+
export declare function withTask<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): ReturnType<F>;
|
|
27
|
+
export declare function withAgent<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): ReturnType<F>;
|
|
28
|
+
export declare function withTool<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): ReturnType<F>;
|
|
29
|
+
export declare function workflow(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
30
|
+
export declare function task(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
31
|
+
export declare function agent(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
32
|
+
export declare function tool(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { context, SpanStatusCode } from "@opentelemetry/api";
|
|
2
|
+
import { suppressTracing } from "@opentelemetry/core";
|
|
3
|
+
import { ASSOCIATION_PROPERTIES_KEY, ENTITY_NAME_KEY, getEntityPath, WORKFLOW_NAME_KEY, shouldSendTraces, } from "../utils/context.js";
|
|
4
|
+
import { getTracer } from "../utils/span.js";
|
|
5
|
+
import { CONTEXT_KEY_ALLOW_TRACE_CONTENT, SpanAttributes, TraceloopSpanKindValues, } from "@traceloop/ai-semantic-conventions";
|
|
6
|
+
/**
|
|
7
|
+
* Core function that wraps any function with OpenTelemetry tracing capabilities.
|
|
8
|
+
* This creates a span around the function execution and manages the trace context.
|
|
9
|
+
*
|
|
10
|
+
* @param type - The type of entity being traced (WORKFLOW, TASK, AGENT, TOOL)
|
|
11
|
+
* @param config - Configuration for the tracing decorator
|
|
12
|
+
* @param fn - The function to be wrapped with tracing
|
|
13
|
+
* @param thisArg - The 'this' context for the function
|
|
14
|
+
* @param args - Arguments to pass to the function
|
|
15
|
+
* @returns The result of the wrapped function
|
|
16
|
+
*/
|
|
17
|
+
function withEntity(type, { name, version, associationProperties, traceContent: overrideTraceContent, inputParameters, suppressTracing: shouldSuppressTracing, processors, }, fn, thisArg, ...args) {
|
|
18
|
+
// STEP 1: Get the current active context (inherits from parent spans)
|
|
19
|
+
// This context contains all the trace information from parent operations
|
|
20
|
+
let entityContext = context.active();
|
|
21
|
+
// STEP 2: Handle workflow/agent context setup
|
|
22
|
+
// Workflows and agents are top-level entities that can contain other entities
|
|
23
|
+
if (type === TraceloopSpanKindValues.WORKFLOW ||
|
|
24
|
+
type === TraceloopSpanKindValues.AGENT) {
|
|
25
|
+
// Store the workflow name in context so child spans can access it
|
|
26
|
+
entityContext = entityContext.setValue(WORKFLOW_NAME_KEY, name);
|
|
27
|
+
}
|
|
28
|
+
// STEP 3: Build hierarchical entity paths for tools and tasks
|
|
29
|
+
// This creates a dot-separated path like "workflow.task.subtask"
|
|
30
|
+
const entityPath = getEntityPath(entityContext);
|
|
31
|
+
if (type === TraceloopSpanKindValues.TOOL ||
|
|
32
|
+
type === TraceloopSpanKindValues.TASK) {
|
|
33
|
+
// Create full path: if we're in "myWorkflow" and this is "myTask",
|
|
34
|
+
// the full name becomes "myWorkflow.myTask"
|
|
35
|
+
const fullEntityName = entityPath ? `${entityPath}.${name}` : name;
|
|
36
|
+
entityContext = entityContext.setValue(ENTITY_NAME_KEY, fullEntityName);
|
|
37
|
+
}
|
|
38
|
+
// STEP 4: Configure trace content settings
|
|
39
|
+
// This controls whether input/output data should be captured in traces
|
|
40
|
+
if (overrideTraceContent != undefined) {
|
|
41
|
+
entityContext = entityContext.setValue(CONTEXT_KEY_ALLOW_TRACE_CONTENT, overrideTraceContent);
|
|
42
|
+
}
|
|
43
|
+
// STEP 5: Add association properties for linking related spans
|
|
44
|
+
// These are custom key-value pairs that help correlate spans
|
|
45
|
+
if (associationProperties) {
|
|
46
|
+
entityContext = entityContext.setValue(ASSOCIATION_PROPERTIES_KEY, associationProperties);
|
|
47
|
+
}
|
|
48
|
+
// STEP 6: Handle tracing suppression
|
|
49
|
+
// This allows disabling tracing for specific operations
|
|
50
|
+
if (shouldSuppressTracing) {
|
|
51
|
+
entityContext = suppressTracing(entityContext);
|
|
52
|
+
}
|
|
53
|
+
// STEP 7: Execute the function within the trace context
|
|
54
|
+
// context.with() ensures all operations inside use the entityContext
|
|
55
|
+
return context.with(entityContext, () =>
|
|
56
|
+
// STEP 8: Create and start a new span
|
|
57
|
+
getTracer().startActiveSpan(`${name}.${type}`, // Span name format: "functionName.WORKFLOW"
|
|
58
|
+
{}, // Span options (empty for now)
|
|
59
|
+
entityContext, // The context to use for this span
|
|
60
|
+
(span) => {
|
|
61
|
+
// STEP 9: Set span attributes for metadata
|
|
62
|
+
// These attributes help identify and categorize the span
|
|
63
|
+
// Special handling for workflow/agent spans
|
|
64
|
+
if (type === TraceloopSpanKindValues.WORKFLOW ||
|
|
65
|
+
type === TraceloopSpanKindValues.AGENT) {
|
|
66
|
+
span.setAttribute(SpanAttributes.TRACELOOP_WORKFLOW_NAME, name);
|
|
67
|
+
}
|
|
68
|
+
// Standard attributes for all spans
|
|
69
|
+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_NAME, name);
|
|
70
|
+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_PATH, entityPath || "");
|
|
71
|
+
span.setAttribute(SpanAttributes.TRACELOOP_SPAN_KIND, type);
|
|
72
|
+
// Optional version information
|
|
73
|
+
if (version) {
|
|
74
|
+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_VERSION, version);
|
|
75
|
+
}
|
|
76
|
+
// Set processor routing if specified
|
|
77
|
+
if (processors) {
|
|
78
|
+
span.setAttribute("respan.processors", processors);
|
|
79
|
+
}
|
|
80
|
+
// STEP 10: Capture input parameters if tracing is enabled
|
|
81
|
+
if (shouldSendTraces()) {
|
|
82
|
+
try {
|
|
83
|
+
const input = inputParameters ?? args;
|
|
84
|
+
// Handle single object parameter (common pattern)
|
|
85
|
+
if (input.length === 1 &&
|
|
86
|
+
typeof input[0] === "object" &&
|
|
87
|
+
!(input[0] instanceof Map)) {
|
|
88
|
+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_INPUT, serialize({ args: [], kwargs: input[0] }));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Handle multiple parameters
|
|
92
|
+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_INPUT, serialize({
|
|
93
|
+
args: input,
|
|
94
|
+
kwargs: {},
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error("Error serializing input:", error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// STEP 11: Execute the wrapped function with error handling
|
|
103
|
+
try {
|
|
104
|
+
const res = fn.apply(thisArg, args);
|
|
105
|
+
// STEP 12: Handle async functions (Promises)
|
|
106
|
+
if (res instanceof Promise) {
|
|
107
|
+
return res
|
|
108
|
+
.then((resolvedRes) => {
|
|
109
|
+
// Capture successful async result
|
|
110
|
+
try {
|
|
111
|
+
if (shouldSendTraces()) {
|
|
112
|
+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, serialize(resolvedRes));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error("Error serializing output:", error);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
// Always end the span when async operation completes
|
|
120
|
+
span.end();
|
|
121
|
+
}
|
|
122
|
+
return resolvedRes;
|
|
123
|
+
})
|
|
124
|
+
.catch((error) => {
|
|
125
|
+
// Handle async errors
|
|
126
|
+
if (error instanceof Error) {
|
|
127
|
+
span.recordException(error);
|
|
128
|
+
span.setStatus({
|
|
129
|
+
code: SpanStatusCode.ERROR,
|
|
130
|
+
message: error.message,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
span.setStatus({
|
|
135
|
+
code: SpanStatusCode.ERROR,
|
|
136
|
+
message: String(error),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
span.end();
|
|
140
|
+
throw error; // Re-throw to maintain error propagation
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// STEP 13: Handle synchronous functions
|
|
144
|
+
try {
|
|
145
|
+
if (shouldSendTraces()) {
|
|
146
|
+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, serialize(res));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error("Error serializing output:", error);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
// End span for synchronous operations
|
|
154
|
+
span.end();
|
|
155
|
+
}
|
|
156
|
+
return res;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
// STEP 14: Handle synchronous errors
|
|
160
|
+
if (error instanceof Error) {
|
|
161
|
+
span.recordException(error);
|
|
162
|
+
span.setStatus({
|
|
163
|
+
code: SpanStatusCode.ERROR,
|
|
164
|
+
message: error.message,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
span.setStatus({
|
|
169
|
+
code: SpanStatusCode.ERROR,
|
|
170
|
+
message: String(error),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
span.end();
|
|
174
|
+
throw error; // Re-throw to maintain error propagation
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
export function withWorkflow(config, fn, ...args) {
|
|
179
|
+
return withEntity(TraceloopSpanKindValues.WORKFLOW, config, fn, undefined, ...args);
|
|
180
|
+
}
|
|
181
|
+
export function withTask(config, fn, ...args) {
|
|
182
|
+
return withEntity(TraceloopSpanKindValues.TASK, config, fn, undefined, ...args);
|
|
183
|
+
}
|
|
184
|
+
export function withAgent(config, fn, ...args) {
|
|
185
|
+
return withEntity(TraceloopSpanKindValues.AGENT, config, fn, undefined, ...args);
|
|
186
|
+
}
|
|
187
|
+
export function withTool(config, fn, ...args) {
|
|
188
|
+
return withEntity(TraceloopSpanKindValues.TOOL, config, fn, undefined, ...args);
|
|
189
|
+
}
|
|
190
|
+
function cleanInput(input) {
|
|
191
|
+
if (Array.isArray(input)) {
|
|
192
|
+
return input.map((value) => cleanInput(value));
|
|
193
|
+
}
|
|
194
|
+
else if (!input) {
|
|
195
|
+
return input;
|
|
196
|
+
}
|
|
197
|
+
else if (typeof input === "object" && input !== null) {
|
|
198
|
+
const cleaned = {};
|
|
199
|
+
for (const [key, value] of Object.entries(input)) {
|
|
200
|
+
cleaned[key] = cleanInput(value);
|
|
201
|
+
}
|
|
202
|
+
return cleaned;
|
|
203
|
+
}
|
|
204
|
+
return input;
|
|
205
|
+
}
|
|
206
|
+
function serialize(input) {
|
|
207
|
+
try {
|
|
208
|
+
return JSON.stringify(cleanInput(input));
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
return String(input);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function entity(type, config) {
|
|
215
|
+
return function (target, propertyKey, descriptor) {
|
|
216
|
+
const originalMethod = descriptor.value;
|
|
217
|
+
descriptor.value = function (...args) {
|
|
218
|
+
let actualConfig;
|
|
219
|
+
if (typeof config === "function") {
|
|
220
|
+
actualConfig = config(this, ...args);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
actualConfig = config;
|
|
224
|
+
}
|
|
225
|
+
const entityName = actualConfig.name ?? originalMethod.name;
|
|
226
|
+
return withEntity(type, { ...actualConfig, name: entityName }, originalMethod, this, ...args);
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export function workflow(config) {
|
|
231
|
+
return entity(TraceloopSpanKindValues.WORKFLOW, config ?? {});
|
|
232
|
+
}
|
|
233
|
+
export function task(config) {
|
|
234
|
+
return entity(TraceloopSpanKindValues.TASK, config ?? {});
|
|
235
|
+
}
|
|
236
|
+
export function agent(config) {
|
|
237
|
+
return entity(TraceloopSpanKindValues.AGENT, config ?? {});
|
|
238
|
+
}
|
|
239
|
+
export function tool(config) {
|
|
240
|
+
return entity(TraceloopSpanKindValues.TOOL, config ?? {});
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/decorators/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACd,uBAAuB,GACxB,MAAM,oCAAoC,CAAC;AAyB5C;;;;;;;;;;GAUG;AACH,SAAS,UAAU,CAIjB,IAA6B,EAC7B,EACE,IAAI,EACJ,OAAO,EACP,qBAAqB,EACrB,YAAY,EAAE,oBAAoB,EAClC,eAAe,EACf,eAAe,EAAE,qBAAqB,EACtC,UAAU,GACM,EAClB,EAAK,EACL,OAA8B,EAC9B,GAAG,IAAO;IAEV,sEAAsE;IACtE,yEAAyE;IACzE,IAAI,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CA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E,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,MAE4E;IAE5E,OAAO,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,KAAK,CACnB,MAE4E;IAE5E,OAAO,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,MAE4E;IAE5E,OAAO,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./base.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { RespanTelemetry } from "./main.js";
|
|
2
|
+
export * from "./decorators/index.js";
|
|
3
|
+
export * from "./contexts/index.js";
|
|
4
|
+
export * from "./types/index.js";
|
|
5
|
+
export * from "./utils/index.js";
|
|
6
|
+
export { getClient } from "./utils/client.js";
|
|
7
|
+
export type { RespanClient, UpdateSpanOptions } from "./utils/client.js";
|
|
8
|
+
export { getSpanBufferManager } from "./utils/spanBuffer.js";
|
|
9
|
+
export type { SpanBuffer } from "./utils/spanBuffer.js";
|
|
10
|
+
export type { ProcessorConfig } from "./types/clientTypes.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { RespanTelemetry } from "./main.js";
|
|
2
|
+
export * from "./decorators/index.js";
|
|
3
|
+
export * from "./contexts/index.js";
|
|
4
|
+
export * from "./types/index.js";
|
|
5
|
+
export * from "./utils/index.js";
|
|
6
|
+
export { getClient } from "./utils/client.js";
|
|
7
|
+
export { getSpanBufferManager } from "./utils/spanBuffer.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { INSTRUMENTATION_INFO } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Dynamic instrumentation loading with enhanced logging and installation hints
|
|
4
|
+
*/
|
|
5
|
+
export const loadInstrumentation = async (name) => {
|
|
6
|
+
console.debug(`[Respan Debug] Attempting to load instrumentation: ${name}`);
|
|
7
|
+
const info = INSTRUMENTATION_INFO[name];
|
|
8
|
+
if (!info) {
|
|
9
|
+
console.warn(`[Respan] Unknown instrumentation: ${name}`);
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
console.debug(`[Respan Debug] Loading ${info.description}...`);
|
|
14
|
+
switch (name) {
|
|
15
|
+
case "openAI":
|
|
16
|
+
const { OpenAIInstrumentation } = await import("@traceloop/instrumentation-openai");
|
|
17
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
18
|
+
return new OpenAIInstrumentation({
|
|
19
|
+
exceptionLogger: (e) => console.error("OpenAI instrumentation error:", e),
|
|
20
|
+
});
|
|
21
|
+
case "anthropic":
|
|
22
|
+
const { AnthropicInstrumentation } = await import("@traceloop/instrumentation-anthropic");
|
|
23
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
24
|
+
return new AnthropicInstrumentation({
|
|
25
|
+
exceptionLogger: (e) => console.error("Anthropic instrumentation error:", e),
|
|
26
|
+
});
|
|
27
|
+
case "azureOpenAI":
|
|
28
|
+
const { AzureOpenAIInstrumentation } = await import("@traceloop/instrumentation-azure");
|
|
29
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
30
|
+
return new AzureOpenAIInstrumentation({
|
|
31
|
+
exceptionLogger: (e) => console.error("Azure instrumentation error:", e),
|
|
32
|
+
});
|
|
33
|
+
case "bedrock":
|
|
34
|
+
const { BedrockInstrumentation } = await import("@traceloop/instrumentation-bedrock");
|
|
35
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
36
|
+
return new BedrockInstrumentation({
|
|
37
|
+
exceptionLogger: (e) => console.error("Bedrock instrumentation error:", e),
|
|
38
|
+
});
|
|
39
|
+
case "cohere":
|
|
40
|
+
const { CohereInstrumentation } = await import("@traceloop/instrumentation-cohere");
|
|
41
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
42
|
+
return new CohereInstrumentation({
|
|
43
|
+
exceptionLogger: (e) => console.error("Cohere instrumentation error:", e),
|
|
44
|
+
});
|
|
45
|
+
case "langChain":
|
|
46
|
+
const { LangChainInstrumentation } = await import("@traceloop/instrumentation-langchain");
|
|
47
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
48
|
+
return new LangChainInstrumentation({
|
|
49
|
+
exceptionLogger: (e) => console.error("LangChain instrumentation error:", e),
|
|
50
|
+
});
|
|
51
|
+
case "llamaIndex":
|
|
52
|
+
const { LlamaIndexInstrumentation } = await import("@traceloop/instrumentation-llamaindex");
|
|
53
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
54
|
+
return new LlamaIndexInstrumentation({
|
|
55
|
+
exceptionLogger: (e) => console.error("LlamaIndex instrumentation error:", e),
|
|
56
|
+
});
|
|
57
|
+
case "pinecone":
|
|
58
|
+
const { PineconeInstrumentation } = await import("@traceloop/instrumentation-pinecone");
|
|
59
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
60
|
+
return new PineconeInstrumentation({
|
|
61
|
+
exceptionLogger: (e) => console.error("Pinecone instrumentation error:", e),
|
|
62
|
+
});
|
|
63
|
+
case "chromaDB":
|
|
64
|
+
const { ChromaDBInstrumentation } = await import("@traceloop/instrumentation-chromadb");
|
|
65
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
66
|
+
return new ChromaDBInstrumentation({
|
|
67
|
+
exceptionLogger: (e) => console.error("ChromaDB instrumentation error:", e),
|
|
68
|
+
});
|
|
69
|
+
case "qdrant":
|
|
70
|
+
const { QdrantInstrumentation } = await import("@traceloop/instrumentation-qdrant");
|
|
71
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
72
|
+
return new QdrantInstrumentation({
|
|
73
|
+
exceptionLogger: (e) => console.error("Qdrant instrumentation error:", e),
|
|
74
|
+
});
|
|
75
|
+
case "together":
|
|
76
|
+
const { TogetherInstrumentation } = await import("@traceloop/instrumentation-together");
|
|
77
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
78
|
+
return new TogetherInstrumentation({
|
|
79
|
+
exceptionLogger: (e) => console.error("Together instrumentation error:", e),
|
|
80
|
+
});
|
|
81
|
+
case "googleVertexAI":
|
|
82
|
+
const { VertexAIInstrumentation } = await import("@traceloop/instrumentation-vertexai");
|
|
83
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
84
|
+
return new VertexAIInstrumentation({
|
|
85
|
+
exceptionLogger: (e) => console.error("VertexAI instrumentation error:", e),
|
|
86
|
+
});
|
|
87
|
+
case "googleAIPlatform":
|
|
88
|
+
const { AIPlatformInstrumentation } = await import("@traceloop/instrumentation-vertexai");
|
|
89
|
+
console.debug(`[Respan Debug] Successfully imported ${info.description}`);
|
|
90
|
+
return new AIPlatformInstrumentation({
|
|
91
|
+
exceptionLogger: (e) => console.error("AI Platform instrumentation error:", e),
|
|
92
|
+
});
|
|
93
|
+
default:
|
|
94
|
+
console.warn(`[Respan] Unknown instrumentation: ${name}`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.info(`[Respan] ${info.description} is not available. To enable it, install the required package:\n ${info.installCommand}`);
|
|
100
|
+
console.debug(`[Respan Debug] Failed to load ${name} instrumentation:`, error);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/instrumentation/loader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,IAAY,EACqB,EAAE;IACnC,OAAO,CAAC,KAAK,CACX,sDAAsD,IAAI,EAAE,CAC7D,CAAC;IAEF,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,IAAI,CAAC,qCAAqC,IAAI,EAAE,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,0BAA0B,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC;QAE/D,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,QAAQ;gBACX,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAC5C,mCAAmC,CACpC,CAAC;gBACF,OAAO,CAAC,KAAK,CACX,wCAAwC,IAAI,C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,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC;iBACtD,CAAC,CAAC;YAEL,KAAK,kBAAkB;gBACrB,MAAM,EAAE,yBAAyB,EAAE,GAAG,MAAM,MAAM,CAChD,qCAAqC,CACtC,CAAC;gBACF,OAAO,CAAC,KAAK,CACX,wCAAwC,IAAI,CAAC,WAAW,EAAE,CAC3D,CAAC;gBACF,OAAO,IAAI,yBAAyB,CAAC;oBACnC,eAAe,EAAE,CAAC,CAAQ,EAAE,EAAE,CAC5B,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,CAAC,CAAC;iBACzD,CAAC,CAAC;YAEL;gBACE,OAAO,CAAC,IAAI,CAAC,qCAAqC,IAAI,EAAE,CAAC,CAAC;gBAC1D,OAAO,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CACV,YAAY,IAAI,CAAC,WAAW,sEAAsE,IAAI,CAAC,cAAc,EAAE,CACxH,CAAC;QACF,OAAO,CAAC,KAAK,CACX,iCAAiC,IAAI,mBAAmB,EACxD,KAAK,CACN,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Instrumentation } from "@opentelemetry/instrumentation";
|
|
2
|
+
import { InstrumentationName, RespanOptions } from "../types/clientTypes.js";
|
|
3
|
+
/**
|
|
4
|
+
* Get all loaded instrumentations
|
|
5
|
+
*/
|
|
6
|
+
export declare const getInstrumentations: () => Instrumentation[];
|
|
7
|
+
/**
|
|
8
|
+
* Get a specific instrumentation instance by name
|
|
9
|
+
*/
|
|
10
|
+
export declare const getInstrumentationInstance: (name: InstrumentationName) => any;
|
|
11
|
+
/**
|
|
12
|
+
* Configure trace content for instrumentations
|
|
13
|
+
*/
|
|
14
|
+
export declare const configureTraceContent: (enabled: boolean) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize all available instrumentations automatically.
|
|
17
|
+
* This is used when no specific instrumentModules are provided.
|
|
18
|
+
*/
|
|
19
|
+
export declare const initInstrumentations: (disabledInstrumentations?: InstrumentationName[], showInstallWarnings?: boolean) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Manually initialize instrumentations with provided modules.
|
|
22
|
+
* This is similar to Traceloop's approach for environments like Next.js
|
|
23
|
+
* where dynamic imports might not work properly.
|
|
24
|
+
*/
|
|
25
|
+
export declare const manuallyInitInstrumentations: (instrumentModules: NonNullable<RespanOptions["instrumentModules"]>, disabledInstrumentations?: InstrumentationName[]) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Add an instrumentation to the collection
|
|
28
|
+
*/
|
|
29
|
+
export declare const enableInstrumentation: (name: string) => Promise<void>;
|