Skip to content

Commit

Permalink
fix(sdk): support parameters needed by Sentry SDK (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirga authored Jul 10, 2024
1 parent a5ee50c commit b1f195c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SpanExporter } from "@opentelemetry/sdk-trace-base";

import { SpanExporter, SpanProcessor } from "@opentelemetry/sdk-trace-base";
import { TextMapPropagator, ContextManager } from "@opentelemetry/api";
import type * as openai from "openai";
import type * as anthropic from "@anthropic-ai/sdk";
import type * as azure from "@azure/openai";
Expand Down Expand Up @@ -67,6 +67,24 @@ export interface InitializeOptions {
*/
exporter?: SpanExporter;

/**
* The OpenTelemetry SpanProcessor to be used for processing traces data. Optional.
* Defaults to the BatchSpanProcessor.
*/
processor?: SpanProcessor;

/**
* The OpenTelemetry Propagator to use. Optional.
* Defaults to OpenTelemetry SDK defaults.
*/
propagator?: TextMapPropagator;

/**
* The OpenTelemetry ContextManager to use. Optional.
* Defaults to OpenTelemetry SDK defaults.
*/
contextManager?: ContextManager;

/**
* Explicitly specify modules to instrument. Optional.
* This is a workaround specific to Next.js, see https://www.traceloop.com/docs/openllmetry/getting-started-nextjs
Expand Down
10 changes: 9 additions & 1 deletion packages/traceloop-sdk/src/lib/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NodeSDK } from "@opentelemetry/sdk-node";
import {
SimpleSpanProcessor,
BatchSpanProcessor,
SpanProcessor,
} from "@opentelemetry/sdk-trace-node";
import { Span, context, diag } from "@opentelemetry/api";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
Expand Down Expand Up @@ -281,12 +282,19 @@ export const startTracing = (options: InitializeOptions) => {
});
}

const spanProcessors: SpanProcessor[] = [_spanProcessor];
if (options.processor) {
spanProcessors.push(options.processor);
}

_sdk = new NodeSDK({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]:
options.appName || process.env.npm_package_name,
}),
spanProcessors: [_spanProcessor],
spanProcessors,
contextManager: options.contextManager,
textMapPropagator: options.propagator,
traceExporter,
instrumentations,
// We should re-consider removing unrelevant spans here in the future
Expand Down

0 comments on commit b1f195c

Please sign in to comment.