Advanced LangSmith features including OpenTelemetry integration, data anonymization, and annotation queues for human-in-the-loop workflows.
LangSmith provides three advanced features for specialized use cases:
Enables standards-based distributed tracing using OpenTelemetry instrumentation libraries. Export traces to LangSmith while maintaining compatibility with the OpenTelemetry ecosystem.
initializeOTEL(config) - One-line setup with automatic instrumentationLangSmithOTLPTraceExporter - OTLP exporter configured for LangSmithGEN_AI_*) - Standard attribute names for LLM operations→ Read OpenTelemetry Documentation
Removes sensitive information from traces before sending to LangSmith. Supports pattern-based rules, custom functions, and advanced processors for comprehensive PII protection.
createAnonymizer(replacer, options) - Create anonymizers from rules, functions, or processors→ Read Anonymization Documentation
Provides structured queues for human review of LLM outputs. Enables quality assurance workflows, training data collection, and comparative model evaluation with human feedback.
createAnnotationQueue(options) - Create queues with rubric instructionsaddRunsToAnnotationQueue(params) - Add runs for reviewgetRunFromAnnotationQueue(queueId, index) - Retrieve runs for annotationgetSizeFromAnnotationQueue(queueId) - Monitor queue size→ Read Annotation Queues Documentation
Combining all three advanced features in a production application:
import { initializeOTEL } from "langsmith/experimental/otel/setup";
import { createAnonymizer } from "langsmith/anonymizer";
import { Client } from "langsmith";
import { traceable } from "langsmith/traceable";
// 1. Initialize OpenTelemetry for distributed tracing
initializeOTEL({
projectName: "production-app",
instrumentations: [
new HttpInstrumentation(),
new ExpressInstrumentation(),
],
});
// 2. Create anonymizer to protect sensitive data
const anonymizer = createAnonymizer([
{ pattern: /\b[\w\.-]+@[\w\.-]+\.\w+\b/g, replace: "[EMAIL]" },
{ pattern: /\bsk-[a-zA-Z0-9]+\b/g, replace: "[API_KEY]" },
{ pattern: /\b\d{3}-\d{2}-\d{4}\b/g, replace: "[SSN]" },
]);
// 3. Create client with anonymization enabled
const client = new Client({
apiKey: process.env.LANGSMITH_API_KEY,
anonymizer,
});
// 4. Create annotation queue for human quality review
const qaQueue = await client.createAnnotationQueue({
name: "Production QA",
description: "Human review of low-confidence outputs",
rubricInstructions: "Rate accuracy, helpfulness, and safety on 1-5 scale",
});
// 5. Create traced function with anonymization
const processUserQuery = traceable(
async (input: { email: string; query: string }) => {
// Process query - traced by both OTEL and LangSmith
const response = await handleQuery(input.query);
return {
response,
userEmail: input.email, // Will be anonymized in traces
confidence: response.confidence,
};
},
{
name: "process_user_query",
run_type: "chain",
processInputs: anonymizer, // Anonymize inputs
processOutputs: anonymizer, // Anonymize outputs
}
);
// 6. Production workflow with all features
async function productionWorkflow(email: string, query: string) {
// Process query (OpenTelemetry + LangSmith tracing, anonymized)
const result = await processUserQuery({ email, query });
// If confidence is low, add to human review queue
if (result.confidence < 0.7) {
await client.addRunsToAnnotationQueue({
queueId: qaQueue.id,
runIds: [result.runId], // From trace context
});
console.log(`Low confidence (${result.confidence}) - added to human review queue`);
}
return result;
}
// Example usage
await productionWorkflow(
"user@example.com",
"Show me data for SSN 123-45-6789"
);
// Traces will show: "[EMAIL]" and "SSN [SSN]" (anonymized)
// Low-confidence outputs automatically queued for human review
// All traces captured by OpenTelemetry + LangSmith