Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/nperez0111/bookhive. Track your books, share your shelves, see what others are reading bookhive.buzz
atproto bluesky books bookshelf goodreads management-system
Something went wrong. Try again.
1.0 kB · 33 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334import { SpanKind } from "@opentelemetry/api";import shimmer from "shimmer";import { measure } from "../measure";import { getRequestAttributes, getResponseAttributes, isWrapped } from "../utils";
const wrap = shimmer.wrap.bind(shimmer);
export function patchFetch() { // Check if the function is already patched // If it is, we don't want to patch it again if (isWrapped(globalThis.fetch)) { return; }
wrap(globalThis, "fetch", (original) => { return measure( { name: "fetch", spanKind: SpanKind.CLIENT, onStart: (span, [input, init]) => { span.setAttributes(getRequestAttributes(input, init)); }, onSuccess: async (span, responsePromise) => { const response = responsePromise; const attributeResponse = response.clone(); const attributes = await getResponseAttributes(attributeResponse); span.setAttributes(attributes); }, }, original, ) as typeof original; });}