( input: RequestInfo | URL | string, init?: RequestInit, attemptCount: number = 0 )
| 362 | } |
| 363 | |
| 364 | const doFetchRequest = async ( |
| 365 | input: RequestInfo | URL | string, |
| 366 | init?: RequestInit, |
| 367 | attemptCount: number = 0 |
| 368 | ): Promise<[Response, Span]> => { |
| 369 | const httpMethod = normalizeHttpMethod(input, init); |
| 370 | |
| 371 | const span = tracer.startSpan(`HTTP ${httpMethod}`, { |
| 372 | attributes: { |
| 373 | [SemanticInternalAttributes.STYLE_ICON]: "world", |
| 374 | ...(attemptCount > 1 ? { ["http.request.resend_count"]: attemptCount - 1 } : {}), |
| 375 | ...createFetchAttributes(input, init), |
| 376 | }, |
| 377 | }); |
| 378 | |
| 379 | try { |
| 380 | const response = await fetchWithInterceptors(input, { |
| 381 | ...init, |
| 382 | headers: { |
| 383 | ...init?.headers, |
| 384 | "x-retry-count": attemptCount.toString(), |
| 385 | }, |
| 386 | }); |
| 387 | |
| 388 | span.setAttributes(createFetchResponseAttributes(response)); |
| 389 | |
| 390 | if (!response.ok) { |
| 391 | span.recordException(`${response.status}: ${response.statusText}`); |
| 392 | span.setStatus({ |
| 393 | code: SpanStatusCode.ERROR, |
| 394 | message: `${response.status}: ${response.statusText}`, |
| 395 | }); |
| 396 | } |
| 397 | |
| 398 | return [response, span]; |
| 399 | } catch (e) { |
| 400 | if (typeof e === "string" || e instanceof Error) { |
| 401 | span.recordException(e); |
| 402 | } |
| 403 | |
| 404 | span.setStatus({ code: SpanStatusCode.ERROR }); |
| 405 | span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, 0); |
| 406 | span.setAttribute("http.status_text", "This operation was aborted."); |
| 407 | |
| 408 | throw new FetchErrorWithSpan(e, span); |
| 409 | } |
| 410 | }; |
| 411 | |
| 412 | const calculateRetryDelayForResponse = async ( |
| 413 | retry: FetchRetryByStatusOptions | undefined, |
no test coverage detected
searching dependent graphs…