Skip to content

fix(sdk): support parameters needed by Sentry SDK #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading