Observation-specific attributes to update (type varies by observation type)
Optional
options: { asType: "span" }Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context
and updates it with Langfuse-specific attributes. It supports all observation types
through TypeScript overloads, providing type safety for attributes based on the
specified asType
parameter. If no active span exists, the update is skipped with a warning.
asType
parameterstartActiveObservation
callbacks or manual span contextsObservation-specific attributes to update (type varies by observation type)
Configuration specifying observation type (defaults to 'span')
import { updateActiveObservation, startActiveObservation } from '@langfuse/tracing';
// Update active span (default)
await startActiveObservation('data-processing', async (observation) => {
// Process data...
const result = await processData(inputData);
// Update with results
updateActiveObservation({
output: { processedRecords: result.count },
metadata: { processingTime: result.duration }
});
});
// Update active generation
await startActiveObservation('llm-call', async () => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }]
});
// Update with LLM-specific attributes
updateActiveObservation({
output: response.choices[0].message,
usageDetails: {
promptTokens: response.usage.prompt_tokens,
completionTokens: response.usage.completion_tokens,
totalTokens: response.usage.total_tokens
},
costDetails: {
totalCost: 0.025,
currency: 'USD'
}
}, { asType: 'generation' });
}, {}, { asType: 'generation' });
// Update active tool execution
await startActiveObservation('web-search', async () => {
const results = await searchAPI('latest news');
updateActiveObservation({
output: {
results: results,
count: results.length,
relevanceScore: 0.89
},
metadata: {
searchLatency: 150,
cacheHit: false
}
}, { asType: 'tool' });
}, {}, { asType: 'tool' });
// Update active agent workflow
await startActiveObservation('research-agent', async () => {
// Agent performs multiple operations...
const findings = await conductResearch();
updateActiveObservation({
output: {
completed: true,
toolsUsed: ['web-search', 'summarizer'],
iterationsRequired: 3,
confidence: 0.92
},
metadata: {
efficiency: 0.85,
qualityScore: 0.88
}
}, { asType: 'agent' });
}, {}, { asType: 'agent' });
// Update active chain workflow
await startActiveObservation('rag-pipeline', async () => {
// Execute multi-step RAG process...
const finalResponse = await executeRAGPipeline();
updateActiveObservation({
output: {
finalResponse: finalResponse,
stepsCompleted: 4,
documentsRetrieved: 8,
qualityScore: 0.91
},
metadata: {
pipelineEfficiency: 0.87,
totalLatency: 3200
}
}, { asType: 'chain' });
}, {}, { asType: 'chain' });
Updates the currently active observation with new attributes.
This function finds the currently active OpenTelemetry span in the execution context and updates it with Langfuse-specific attributes. It supports all observation types through TypeScript overloads, providing type safety for attributes based on the specified
asType
parameter. If no active span exists, the update is skipped with a warning.Type Safety
asType
parameterContext Requirements
startActiveObservation
callbacks or manual span contextsSupported Observation Types