Remove OpenTelemetry tracing infrastructure (#662)

This commit is contained in:
Thomas Durieux
2026-04-15 04:39:08 +02:00
committed by GitHub
parent c6d6806d7a
commit 655ae92c4c
19 changed files with 848 additions and 1366 deletions
+45 -85
View File
@@ -7,7 +7,6 @@ import { Readable, pipeline, Transform } from "stream";
import * as archiver from "archiver";
import { promisify } from "util";
import { lookup } from "mime-types";
import { trace } from "@opentelemetry/api";
import StorageBase, { FILE_TYPE } from "./Storage";
import FileModel from "../model/files/files.model";
import { IFile } from "../model/files/files.types";
@@ -22,37 +21,20 @@ export default class FileSystem extends StorageBase {
/** @override */
async exists(repoId: string, p: string = ""): Promise<FILE_TYPE> {
const fullPath = join(config.FOLDER, this.repoPath(repoId), p);
return trace
.getTracer("ano-file")
.startActiveSpan("fs.exists", async (span) => {
span.setAttribute("path", p);
span.setAttribute("full-path", fullPath);
try {
const stat = await fs.promises.stat(fullPath);
if (stat.isDirectory()) return FILE_TYPE.FOLDER;
if (stat.isFile()) return FILE_TYPE.FILE;
} catch (_) {
// ignore file not found or not downloaded
}
span.end();
return FILE_TYPE.NOT_FOUND;
});
try {
const stat = await fs.promises.stat(fullPath);
if (stat.isDirectory()) return FILE_TYPE.FOLDER;
if (stat.isFile()) return FILE_TYPE.FILE;
} catch (_) {
// ignore file not found or not downloaded
}
return FILE_TYPE.NOT_FOUND;
}
/** @override */
async send(repoId: string, p: string, res: Response) {
const fullPath = join(config.FOLDER, this.repoPath(repoId), p);
return trace
.getTracer("ano-file")
.startActiveSpan("fs.send", async (span) => {
span.setAttribute("path", fullPath);
res.sendFile(fullPath, { dotfiles: "allow" }, (err) => {
if (err) {
span.recordException(err);
}
span.end();
});
});
res.sendFile(fullPath, { dotfiles: "allow" });
}
/** @override */
@@ -79,9 +61,7 @@ export default class FileSystem extends StorageBase {
p: string,
data: string | Readable
): Promise<void> {
const span = trace.getTracer("ano-file").startSpan("fs.write");
const fullPath = join(config.FOLDER, this.repoPath(repoId), p);
span.setAttribute("path", fullPath);
try {
await this.mk(repoId, dirname(p));
if (data instanceof Readable) {
@@ -91,32 +71,21 @@ export default class FileSystem extends StorageBase {
}
return await fs.promises.writeFile(fullPath, data, "utf-8");
} catch (err: any) {
span.recordException(err);
// throw err;
} finally {
span.end();
}
}
/** @override */
async rm(repoId: string, dir: string = ""): Promise<void> {
const span = trace.getTracer("ano-file").startSpan("fs.rm");
const fullPath = join(config.FOLDER, this.repoPath(repoId), dir);
span.setAttribute("path", fullPath);
try {
await fs.promises.rm(fullPath, {
force: true,
recursive: true,
});
} finally {
span.end();
}
await fs.promises.rm(fullPath, {
force: true,
recursive: true,
});
}
/** @override */
async mk(repoId: string, dir: string = ""): Promise<void> {
const span = trace.getTracer("ano-file").startSpan("fs.mk");
span.setAttribute("path", dir);
const fullPath = join(config.FOLDER, this.repoPath(repoId), dir);
try {
await fs.promises.mkdir(fullPath, {
@@ -124,11 +93,8 @@ export default class FileSystem extends StorageBase {
});
} catch (err: any) {
if (err.code !== "EEXIST") {
span.recordException(err);
throw err;
}
} finally {
span.end();
}
}
@@ -140,46 +106,40 @@ export default class FileSystem extends StorageBase {
onEntry?: (file: { path: string; size: number }) => void;
} = {}
): Promise<IFile[]> {
return trace
.getTracer("ano-file")
.startActiveSpan("fs.listFiles", async (span) => {
span.setAttribute("path", dir);
const fullPath = join(config.FOLDER, this.repoPath(repoId), dir);
const files = await fs.promises.readdir(fullPath);
const output2: IFile[] = [];
for (const file of files) {
const filePath = join(fullPath, file);
try {
const stats = await fs.promises.stat(filePath);
if (stats.isDirectory()) {
output2.push(new FileModel({ name: file, path: dir, repoId }));
output2.push(
...(await this.listFiles(repoId, join(dir, file), opt))
);
} else if (stats.isFile()) {
if (opt.onEntry) {
opt.onEntry({
path: join(dir, file),
size: stats.size,
});
}
output2.push(
new FileModel({
name: file,
path: dir,
repoId: repoId,
size: stats.size,
sha: stats.ino.toString(),
})
);
}
} catch (error) {
span.recordException(error as Error);
const fullPath = join(config.FOLDER, this.repoPath(repoId), dir);
const files = await fs.promises.readdir(fullPath);
const output2: IFile[] = [];
for (const file of files) {
const filePath = join(fullPath, file);
try {
const stats = await fs.promises.stat(filePath);
if (stats.isDirectory()) {
output2.push(new FileModel({ name: file, path: dir, repoId }));
output2.push(
...(await this.listFiles(repoId, join(dir, file), opt))
);
} else if (stats.isFile()) {
if (opt.onEntry) {
opt.onEntry({
path: join(dir, file),
size: stats.size,
});
}
output2.push(
new FileModel({
name: file,
path: dir,
repoId: repoId,
size: stats.size,
sha: stats.ino.toString(),
})
);
}
span.end();
return output2;
});
} catch (error) {
// ignore stat errors for individual files
}
}
return output2;
}
/** @override */