Added a X-Trace-Id header
For tracking calls to remote runnables. This needs to be implemented in LangServe as follows:
import contextvars
trace_id_var = contextvars.ContextVar("trace_id", default=None)
async def set_trace_id(x_trace_id: Optional[str] = Header(None)):
if x_trace_id:
trace_id_var.set(x_trace_id)
dependencies.append(Depends(set_trace_id))
app = FastAPI(
title="AINinja Server",
version="1.0",
dependencies=dependencies,
)
def config_modifier(config: RunnableConfig, ctx):
if "tags" not in config:
config["tags"] = []
if trace_id_var.get():
config["tags"].append(trace_id_var.get())
return config
add_routes(
app,
runnable,
path=path,
per_req_config_modifier=config_modifier,
)
This then creates a tag in LangSmith for the trace ID