-
Notifications
You must be signed in to change notification settings - Fork 5
Spike: Making a browser compatible lib #193
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
Open
intentionally-left-nil
wants to merge
19
commits into
main
Choose a base branch
from
feature/lib-web
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cfffc6e
Create a lib-web package
intentionally-left-nil 66fae43
Refactor the logger to work in the web context
intentionally-left-nil cd07402
Add the artifact-client
intentionally-left-nil bf6d2c8
Add config.ts
intentionally-left-nil ab01f47
Add the runtime agent
intentionally-left-nil 3f8ead8
Fix the tests
intentionally-left-nil 71e2c7f
Change the logger code to lib-web
intentionally-left-nil e83f5ac
Remove tests migrated to lib-web
intentionally-left-nil afc340f
Remove types.ts from lib and use lib-web instead
intentionally-left-nil cd7735a
Remove artifact client
intentionally-left-nil 97e35ec
Remove the config from lib
intentionally-left-nil d7e03e6
Switch to the DenoRuntimeAgent extended from lib-web
intentionally-left-nil a5a2886
Run the formatter
intentionally-left-nil a1773c4
Fix publish dry run
intentionally-left-nil 56f6fbd
Fix linter errors
intentionally-left-nil 7e72b5a
Fix dorny/filter
intentionally-left-nil 5c0f7f3
Switch the runtime agents to be based off Deno for consistency
intentionally-left-nil 37906a3
Fix imports to use import map
intentionally-left-nil 4b57449
fixup imports to use standard import mapping names
intentionally-left-nil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| # @runt/lib-web | ||
|
|
||
| Web-compatible logging library for Runt applications. | ||
|
|
||
| This package provides a lightweight, web-compatible version of the Runt logging | ||
| system, containing only the essential logging functionality without the full | ||
| runtime agent capabilities. | ||
|
|
||
| ## Features | ||
|
|
||
| - Structured logging with OpenTelemetry support | ||
| - Configurable log levels (DEBUG, INFO, WARN, ERROR) | ||
| - Child loggers with additional context | ||
| - Operation tracing and timing utilities | ||
| - Environment-based configuration | ||
| - Console output suppression utilities | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Basic Usage | ||
|
|
||
| ```typescript | ||
| import { createLogger, logger } from "@runt/lib-web"; | ||
|
|
||
| // Use the default logger | ||
| logger.info("Application started"); | ||
|
|
||
| // Create a custom logger | ||
| const appLogger = createLogger("my-app"); | ||
| appLogger.debug("Debug message"); | ||
| appLogger.warn("Warning message"); | ||
| appLogger.error("Error occurred", new Error("Something went wrong")); | ||
| ``` | ||
|
|
||
| ### Configuration | ||
|
|
||
| ```typescript | ||
| import { Logger, LogLevel } from "@runt/lib-web"; | ||
|
|
||
| const logger = new Logger({ | ||
| level: LogLevel.DEBUG, | ||
| service: "my-service", | ||
| console: true, | ||
| context: { version: "1.0.0" }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Child Loggers | ||
|
|
||
| ```typescript | ||
| const parentLogger = createLogger("parent"); | ||
| const childLogger = parentLogger.child({ | ||
| userId: "123", | ||
| sessionId: "abc", | ||
| }); | ||
|
|
||
| childLogger.info("User action performed"); // Includes parent and child context | ||
| ``` | ||
|
|
||
| ### Operation Tracing | ||
|
|
||
| ```typescript | ||
| const result = await logger.trace("database-query", async () => { | ||
| // Your async operation here | ||
| return await database.query("SELECT * FROM users"); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Operation Timing | ||
|
|
||
| ```typescript | ||
| const result = await logger.time("api-call", async () => { | ||
| // Your async operation here | ||
| return await fetch("/api/data"); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Environment Configuration | ||
|
|
||
| Set environment variables to configure logging: | ||
|
|
||
| - `RUNT_LOG_LEVEL`: Set log level (DEBUG, INFO, WARN, ERROR) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this means that we'd need to set |
||
| - `RUNT_DISABLE_CONSOLE_LOGS`: Disable console output | ||
|
|
||
| ### Signal Handling (Runtime Agent) | ||
|
|
||
| For runtime agents, you can inject custom signal handling functions: | ||
|
|
||
| ```typescript | ||
| import { RuntimeAgent, RuntimeConfig } from "@runt/lib-web"; | ||
|
|
||
| const signalHandlers = { | ||
| setup: (shutdown: () => void) => { | ||
| // Set up your signal handlers here | ||
| // For example, in a web environment: | ||
| window.addEventListener("beforeunload", shutdown); | ||
|
|
||
| // Or in a Node.js environment: | ||
| process.on("SIGINT", shutdown); | ||
| process.on("SIGTERM", shutdown); | ||
| }, | ||
| cleanup: () => { | ||
| // Clean up your signal handlers here | ||
| // For example: | ||
| window.removeEventListener("beforeunload", shutdown); | ||
| }, | ||
| }; | ||
|
|
||
| const options = { | ||
| runtimeId: "my-runtime", | ||
| runtimeType: "python", | ||
| capabilities: { | ||
| canExecuteCode: true, | ||
| canExecuteSql: false, | ||
| canExecuteAi: false, | ||
| }, | ||
| syncUrl: "wss://example.com", | ||
| authToken: "your-token", | ||
| notebookId: "your-notebook", | ||
| signalHandlers, // Inject the signal handlers | ||
| environmentOptions: {}, | ||
| }; | ||
|
|
||
| const config = new RuntimeConfig(options); | ||
| const agent = new RuntimeAgent(config, options.capabilities); | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| ### Classes | ||
|
|
||
| #### Logger | ||
|
|
||
| The main logging class. | ||
|
|
||
| **Constructor:** | ||
|
|
||
| ```typescript | ||
| new Logger(config?: Partial<LoggerConfig>) | ||
| ``` | ||
|
|
||
| **Methods:** | ||
|
|
||
| - `debug(message: string, data?: Record<string, unknown>): void` | ||
| - `info(message: string, data?: Record<string, unknown>): void` | ||
| - `warn(message: string, data?: Record<string, unknown>): void` | ||
| - `error(message: string, error?: Error | unknown, data?: Record<string, unknown>): void` | ||
| - `child(context: Record<string, unknown>): Logger` | ||
| - `trace<T>(name: string, operation: () => Promise<T>, attributes?: Record<string, unknown>): Promise<T>` | ||
| - `time<T>(name: string, operation: () => Promise<T>, data?: Record<string, unknown>): Promise<T>` | ||
|
|
||
| ### Functions | ||
|
|
||
| - `createLogger(service: string, options?: Partial<LoggerConfig>): Logger` | ||
| - `withQuietLogging<T>(operation: () => T): T` | ||
|
|
||
| ### Types | ||
|
|
||
| - `LogLevel`: Enum with DEBUG, INFO, WARN, ERROR | ||
| - `LoggerConfig`: Interface for logger configuration | ||
|
|
||
| ### Constants | ||
|
|
||
| - `logger`: Default logger instance | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| # Run tests | ||
| deno task test | ||
|
|
||
| # Run tests in watch mode | ||
| deno task test:watch | ||
|
|
||
| # Check types | ||
| deno task check | ||
|
|
||
| # Format code | ||
| deno task fmt | ||
|
|
||
| # Lint code | ||
| deno task lint | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style wise, the reason I keep the
npm:prefix is to make our code copy-pastable into a Deno notebook. Looking at this now though, I'd need to do the same withjsr:deps.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, but local usage of this (prior to publishing to jsr) would need to have the right references. Guck.