Skip to content

Commit

Permalink
add proper otel logging for find book
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnmclean committed Dec 18, 2024
1 parent 6e68935 commit 931a0d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ SUPABASE_URL="http://localhost:54321"
NEXT_PUBLIC_SUPABASE_URL="http://localhost:54321"
SUPABASE_ANON_KEY="123"

NEXT_PUBLIC_POSTHOG_KEY=123
NEXT_PUBLIC_POSTHOG_KEY=123

OTEL_EXPORTER_OTLP_HEADERS="x-api-key=123"
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://localhost:4317"
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="http://localhost:4317"
22 changes: 14 additions & 8 deletions apps/sovoli.com/src/services/books/findBookByISBN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ export class FindBookByISBN extends BaseService<
where: or(eq(schema.Book.isbn10, isbn), eq(schema.Book.isbn13, isbn)),
});

if (internalBook && !forceExternal) {
console.log("found book in internal db");
return {
book: internalBook,
};
if (internalBook) {
this.logger.info("Found book in internal DB");

if (!forceExternal) {
return {
book: internalBook,
};
}

this.logger.info("Force external search despite finding internal result");
} else {
this.logger.info("No internal book found, proceeding to external search");
}

console.log("no internal results, searching externally");
const getBookFromISBNdb = new GetBookFromISBNdb();

const { book } = await getBookFromISBNdb.call({ isbn });

if (!book) {
console.log("no external book found");
this.logger.info("No external book found");
return {};
}

console.log("found external book");
this.logger.info("Found book externally and upserting into DB", book);

const [insertedBooks] = await db
.insert(schema.Book)
Expand Down

0 comments on commit 931a0d5

Please sign in to comment.