1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 10:07:54 -05:00
denoland-deno/ext/telemetry/util.ts
snek e61cf8d7d6
refactor(unstable): move telemetry to own ext (#27067)
Move telemetry to its own ext to clean up some code and resolve circular
deps.
2024-11-26 11:22:18 +00:00

27 lines
863 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { primordials } from "ext:core/mod.js";
import type { Span } from "ext:deno_telemetry/telemetry.ts";
const { String, StringPrototypeSlice } = primordials;
export function updateSpanFromRequest(span: Span, request: Request) {
span.updateName(request.method);
span.setAttribute("http.request.method", request.method);
const url = new URL(request.url);
span.setAttribute("url.full", request.url);
span.setAttribute(
"url.scheme",
StringPrototypeSlice(url.protocol, 0, -1),
);
span.setAttribute("url.path", url.pathname);
span.setAttribute("url.query", StringPrototypeSlice(url.search, 1));
}
export function updateSpanFromResponse(span: Span, response: Response) {
span.setAttribute(
"http.response.status_code",
String(response.status),
);
}