Skip to content

Commit 1fa682e

Browse files
authored
fix(tracing): introduce tracingEnabled option to support sdk initialization for standalone processor (#599)
1 parent 81a2c43 commit 1fa682e

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

packages/sample-app/src/sample_otel_sdk.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { NodeSDK } from "@opentelemetry/sdk-node";
22
import { Resource } from "@opentelemetry/resources";
33
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
4-
import {
5-
createSpanProcessor,
6-
withTask,
7-
withWorkflow,
8-
} from "@traceloop/node-server-sdk";
4+
import * as traceloop from "@traceloop/node-server-sdk";
95
import { trace } from "@opentelemetry/api";
106
import OpenAI from "openai";
117

12-
const traceloopSpanProcessor = createSpanProcessor({
8+
traceloop.initialize({
9+
tracingEnabled: false,
10+
traceloopSyncEnabled: false,
11+
});
12+
13+
const traceloopSpanProcessor = traceloop.createSpanProcessor({
1314
apiKey: process.env.TRACELOOP_API_KEY,
1415
baseUrl: process.env.TRACELOOP_BASE_URL,
1516
disableBatch: true,
@@ -45,9 +46,9 @@ async function main() {
4546
}
4647

4748
async function chat() {
48-
return await withWorkflow({ name: "sample_chat" }, async () => {
49-
return await withTask({ name: "parent_task" }, async () => {
50-
return await withTask({ name: "child_task" }, async () => {
49+
return await traceloop.withWorkflow({ name: "sample_chat" }, async () => {
50+
return await traceloop.withTask({ name: "parent_task" }, async () => {
51+
return await traceloop.withTask({ name: "child_task" }, async () => {
5152
const chatCompletion = await openai.chat.completions.create({
5253
messages: [
5354
{ role: "user", content: "Tell me a joke about OpenTelemetry" },

packages/traceloop-sdk/src/lib/configuration/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ export const initialize = (options: InitializeOptions) => {
8686
);
8787
}
8888

89-
startTracing(_configuration);
89+
if (options.tracingEnabled === undefined || options.tracingEnabled) {
90+
startTracing(_configuration);
91+
}
92+
9093
initializeRegistry(_configuration);
9194
if (options.apiKey) {
9295
_client = new TraceloopClient({

packages/traceloop-sdk/src/lib/interfaces/initialize-options.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,10 @@ export interface InitializeOptions {
142142
* Defaults to false.
143143
*/
144144
silenceInitializationMessage?: boolean;
145+
146+
/**
147+
* Whether to enable tracing. Optional.
148+
* Defaults to true.
149+
*/
150+
tracingEnabled?: boolean;
145151
}

0 commit comments

Comments
 (0)