feat(blog): wire instrumentation — repo spans + use-case/controller withSpan + logger capture

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-07 00:18:13 +02:00
parent 64b6eb79d4
commit 5903cef70a
8 changed files with 506 additions and 111 deletions

View File

@@ -1,5 +1,6 @@
import "reflect-metadata";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { NoopTracer, NoopLogger } from "@repo/core-shared/instrumentation";
import { bindDevSeedBlog } from "@/di/bind-dev-seed";
import { blogContainer } from "@/di/container";
import { BLOG_SYMBOLS } from "@/di/symbols";
@@ -7,11 +8,14 @@ import { MockArticlesRepository } from "@/infrastructure/repositories/articles.r
import type { IArticlesRepository } from "@/application/repositories/articles.repository.interface";
describe("bindDevSeedBlog", () => {
const tracer = new NoopTracer();
const logger = new NoopLogger();
// Each test starts from the default empty-mock binding and tears down
// afterwards so the global blogContainer state stays clean for siblings.
beforeEach(() => {
if (blogContainer.isBound(BLOG_SYMBOLS.IArticlesRepository)) {
blogContainer.unbind(BLOG_SYMBOLS.IArticlesRepository);
for (const sym of Object.values(BLOG_SYMBOLS)) {
if (blogContainer.isBound(sym)) blogContainer.unbind(sym);
}
blogContainer
.bind<IArticlesRepository>(BLOG_SYMBOLS.IArticlesRepository)
@@ -19,8 +23,8 @@ describe("bindDevSeedBlog", () => {
});
afterEach(() => {
if (blogContainer.isBound(BLOG_SYMBOLS.IArticlesRepository)) {
blogContainer.unbind(BLOG_SYMBOLS.IArticlesRepository);
for (const sym of Object.values(BLOG_SYMBOLS)) {
if (blogContainer.isBound(sym)) blogContainer.unbind(sym);
}
blogContainer
.bind<IArticlesRepository>(BLOG_SYMBOLS.IArticlesRepository)
@@ -28,7 +32,7 @@ describe("bindDevSeedBlog", () => {
});
it("populates the repository with the dev articles", async () => {
await bindDevSeedBlog();
await bindDevSeedBlog(tracer, logger);
const repo = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository,
@@ -39,7 +43,7 @@ describe("bindDevSeedBlog", () => {
});
it("seeds the welcome article reachable by slug", async () => {
await bindDevSeedBlog();
await bindDevSeedBlog(tracer, logger);
const repo = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository,
@@ -52,13 +56,13 @@ describe("bindDevSeedBlog", () => {
});
it("is idempotent — calling twice rebuilds a fresh populated repo", async () => {
await bindDevSeedBlog();
await bindDevSeedBlog(tracer, logger);
const before = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository,
);
const beforeCount = (await before.getArticles()).length;
await bindDevSeedBlog();
await bindDevSeedBlog(tracer, logger);
const after = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository,
);