Skip to content

Integrate logger client into cdp-client with service-based discovery#27

Merged
stefanrammo merged 45 commits intomainfrom
logger-client-integration
Apr 10, 2026
Merged

Integrate logger client into cdp-client with service-based discovery#27
stefanrammo merged 45 commits intomainfrom
logger-client-integration

Conversation

@stefanrammo
Copy link
Copy Markdown
Collaborator

Bundle cdplogger-client as studio.logger and add client.logger() method that discovers loggers via ServicesNotification and connects through proxy transport via makeServiceTransport (CDP 5.1+).

  • client.logger(name, options): auto-discovers logserver proxy service, creates service transport, passes to LoggerClient constructor
  • client.loggers(): returns all discovered logger services as [{name, metadata}] after first ServicesNotification
  • LoggerClient constructor extended to accept service transport object in addition to endpoint string (autoReconnect forced false)
  • Caching by name with eviction on transport close
  • close() disconnects cached loggers and rejects pending promises
  • Logger transports registered in serviceConnections for proper cleanup on primary connection drop
  • Rejects immediately on CDP < 5.1 (no proxy protocol support)
  • Proto files use raw .proto.js format matching studioapi.proto.js, with Node/browser parity via require() and window globals
  • Unit tests adapted from cdplogger-client test suite
  • README.rst updated with Logger Integration API documentation

Karmo7 and others added 30 commits March 19, 2025 16:56
Initial implementation: logger, example usage, and tests
A test for Events using the example case in CDP Studio
Match type added and restructuring client.js
@stefanrammo
Copy link
Copy Markdown
Collaborator Author

The bundled logger client is adapted from https://github.com/CDPTechnologies/JavascriptCDPLoggerClient with these changes to support integration:

  1. Proto loading: replaced pre-compiled containerPb.js with runtime protobuf.parse() of raw .proto.js files — same format as studioapi.proto.js, Node/browser parity via require() and window globals
  2. Transport mode: constructor accepts a service transport object (duck-typed via typeof send === 'function'), forces autoReconnect = false, wires onopen/onmessage/onerror/onclose handlers — enables tunneling through StudioAPI proxy
  3. disconnected flag: tracks connection state for cache eviction in client.logger()
  4. _rejectIfDisconnected() guard: every public method rejects immediately after disconnect() or transport close
  5. countEvents dispatch: added missing case in _sendQueuedRequests switch

@stefanrammo stefanrammo requested review from Karmo7 and nuubik April 8, 2026 13:45
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Were there any changes to this file? It would be better to make bringing in existing code a separate commit, so it would be easier to review the actual changes done after that.

By the way, we have a guide in our wiki how to merge repositories (or some files from a repository) while keeping commit history, search for the "Git tips & tricks" page. Then the development log of the logger client will be preserved.

index.js Outdated
/**
* Get a logger client via service-based discovery and proxy transport (CDP 5.1+).
* @param {string} [name] - Logger service name (node path) to filter by.
* @param {Object} [options] - Options.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[options] - Options. - just repeating the argument name is not useful

index.js Outdated
}

/**
* Get a logger client via service-based discovery and proxy transport (CDP 5.1+).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the doc should describe more what one can do with the logger client (query historic data) not how it was found. Should keep the CDP 5.1+ comment though

index.js Outdated
* Get a logger client via service-based discovery and proxy transport (CDP 5.1+).
* @param {string} [name] - Logger service name (node path) to filter by.
* @param {Object} [options] - Options.
* @param {number} [options.timeout] - Timeout in milliseconds. Rejects if no matching service appears in time.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens when timeout is not specified?

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.

Indefinite wait for server event using 2s sibling polling.

index.js Outdated
reject("Logger service discovery requires CDP 5.1+");
return;
}
var service = primary.findLoggerService(name);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it also look for logger services from other sibling applications?

In case there are multiple apps in the system, the connection to logger can be "tunneled twice", e.g. StudioAPI client -> MainApp -> LoggerApp -> CDPLogger server.

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.

Changed it, it searches all connections now

README.rst Outdated
Auto-discovers the first available CDPLogger or LogServer via service discovery,
creates a proxy transport, and returns a ready-to-use logger client. Repeated calls
return the same cached instance. A cached logger whose transport has closed is evicted
on the next call.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should explain why is it relevant to the user when the cached call is evicted

For more information about CDP Logger, see https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-index.html.

Logger data is served behind StudioAPI authentication and tunneled through the
existing proxy connection.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should have somewhere also a longer description. Either in this file or a different file. The https://github.com/CDPTechnologies/JavascriptCDPLoggerClient/blob/main/DOCUMENTATION.md had a good overview and some background into what the logger can do.

And I also liked the examples folder in the logger client repo, maybe should copy those also over here.

Merge JavascriptCDPLoggerClient repository into logger/ with full
commit history preserved. All files imported unchanged.

Source: https://github.com/CDPTechnologies/JavascriptCDPLoggerClient
@stefanrammo stefanrammo force-pushed the logger-client-integration branch from e8addfd to d4d7903 Compare April 9, 2026 17:19
index.js Outdated
* Discovers loggers from all applications in the system, including
* sibling apps connected via proxy.
* @param {string} [name] - Logger service name to filter by, e.g. "App.CDPLogger".
* @param {number} [options.timeout] - Timeout in milliseconds. Without timeout, waits indefinitely until a matching logger appears.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should mention that timeout 0 means immediate fail if logger was not found.

logger/LICENSE Outdated
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 CDP Technologies
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2026

README.rst Outdated
to manually discover the logger port or manage a separate WebSocket connection.
For more information about CDP Logger, see https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-index.html.
For background on the data query protocol, time synchronization, and API version
history, see `logger/DOCUMENTATION.md <logger/DOCUMENTATION.md>`_. Runnable
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make sure to test that this link still works after pushing the code to npm

Bundle cdplogger-client as studio.logger and add client.logger() method
that discovers loggers via ServicesNotification and connects through
proxy transport via makeServiceTransport (CDP 5.1+).

- client.logger(name, options): auto-discovers logserver proxy service
  across all connections including sibling apps via proxy
- client.loggers(): returns all discovered logger services
- Sibling app discovery: searches all AppConnections, not just primary;
  serviceUpdateListeners fire on all connections; poll interval catches
  new siblings that appear after initial listener registration
- Dead connection guard: isConnectionAlive() skips connections whose
  transport is closed, preventing stale service discovery
- Caching by name with eviction on transport close; stale promise
  cleanup via .then(clearPromise, clearPromise) on both resolve/reject
- close() disconnects cached loggers and rejects pending promises
- Error() rejections matching existing find()/onConnect() patterns
- Proto files use raw .proto.js format matching studioapi.proto.js
- Standalone files from import removed (client.js, package.json,
  generated/, test/, .github/, QUICKSTART.md, README.md)
- DOCUMENTATION.md updated for bundled context
- Unit tests adapted from cdplogger-client test suite
- README.rst Logger Integration section with API docs and examples
- Examples (event.js, value.js) updated for proxy-based discovery
@stefanrammo stefanrammo force-pushed the logger-client-integration branch from d4d7903 to 447cc35 Compare April 10, 2026 09:39
@stefanrammo stefanrammo merged commit fe96b14 into main Apr 10, 2026
4 checks passed
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.

3 participants