Overview

When you’re using the Langtrace SDK with any of the supported vendors, you can set custom span names to traces. This allows you to identify the span in the trace with a custom name. You can use the inject_additional_attributes function to set custom span names to traces. This name will be appended to the operation name and will be identified as the name of the span in the trace.

Please see the example below to learn how to set custom span names to traces. Note that the key langtrace.span.name is used to pass the custom span name to the trace.

If you did not pass langtrace.span.name as key inside inject_additional_attributes, custom span naming will not work
from langtrace_python_sdk import inject_additional_attributes

class CoT(dspy.Module):
    def __init__(self):
        super().__init__()
        self.prog = dspy.ChainOfThought("question -> answer")

    def forward(self, question):
        result = inject_additional_attributes(lambda: self.prog(question=question), {'langtrace.span.name': 'MathProblemsCotParallel'})
        return result