dd-trace
Version:
Datadog APM tracing client for JavaScript
33 lines (23 loc) • 925 B
JavaScript
const { spanHasError } = require('../../../util')
const { formatIO } = require('../messages')
const LangChainLLMObsHandler = require('.')
class LangChainLLMObsChainHandler extends LangChainLLMObsHandler {
setMetaTags ({ span, inputs, results }) {
let input
if (inputs) {
input = formatIO(inputs)
}
const output = !results || spanHasError(span) ? '' : formatIO(results)
// chain spans will always be workflows
this._tagger.tagTextIO(span, input, output)
}
getName ({ span, instance }) {
const firstCallable = instance?.first
if (firstCallable?.constructor?.name === 'ChannelWrite') return
const firstCallableIsLangGraph = firstCallable?.lc_namespace?.includes('langgraph')
const firstCallableName = firstCallable?.name
return firstCallableIsLangGraph ? firstCallableName : super.getName({ span })
}
}
module.exports = LangChainLLMObsChainHandler