File tree 2 files changed +29
-3
lines changed
packages/traceloop-sdk/src/lib
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 1
- import { SpanExporter } from "@opentelemetry/sdk-trace-base" ;
2
-
1
+ import { SpanExporter , SpanProcessor } from "@opentelemetry/sdk-trace-base" ;
2
+ import { TextMapPropagator , ContextManager } from "@opentelemetry/api" ;
3
3
import type * as openai from "openai" ;
4
4
import type * as anthropic from "@anthropic-ai/sdk" ;
5
5
import type * as azure from "@azure/openai" ;
@@ -67,6 +67,24 @@ export interface InitializeOptions {
67
67
*/
68
68
exporter ?: SpanExporter ;
69
69
70
+ /**
71
+ * The OpenTelemetry SpanProcessor to be used for processing traces data. Optional.
72
+ * Defaults to the BatchSpanProcessor.
73
+ */
74
+ processor ?: SpanProcessor ;
75
+
76
+ /**
77
+ * The OpenTelemetry Propagator to use. Optional.
78
+ * Defaults to OpenTelemetry SDK defaults.
79
+ */
80
+ propagator ?: TextMapPropagator ;
81
+
82
+ /**
83
+ * The OpenTelemetry ContextManager to use. Optional.
84
+ * Defaults to OpenTelemetry SDK defaults.
85
+ */
86
+ contextManager ?: ContextManager ;
87
+
70
88
/**
71
89
* Explicitly specify modules to instrument. Optional.
72
90
* This is a workaround specific to Next.js, see https://www.traceloop.com/docs/openllmetry/getting-started-nextjs
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { NodeSDK } from "@opentelemetry/sdk-node";
3
3
import {
4
4
SimpleSpanProcessor ,
5
5
BatchSpanProcessor ,
6
+ SpanProcessor ,
6
7
} from "@opentelemetry/sdk-trace-node" ;
7
8
import { Span , context , diag } from "@opentelemetry/api" ;
8
9
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto" ;
@@ -281,12 +282,19 @@ export const startTracing = (options: InitializeOptions) => {
281
282
} ) ;
282
283
}
283
284
285
+ const spanProcessors : SpanProcessor [ ] = [ _spanProcessor ] ;
286
+ if ( options . processor ) {
287
+ spanProcessors . push ( options . processor ) ;
288
+ }
289
+
284
290
_sdk = new NodeSDK ( {
285
291
resource : new Resource ( {
286
292
[ SEMRESATTRS_SERVICE_NAME ] :
287
293
options . appName || process . env . npm_package_name ,
288
294
} ) ,
289
- spanProcessors : [ _spanProcessor ] ,
295
+ spanProcessors,
296
+ contextManager : options . contextManager ,
297
+ textMapPropagator : options . propagator ,
290
298
traceExporter,
291
299
instrumentations,
292
300
// We should re-consider removing unrelevant spans here in the future
You can’t perform that action at this time.
0 commit comments