Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add stacktrace for warn #48

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clever-dogs-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-use/gcp-logging": patch
---

Don't add stacktrace for warn
10 changes: 9 additions & 1 deletion packages/gcp-logging/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type LogEntry = {
span?: LogSpan.LogSpan | undefined
parent?: LogSpan.LogSpan | undefined
exception?: string
debuggingInfo?: string
[GCP_LOG_SPAN_KEY]?: string | undefined
[GCP_LOG_TRACE_KEY]?: string | undefined
}
Expand Down Expand Up @@ -82,6 +83,7 @@ export const customLogger = (

let messageOrCause = message
let exception: any = undefined
let debuggingInfo: any = undefined

if (cause && cause._tag != 'Interrupt') {
messageOrCause = message ?? Cause.pretty(cause)
Expand All @@ -101,6 +103,11 @@ export const customLogger = (
}
}

if(logLevel.label === 'WARN'){
debuggingInfo = exception
exception = undefined
}

// TODO: should we use logAnnotations for span & trace?
logFn({
annotations: {
Expand All @@ -109,7 +116,8 @@ export const customLogger = (
timestamp: date.toISOString(),
level: logLevel.label,
exception,
message,
message: messageOrCause,
debuggingInfo,
meta,
span,
parent: parentSpan,
Expand Down
45 changes: 45 additions & 0 deletions packages/gcp-logging/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,51 @@ const makeTestLayer = (onLog: (x: any) => void) =>
)
)

describe('logWarning', ()=>{
describe('when logging with an error', ()=>{
it('stores the stacktrace in debugging property', ()=>{
let log: unknown[] = []

pipe(
pipe(
Effect.logWarning('message in the log', Cause.fail(new Error('cause of the error')))
),

Effect.provide(
pipe(
Layer.provideMerge(
Layer.succeed(Clock.Clock, testClock),
Logger.replace(
Logger.defaultLogger,
customLogger((a) => {
log.push(a)
})
)
)
)
),
Effect.runSync
)

expect(log).toEqual([
{
annotations: {},
level: 'WARN',
'logging.googleapis.com/spanId': undefined,
'logging.googleapis.com/trace': undefined,
message: 'message in the log',
debuggingInfo: expect.stringContaining('at Object.<anonymous>'),
meta: {},
exception: undefined,
parent: undefined,
span: undefined,
timestamp: expect.any(String),
},
])
})
})
})

describe('logError', () => {
describe('when logging error with a message and a cause from a handled error', () => {
it('reports the failure', () => {
Expand Down
Loading