documentation icon indicating copy to clipboard operation
documentation copied to clipboard

[ Documentation request ] [Typo] Observability Testing with DefaultLogger unclear

Open cloudbring opened this issue 1 year ago • 0 comments

Brief description

There is a typo on the Observability Typescript Guide ➡️

typo

import { DefaultLogger, LogEntry } from '@temporalio/worker';

const logs: LogEntry[] = [];
const logger = new DefaultLogger('TRACE', (entry) => logs.push(entry));
log.debug('hey', { a: 1 });
log.info('ho');
log.warn('lets', { a: 1 });
log.error('go');

The code doesn't make sense as it is written. I think the intent was that the log object referenced should be logger. If it's not a typo, it isn't clear to me what the 'log' object is and it's relationship to logs and logger.

The context of this was for a section "Accumulate logs for testing and reporting" but, the code above doesn't show how it can be used in a test.

A testing question I think would be useful answered in the documentation is:

  1. How could you iterate through the <LogEntry> objects in logs to assert/expect an outcome?
  • How do you access the LEVEL in a <LogEntry> object?
  • How do you access the metadata object in a <LogEntry> object?

    Example: log.debug('hey', { a: 1, foo: 'bar' }) ➡️ { a: 1, foo: 'bar' }

Your recommended content

I'd be more than happy to fix the typo above and look up <LogEntry> so that a more useful code snippet for testing Observability can be made.

cloudbring avatar Feb 15 '24 21:02 cloudbring