Skip to content
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
19 changes: 10 additions & 9 deletions packages/sample-app/src/sample_otel_sdk.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { NodeSDK } from "@opentelemetry/sdk-node";
import { Resource } from "@opentelemetry/resources";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
import {
createSpanProcessor,
withTask,
withWorkflow,
} from "@traceloop/node-server-sdk";
import * as traceloop from "@traceloop/node-server-sdk";
import { trace } from "@opentelemetry/api";
import OpenAI from "openai";

const traceloopSpanProcessor = createSpanProcessor({
traceloop.initialize({
tracingEnabled: false,
traceloopSyncEnabled: false,
});

const traceloopSpanProcessor = traceloop.createSpanProcessor({
apiKey: process.env.TRACELOOP_API_KEY,
baseUrl: process.env.TRACELOOP_BASE_URL,
disableBatch: true,
Expand Down Expand Up @@ -45,9 +46,9 @@ async function main() {
}

async function chat() {
return await withWorkflow({ name: "sample_chat" }, async () => {
return await withTask({ name: "parent_task" }, async () => {
return await withTask({ name: "child_task" }, async () => {
return await traceloop.withWorkflow({ name: "sample_chat" }, async () => {
return await traceloop.withTask({ name: "parent_task" }, async () => {
return await traceloop.withTask({ name: "child_task" }, async () => {
const chatCompletion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Tell me a joke about OpenTelemetry" },
Expand Down
5 changes: 4 additions & 1 deletion packages/traceloop-sdk/src/lib/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ export const initialize = (options: InitializeOptions) => {
);
}

startTracing(_configuration);
if (options.tracingEnabled === undefined || options.tracingEnabled) {
startTracing(_configuration);
}

initializeRegistry(_configuration);
if (options.apiKey) {
_client = new TraceloopClient({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ export interface InitializeOptions {
* Defaults to false.
*/
silenceInitializationMessage?: boolean;

/**
* Whether to enable tracing. Optional.
* Defaults to true.
*/
tracingEnabled?: boolean;
}