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 · 37 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738import { SpanKind } from "@opentelemetry/api";import shimmer from "shimmer";import { measure } from "../measure";import { getRequestAttributes, getResponseAttributes, isWrapped,} from "../utils";
const { wrap } = 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 = await responsePromise; const attributeResponse = response.clone(); const attributes = await getResponseAttributes(attributeResponse); span.setAttributes(attributes); }, }, original, ) as typeof original; });}