Skip to content

Conversation

aarsilv
Copy link
Contributor

@aarsilv aarsilv commented Oct 4, 2025

πŸ‘― Related PR: js-client-sdk #257

Eppo Only:
🎟️ Tickets:

Motivation and Context

This common repository is shared with the Node.js and Browser JavaScript SDKs. The latter won't have a global process, causing errors unless a dummy global process is defined.

Also, currently, logging is hard-coded to be off (silent) for the Browser SDK. However, having logs can be helpful, especially for debugging.

Description

This PR does not assume process will be defined.

It also changes the logger's default log level for browser to be warn instead of forced off. There is a new setLogLevel() method that can be called to change that if desired.

How has this been documented?

How has this been tested?

  • Existing unit tests
  • Spun up sample browser app that worked without a dummy process. Also I saw no logs by default, error if I provided a bad SDK key, and then all the info logs if I changed the log level on purpose.
image

// Use any specified log level, or warn in production/browser, info otherwise
/* eslint-disable no-restricted-globals */
level:
typeof process !== 'undefined' && process.env.LOG_LEVEL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ”§ The fix: we now check that process is defined before accessing

} catch (err: any) {
logger.error('Error logging bandit event', err);
} catch (err) {
logger.error({ err }, 'Error logging bandit event');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pino's API (link) is to have context first, then the log message.

@aarsilv aarsilv changed the title Aarsilv/ffesupport 100/browser logging fixes Fix browser logging fixes Oct 4, 2025
@aarsilv aarsilv marked this pull request as ready for review October 4, 2025 23:23
? process.env.LOG_LEVEL
: typeof process === 'undefined' || process.env.NODE_ENV === 'production'
? 'warn'
: 'info',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getpino.io/#/docs/api?id=level-string

Looks like it defaults to 'info' anyway, but I like that it's explicit here

@aarsilv aarsilv merged commit 5789448 into main Oct 5, 2025
8 checks passed
@aarsilv aarsilv deleted the aarsilv/ffesupport-100/browser-logging-fixes branch October 5, 2025 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants