Skip to content

refactor: centralize environment variable lookups#89

Merged
Lyokone merged 8 commits intomainfrom
cleanup
Mar 27, 2026
Merged

refactor: centralize environment variable lookups#89
Lyokone merged 8 commits intomainfrom
cleanup

Conversation

@kevmoo
Copy link
Copy Markdown
Collaborator

@kevmoo kevmoo commented Mar 27, 2026

Introduced FirebaseEnv to unify emulator configuration and project ID resolution across namespaces, replacing scattered Platform.environment lookups.

Also made projecId not nullable and moved the demo-test
logic into a mock setting

I also refactored logging to use Zone so we get the trace ID behavior

(this was kinda tested, but never completed!)

I did a benchmark to make sure the zone overhead for each request was tiny (like 3% on a no-op request, which I'm not worried about)

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes environment variable management by introducing the FirebaseEnv class, which replaces scattered Platform.environment calls and the EmulatorEnvironment class. The feedback identifies a performance concern regarding frequent FirebaseEnv instantiations in hot paths and a robustness issue where the logger might crash if a project ID is missing. Additionally, suggestions were provided to improve code conciseness and further enhance encapsulation by adding specific getters for variables like PORT and K_SERVICE.

@kevmoo
Copy link
Copy Markdown
Collaborator Author

kevmoo commented Mar 27, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a centralized FirebaseEnv class to manage environment variables and configuration, replacing manual Platform.environment lookups throughout the package. It also refactors the logging system to use Zone keys for propagating project and trace IDs and updates the server runtime to handle trace context headers. Feedback suggests centralizing the FirebaseEnv instance within the Firebase class to improve efficiency and consistency instead of instantiating it repeatedly.

@kevmoo
Copy link
Copy Markdown
Collaborator Author

kevmoo commented Mar 27, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes environment variable management through a new FirebaseEnv class and refactors the logging system to utilize Zone-based context for project and trace IDs. The changes also include cleaning up internal exports and replacing manual environment lookups across various namespaces. Feedback identifies a bug where the trace ID prefix is duplicated in the server request handler and suggests an improvement to a unit test to properly leverage the new zone keys for better coverage.

Introduced FirebaseEnv to unify emulator configuration and project ID resolution across namespaces, replacing scattered Platform.environment lookups.

Also made `projecId` not nullable and moved the `demo-test`
logic into a mock setting
@kevmoo
Copy link
Copy Markdown
Collaborator Author

kevmoo commented Mar 27, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes environment variable management by introducing the FirebaseEnv class and refactors the logging system to utilize Zone values for project and trace IDs. These changes improve testability and ensure consistent environment handling across the SDK. One review comment identifies a documentation inconsistency in the logger's zone key example that needs to be updated.

kevmoo added 4 commits March 26, 2026 21:06
- Add robust validation to `extractTraceId` in `server.dart`
- Ensure strict 32-character hexadecimal requirement
- Add trace parsing unit tests
- Defend against empty trace strings in logger assertions
@kevmoo
Copy link
Copy Markdown
Collaborator Author

kevmoo commented Mar 27, 2026

/gemini review


/// Zone key for propagating trace IDs.
@internal
final Object traceIdZoneKey = Object();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Object is better than symbol since it'll never conflict.

Just don't make it const. 😄

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes environment variable management by introducing the FirebaseEnv class and refactoring the codebase to use it. It also improves structured logging by using Zone keys for project and trace ID propagation and adds logic to extract trace IDs from request headers. Feedback was provided regarding the projectId getter to ensure empty environment variables are treated as missing values.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Lyokone Lyokone merged commit c45fe60 into main Mar 27, 2026
8 checks passed
@Lyokone Lyokone deleted the cleanup branch March 27, 2026 10:36
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