Skip to content

Commit 3133f21

Browse files
committed
fix: send logs as Sentry events using captureMessage/captureException
1 parent 11a61bb commit 3133f21

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## [1.11.3](https://github.com/typelets/typelets-api/compare/v1.11.2...v1.11.3) (2025-10-18)
22

3-
43
### Bug Fixes
54

6-
* use Sentry breadcrumbs for proper structured logging field extraction ([f26f3e6](https://github.com/typelets/typelets-api/commit/f26f3e6249b19f91cd52fe39b53a7fcd215ec1a8))
5+
- use Sentry breadcrumbs for proper structured logging field extraction ([f26f3e6](https://github.com/typelets/typelets-api/commit/f26f3e6249b19f91cd52fe39b53a7fcd215ec1a8))
76

87
## [1.11.2](https://github.com/typelets/typelets-api/compare/v1.11.1...v1.11.2) (2025-10-18)
98

src/lib/logger.ts

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,64 @@ class Logger {
4040
message: string,
4141
meta: LogMetadata = {}
4242
): void {
43-
// Send as breadcrumb for proper field extraction in Sentry
43+
const enrichedData = {
44+
service: this.service,
45+
environment: this.environment,
46+
version: this.version,
47+
...meta,
48+
};
49+
50+
// Add breadcrumb for context (appears in transaction/error details)
4451
Sentry.addBreadcrumb({
4552
level,
4653
message,
4754
category: (meta.type as string) || "app",
48-
data: {
49-
service: this.service,
50-
environment: this.environment,
51-
version: this.version,
52-
...meta,
53-
},
55+
data: enrichedData,
5456
});
57+
58+
// Also send as message event so it appears in Sentry Issues
59+
// Only send info/warn/error as events (not debug to reduce noise)
60+
if (level !== "debug") {
61+
Sentry.captureMessage(message, {
62+
level,
63+
contexts: {
64+
metadata: enrichedData,
65+
},
66+
tags: {
67+
type: (meta.type as string) || "app",
68+
service: this.service,
69+
},
70+
});
71+
}
5572
}
5673

5774
error(message: string, meta: LogMetadata = {}, error?: Error): void {
5875
if (this.shouldLog(LOG_LEVELS.error)) {
5976
const enrichedMeta = { ...meta };
77+
6078
if (error) {
61-
enrichedMeta.errorMessage = error.message;
62-
enrichedMeta.errorStack = error.stack || "";
79+
// Send exception to Sentry with context
80+
Sentry.captureException(error, {
81+
contexts: {
82+
metadata: {
83+
service: this.service,
84+
environment: this.environment,
85+
version: this.version,
86+
message,
87+
...meta,
88+
},
89+
},
90+
tags: {
91+
type: (meta.type as string) || "error",
92+
service: this.service,
93+
},
94+
});
95+
} else {
96+
// No error object, send as error message
97+
this.sendToSentry("error", message, enrichedMeta);
6398
}
6499

65-
this.sendToSentry("error", message, enrichedMeta);
66-
67-
// Also send to console for CloudWatch
100+
// Also send to console for development debugging
68101
if (this.environment === "development") {
69102
console.error(message, enrichedMeta);
70103
}

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// This file is automatically updated by semantic-release
2-
export const VERSION = "1.11.3"
2+
export const VERSION = "1.11.3";

0 commit comments

Comments
 (0)