Skip to content

Conversation

@dbrian57
Copy link
Contributor

Description

This PR adds the equivalent TypeScript examples to the OTEL integration doc.

@github-actions
Copy link
Contributor

📚 Mintlify Preview Links

🔗 View Full Preview

📝 Changed (1 total)

📄 Pages (1)

File Preview
weave/guides/tracking/otel.mdx Otel

🤖 Generated automatically when Mintlify deployment succeeds
📍 Deployment: b492f72 at 2026-01-14 20:31:18 UTC

Copy link

@zbirenbaum zbirenbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lower examples look good, but I think the instrumented examples can be improved a bit.

I think you can do something like this to perform a lot of the work in one step (I haven't verified but google thinks so).

Also, soon we will use ResourceAttributes for handling project and entity, alongside any other wandb specific attributes like wb_run_id so the below code is even more applicable.

// instrumentation.ts
import { NodeSDK } from "@opentelemetry/sdk-trace-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
import { Resource } from "@opentelemetry/resources";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";

const sdk = new NodeSDK({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: "my-llm-app",
  }),
  traceExporter: new OTLPTraceExporter({
    // Default to http://localhost:4318/v1/traces use weave url here
  }),
  instrumentations: [new OpenAIInstrumentation()],
});

sdk.start();

const provider = new NodeTracerProvider({
spanProcessors: [
new BatchSpanProcessor(exporter),
new BatchSpanProcessor(new ConsoleSpanExporter()),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe comment this line and put a note that says 'If you want to print to console as well'.

This isn't strictly required to export to weave and might mess up the user's existing logs.

// Manually instrument OpenAI since we're using ESM
openAIInstrumentation.manuallyInstrument(OpenAI);

console.log("Instrumentation registered. Is patched?", isPatched());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do this sort of logging in the python example I don't think

Comment on lines +195 to +203
console.log("OpenAI is patched?", isPatched());

// Create a manual span to verify pipeline works
const tracer = trace.getTracer("test-tracer");
const manualSpan = tracer.startSpan("manual-test-span");
manualSpan.setAttribute("test", "manual span works");
manualSpan.end();
console.log("Manual span created");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this should be required if you are using Arize. The logs are also probably not necessary

Comment on lines +219 to +226

// Give spans time to flush
console.log("Waiting 2 seconds for spans to flush...");
await new Promise(resolve => setTimeout(resolve, 2000));

await provider.shutdown(); // flush all pending spans before exit
console.log("Shutdown complete");
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't await outside an async function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants