@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,168 @@
|
|
|
1
|
+
import { SpanStatusCode, Tracer } from "@opentelemetry/api";
|
|
2
|
+
/**
|
|
3
|
+
* Options for updating a span
|
|
4
|
+
*/
|
|
5
|
+
export interface UpdateSpanOptions {
|
|
6
|
+
/** New name for the span */
|
|
7
|
+
name?: string;
|
|
8
|
+
/** Custom attributes to add to the span */
|
|
9
|
+
attributes?: Record<string, any>;
|
|
10
|
+
/** Status to set on the span */
|
|
11
|
+
status?: {
|
|
12
|
+
code: SpanStatusCode;
|
|
13
|
+
message?: string;
|
|
14
|
+
};
|
|
15
|
+
/** Respan-specific parameters */
|
|
16
|
+
respanParams?: {
|
|
17
|
+
/** Customer identifier for grouping traces by user */
|
|
18
|
+
customerIdentifier?: string;
|
|
19
|
+
/** Trace group identifier for organizing traces */
|
|
20
|
+
traceGroupIdentifier?: string;
|
|
21
|
+
/** Additional metadata */
|
|
22
|
+
metadata?: Record<string, any>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Respan client interface for span management and tracing operations.
|
|
27
|
+
*
|
|
28
|
+
* This client provides methods to:
|
|
29
|
+
* - Get current trace and span IDs
|
|
30
|
+
* - Update span attributes and Respan parameters
|
|
31
|
+
* - Add events and record exceptions
|
|
32
|
+
* - Create manual spans
|
|
33
|
+
* - Control span buffering
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { getClient } from '@respan/tracing';
|
|
38
|
+
*
|
|
39
|
+
* const client = getClient();
|
|
40
|
+
* const traceId = client.getCurrentTraceId();
|
|
41
|
+
*
|
|
42
|
+
* client.updateCurrentSpan({
|
|
43
|
+
* respanParams: {
|
|
44
|
+
* customerIdentifier: 'user-123',
|
|
45
|
+
* traceGroupIdentifier: 'experiment-456'
|
|
46
|
+
* }
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export interface RespanClient {
|
|
51
|
+
/**
|
|
52
|
+
* Get the current trace ID
|
|
53
|
+
* @returns The current trace ID or undefined if no active span
|
|
54
|
+
*/
|
|
55
|
+
getCurrentTraceId(): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Get the current span ID
|
|
58
|
+
* @returns The current span ID or undefined if no active span
|
|
59
|
+
*/
|
|
60
|
+
getCurrentSpanId(): string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Get the OpenTelemetry tracer for manual span creation
|
|
63
|
+
* @returns The tracer instance
|
|
64
|
+
*/
|
|
65
|
+
getTracer(): Tracer;
|
|
66
|
+
/**
|
|
67
|
+
* Update the current span with new attributes, name, status, or Respan parameters
|
|
68
|
+
* @param options - Options for updating the span
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* client.updateCurrentSpan({
|
|
73
|
+
* name: 'updated_name',
|
|
74
|
+
* attributes: { 'custom.field': 'value' },
|
|
75
|
+
* respanParams: {
|
|
76
|
+
* customerIdentifier: 'user-123',
|
|
77
|
+
* traceGroupIdentifier: 'experiment-456',
|
|
78
|
+
* metadata: { version: '1.0' }
|
|
79
|
+
* }
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
updateCurrentSpan(options: UpdateSpanOptions): void;
|
|
84
|
+
/**
|
|
85
|
+
* Add an event to the current span
|
|
86
|
+
* @param name - Event name
|
|
87
|
+
* @param attributes - Optional event attributes
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* client.addEvent('validation_started', { record_count: 100 });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
95
|
+
/**
|
|
96
|
+
* Record an exception on the current span
|
|
97
|
+
* @param exception - The exception to record
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* try {
|
|
102
|
+
* // ... some code
|
|
103
|
+
* } catch (error) {
|
|
104
|
+
* client.recordException(error as Error);
|
|
105
|
+
* throw error;
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
recordException(exception: Error): void;
|
|
110
|
+
/**
|
|
111
|
+
* Check if the current span is recording
|
|
112
|
+
* @returns True if the span is recording, false otherwise
|
|
113
|
+
*/
|
|
114
|
+
isRecording(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Force flush all pending spans
|
|
117
|
+
* @returns Promise that resolves when flush is complete
|
|
118
|
+
*/
|
|
119
|
+
flush(): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get the Respan client instance for span management.
|
|
123
|
+
*
|
|
124
|
+
* This function returns a singleton client that provides methods to:
|
|
125
|
+
* - Get current trace and span IDs
|
|
126
|
+
* - Update spans with custom attributes and Respan parameters
|
|
127
|
+
* - Add events and record exceptions
|
|
128
|
+
* - Access the tracer for manual span creation
|
|
129
|
+
*
|
|
130
|
+
* @returns The Respan client instance
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* import { getClient } from '@respan/tracing';
|
|
135
|
+
*
|
|
136
|
+
* const client = getClient();
|
|
137
|
+
*
|
|
138
|
+
* // Get current trace information
|
|
139
|
+
* const traceId = client.getCurrentTraceId();
|
|
140
|
+
* const spanId = client.getCurrentSpanId();
|
|
141
|
+
*
|
|
142
|
+
* // Update span with Respan parameters
|
|
143
|
+
* client.updateCurrentSpan({
|
|
144
|
+
* respanParams: {
|
|
145
|
+
* customerIdentifier: 'user-123',
|
|
146
|
+
* traceGroupIdentifier: 'data-processing-pipeline',
|
|
147
|
+
* metadata: {
|
|
148
|
+
* version: '1.0',
|
|
149
|
+
* environment: 'production'
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* // Add event to track progress
|
|
155
|
+
* client.addEvent('validation_started', {
|
|
156
|
+
* record_count: 100
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* // Record exception
|
|
160
|
+
* try {
|
|
161
|
+
* // ... some code
|
|
162
|
+
* } catch (error) {
|
|
163
|
+
* client.recordException(error as Error);
|
|
164
|
+
* throw error;
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function getClient(): RespanClient;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { trace, SpanStatusCode } from "@opentelemetry/api";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of the Respan client
|
|
4
|
+
*/
|
|
5
|
+
class RespanClientImpl {
|
|
6
|
+
tracerName = "@respan/tracing";
|
|
7
|
+
getCurrentTraceId() {
|
|
8
|
+
const currentSpan = trace.getActiveSpan();
|
|
9
|
+
if (!currentSpan) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const spanContext = currentSpan.spanContext();
|
|
13
|
+
return spanContext.traceId;
|
|
14
|
+
}
|
|
15
|
+
getCurrentSpanId() {
|
|
16
|
+
const currentSpan = trace.getActiveSpan();
|
|
17
|
+
if (!currentSpan) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const spanContext = currentSpan.spanContext();
|
|
21
|
+
return spanContext.spanId;
|
|
22
|
+
}
|
|
23
|
+
getTracer() {
|
|
24
|
+
return trace.getTracer(this.tracerName);
|
|
25
|
+
}
|
|
26
|
+
updateCurrentSpan(options) {
|
|
27
|
+
const currentSpan = trace.getActiveSpan();
|
|
28
|
+
if (!currentSpan) {
|
|
29
|
+
console.warn("[Respan] No active span to update");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Update span name
|
|
33
|
+
if (options.name) {
|
|
34
|
+
currentSpan.updateName(options.name);
|
|
35
|
+
}
|
|
36
|
+
// Update attributes
|
|
37
|
+
if (options.attributes) {
|
|
38
|
+
for (const [key, value] of Object.entries(options.attributes)) {
|
|
39
|
+
currentSpan.setAttribute(key, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Update status
|
|
43
|
+
if (options.status) {
|
|
44
|
+
currentSpan.setStatus(options.status);
|
|
45
|
+
}
|
|
46
|
+
// Update Respan-specific parameters
|
|
47
|
+
if (options.respanParams) {
|
|
48
|
+
const { customerIdentifier, traceGroupIdentifier, metadata } = options.respanParams;
|
|
49
|
+
if (customerIdentifier) {
|
|
50
|
+
currentSpan.setAttribute("respan.customer_identifier", customerIdentifier);
|
|
51
|
+
}
|
|
52
|
+
if (traceGroupIdentifier) {
|
|
53
|
+
currentSpan.setAttribute("respan.trace_group_identifier", traceGroupIdentifier);
|
|
54
|
+
}
|
|
55
|
+
if (metadata) {
|
|
56
|
+
// Flatten metadata into attributes with respan.metadata prefix
|
|
57
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
58
|
+
currentSpan.setAttribute(`respan.metadata.${key}`, value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
addEvent(name, attributes) {
|
|
64
|
+
const currentSpan = trace.getActiveSpan();
|
|
65
|
+
if (!currentSpan) {
|
|
66
|
+
console.warn("[Respan] No active span to add event to");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
currentSpan.addEvent(name, attributes);
|
|
70
|
+
}
|
|
71
|
+
recordException(exception) {
|
|
72
|
+
const currentSpan = trace.getActiveSpan();
|
|
73
|
+
if (!currentSpan) {
|
|
74
|
+
console.warn("[Respan] No active span to record exception on");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
currentSpan.recordException(exception);
|
|
78
|
+
currentSpan.setStatus({
|
|
79
|
+
code: SpanStatusCode.ERROR,
|
|
80
|
+
message: exception.message,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
isRecording() {
|
|
84
|
+
const currentSpan = trace.getActiveSpan();
|
|
85
|
+
if (!currentSpan) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return currentSpan.isRecording();
|
|
89
|
+
}
|
|
90
|
+
async flush() {
|
|
91
|
+
// Import forceFlush from tracing utils
|
|
92
|
+
const { forceFlush } = await import("./tracing.js");
|
|
93
|
+
await forceFlush();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Singleton instance
|
|
97
|
+
let _clientInstance;
|
|
98
|
+
/**
|
|
99
|
+
* Get the Respan client instance for span management.
|
|
100
|
+
*
|
|
101
|
+
* This function returns a singleton client that provides methods to:
|
|
102
|
+
* - Get current trace and span IDs
|
|
103
|
+
* - Update spans with custom attributes and Respan parameters
|
|
104
|
+
* - Add events and record exceptions
|
|
105
|
+
* - Access the tracer for manual span creation
|
|
106
|
+
*
|
|
107
|
+
* @returns The Respan client instance
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { getClient } from '@respan/tracing';
|
|
112
|
+
*
|
|
113
|
+
* const client = getClient();
|
|
114
|
+
*
|
|
115
|
+
* // Get current trace information
|
|
116
|
+
* const traceId = client.getCurrentTraceId();
|
|
117
|
+
* const spanId = client.getCurrentSpanId();
|
|
118
|
+
*
|
|
119
|
+
* // Update span with Respan parameters
|
|
120
|
+
* client.updateCurrentSpan({
|
|
121
|
+
* respanParams: {
|
|
122
|
+
* customerIdentifier: 'user-123',
|
|
123
|
+
* traceGroupIdentifier: 'data-processing-pipeline',
|
|
124
|
+
* metadata: {
|
|
125
|
+
* version: '1.0',
|
|
126
|
+
* environment: 'production'
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* // Add event to track progress
|
|
132
|
+
* client.addEvent('validation_started', {
|
|
133
|
+
* record_count: 100
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // Record exception
|
|
137
|
+
* try {
|
|
138
|
+
* // ... some code
|
|
139
|
+
* } catch (error) {
|
|
140
|
+
* client.recordException(error as Error);
|
|
141
|
+
* throw error;
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export function getClient() {
|
|
146
|
+
if (!_clientInstance) {
|
|
147
|
+
_clientInstance = new RespanClientImpl();
|
|
148
|
+
}
|
|
149
|
+
return _clientInstance;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAW,cAAc,EAAU,MAAM,oBAAoB,CAAC;AAmI5E;;GAEG;AACH,MAAM,gBAAgB;IACH,UAAU,GAAG,iBAAiB,CAAC;IAEhD,iBAAiB;QACf,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;QAC1C,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C3B,CAAC,CAAC;IACL,CAAC;IAED,WAAW;QACT,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;QAC1C,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,uCAAuC;QACvC,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;QACpD,MAAM,UAAU,EAAE,CAAC;IACrB,CAAC;CACF;AAED,qBAAqB;AACrB,IAAI,eAAyC,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,eAAe,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAC3C,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Context } from "@opentelemetry/api";
|
|
2
|
+
/**
|
|
3
|
+
* Context Keys: Type-safe identifiers for storing values in OpenTelemetry context
|
|
4
|
+
*
|
|
5
|
+
* Why context keys are needed:
|
|
6
|
+
* 1. Type safety - prevents runtime errors from typos in key names
|
|
7
|
+
* 2. Namespace isolation - prevents key collisions between different libraries
|
|
8
|
+
* 3. Hierarchical data flow - allows parent spans to pass data to child spans
|
|
9
|
+
* 4. Cross-cutting concerns - enables data to flow across async boundaries
|
|
10
|
+
*/
|
|
11
|
+
export declare const WORKFLOW_NAME_KEY: symbol;
|
|
12
|
+
export declare const ENTITY_NAME_KEY: symbol;
|
|
13
|
+
export declare const ASSOCIATION_PROPERTIES_KEY: symbol;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the current entity path from the active context.
|
|
16
|
+
* This builds the hierarchical path like "workflow.task.subtask".
|
|
17
|
+
*
|
|
18
|
+
* @param ctx - The context to read from (defaults to current active context)
|
|
19
|
+
* @returns The entity path string or undefined if not set
|
|
20
|
+
*/
|
|
21
|
+
export declare const getEntityPath: (ctx?: Context) => string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Determines whether trace content (input/output data) should be captured.
|
|
24
|
+
* This can be controlled via environment variable for security/privacy.
|
|
25
|
+
*
|
|
26
|
+
* @returns true if traces should include content, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
export declare const shouldSendTraces: () => boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { context, createContextKey } from "@opentelemetry/api";
|
|
2
|
+
import { SpanAttributes } from "@traceloop/ai-semantic-conventions";
|
|
3
|
+
/**
|
|
4
|
+
* Context Keys: Type-safe identifiers for storing values in OpenTelemetry context
|
|
5
|
+
*
|
|
6
|
+
* Why context keys are needed:
|
|
7
|
+
* 1. Type safety - prevents runtime errors from typos in key names
|
|
8
|
+
* 2. Namespace isolation - prevents key collisions between different libraries
|
|
9
|
+
* 3. Hierarchical data flow - allows parent spans to pass data to child spans
|
|
10
|
+
* 4. Cross-cutting concerns - enables data to flow across async boundaries
|
|
11
|
+
*/
|
|
12
|
+
// Stores the name of the current workflow (top-level operation)
|
|
13
|
+
export const WORKFLOW_NAME_KEY = createContextKey(SpanAttributes.TRACELOOP_WORKFLOW_NAME);
|
|
14
|
+
// Stores the hierarchical path of the current entity (e.g., "workflow.task.subtask")
|
|
15
|
+
export const ENTITY_NAME_KEY = createContextKey(SpanAttributes.TRACELOOP_ENTITY_NAME);
|
|
16
|
+
// Stores custom properties for associating related spans
|
|
17
|
+
export const ASSOCIATION_PROPERTIES_KEY = createContextKey(SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES);
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the current entity path from the active context.
|
|
20
|
+
* This builds the hierarchical path like "workflow.task.subtask".
|
|
21
|
+
*
|
|
22
|
+
* @param ctx - The context to read from (defaults to current active context)
|
|
23
|
+
* @returns The entity path string or undefined if not set
|
|
24
|
+
*/
|
|
25
|
+
export const getEntityPath = (ctx = context.active()) => {
|
|
26
|
+
// First check for full entity name (set by TOOL/TASK spans)
|
|
27
|
+
const entityName = ctx.getValue(ENTITY_NAME_KEY);
|
|
28
|
+
if (entityName) {
|
|
29
|
+
return entityName;
|
|
30
|
+
}
|
|
31
|
+
// Fall back to workflow name (set by WORKFLOW/AGENT spans)
|
|
32
|
+
const workflowName = ctx.getValue(WORKFLOW_NAME_KEY);
|
|
33
|
+
return workflowName;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Determines whether trace content (input/output data) should be captured.
|
|
37
|
+
* This can be controlled via environment variable for security/privacy.
|
|
38
|
+
*
|
|
39
|
+
* @returns true if traces should include content, false otherwise
|
|
40
|
+
*/
|
|
41
|
+
export const shouldSendTraces = () => {
|
|
42
|
+
return process.env.RESPAN_TRACE_CONTENT !== "false";
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAW,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE;;;;;;;;GAQG;AAEH,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAC/C,cAAc,CAAC,uBAAuB,CACvC,CAAC;AAEF,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB,CAC7C,cAAc,CAAC,qBAAqB,CACrC,CAAC;AAEF,yDAAyD;AACzD,MAAM,CAAC,MAAM,0BAA0B,GAAG,gBAAgB,CACxD,cAAc,CAAC,gCAAgC,CAChD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,EAAsB,EAAE;IAC1E,4DAA4D;IAC5D,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAuB,CAAC;IACvE,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,2DAA2D;IAC3D,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAuB,CAAC;IAC3E,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAY,EAAE;IAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,OAAO,CAAC;AACtD,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./context.js";
|
|
2
|
+
export * from "./span.js";
|
|
3
|
+
// Export tracing utils but avoid naming conflicts
|
|
4
|
+
export { startTracing, forceFlush, _resolveBaseURL } from "./tracing.js";
|
|
5
|
+
// Export client and span buffer
|
|
6
|
+
export * from "./client.js";
|
|
7
|
+
export * from "./spanBuffer.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAE1B,kDAAkD;AAClD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEzE,gCAAgC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Tracer, Span, SpanStatusCode } from "@opentelemetry/api";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the singleton tracer instance.
|
|
4
|
+
* The tracer is responsible for creating and managing spans.
|
|
5
|
+
*
|
|
6
|
+
* @returns The global tracer instance
|
|
7
|
+
*/
|
|
8
|
+
export declare const getTracer: () => Tracer;
|
|
9
|
+
/**
|
|
10
|
+
* Gets the currently active span from the context.
|
|
11
|
+
* This is the span that's currently being executed.
|
|
12
|
+
*
|
|
13
|
+
* @returns The active span or undefined if no span is active
|
|
14
|
+
*/
|
|
15
|
+
export declare const getCurrentSpan: () => Span | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Update the current active span with new information.
|
|
18
|
+
* This is the JavaScript equivalent of the Python update_current_span method.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Configuration object for updating the span
|
|
21
|
+
* @returns True if the span was updated successfully, False otherwise
|
|
22
|
+
*/
|
|
23
|
+
export declare const updateCurrentSpan: (options?: {
|
|
24
|
+
respanParams?: Record<string, any>;
|
|
25
|
+
attributes?: Record<string, string | number | boolean>;
|
|
26
|
+
status?: SpanStatusCode;
|
|
27
|
+
statusDescription?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
}) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Adds an event to the currently active span.
|
|
32
|
+
* Events are timestamped messages that provide additional context.
|
|
33
|
+
*
|
|
34
|
+
* @param name - Name of the event
|
|
35
|
+
* @param attributes - Optional attributes for the event
|
|
36
|
+
* @returns true if event was added, false if no active span
|
|
37
|
+
*/
|
|
38
|
+
export declare const addSpanEvent: (name: string, attributes?: Record<string, string | number | boolean>) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Records an exception in the currently active span.
|
|
41
|
+
* This is useful for capturing errors that don't necessarily end the span.
|
|
42
|
+
*
|
|
43
|
+
* @param exception - The error/exception to record
|
|
44
|
+
* @returns true if exception was recorded, false if no active span
|
|
45
|
+
*/
|
|
46
|
+
export declare const recordSpanException: (exception: Error) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Sets the status of the currently active span.
|
|
49
|
+
* This indicates whether the operation succeeded or failed.
|
|
50
|
+
*
|
|
51
|
+
* @param status - The status to set (OK or ERROR)
|
|
52
|
+
* @param message - Optional message describing the status
|
|
53
|
+
* @returns true if status was set, false if no active span
|
|
54
|
+
*/
|
|
55
|
+
export declare const setSpanStatus: (status: "OK" | "ERROR", message?: string) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a manual span for custom tracing.
|
|
58
|
+
* This is useful when you need to trace operations that aren't wrapped by withEntity.
|
|
59
|
+
*
|
|
60
|
+
* @param name - Name of the span
|
|
61
|
+
* @param fn - Function to execute within the span
|
|
62
|
+
* @param attributes - Optional attributes for the span
|
|
63
|
+
* @returns The result of the function
|
|
64
|
+
*/
|
|
65
|
+
export declare const withManualSpan: <T>(name: string, fn: (span: import("@opentelemetry/api").Span) => T, attributes?: Record<string, string | number | boolean>) => T;
|