MCPcopy Index your code
hub / github.com/simstudioai/sim / withIncomingGoSpan

Function withIncomingGoSpan

apps/sim/lib/copilot/request/otel.ts:221–246  ·  view source on GitHub ↗
(
  headers: Headers,
  spanName: string,
  attributes: Record<string, string | number | boolean> | undefined,
  fn: (span: Span) => Promise<T>
)

Source from the content-addressed store, hash-verified

219// Wrap an inbound handler that Go called into so its span parents
220// under the Go-side trace (via `traceparent`).
221export async function withIncomingGoSpan<T>(
222 headers: Headers,
223 spanName: string,
224 attributes: Record<string, string | number | boolean> | undefined,
225 fn: (span: Span) => Promise<T>
226): Promise<T> {
227 const parentContext = contextFromRequestHeaders(headers)
228 const tracer = getTracer()
229 return tracer.startActiveSpan(
230 spanName,
231 { kind: SpanKind.SERVER, attributes },
232 parentContext,
233 async (span) => {
234 try {
235 const result = await fn(span)
236 span.setStatus({ code: SpanStatusCode.OK })
237 return result
238 } catch (error) {
239 markSpanForError(span, error)
240 throw error
241 } finally {
242 span.end()
243 }
244 }
245 )
246}
247
248// Wrap a copilot-lifecycle op in an OTel span. Pass `parentContext`
249// explicitly when AsyncLocalStorage-tracked context can be dropped

Callers 5

route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls 4

markSpanForErrorFunction · 0.85
getTracerFunction · 0.70
fnFunction · 0.50

Tested by

no test coverage detected