refactor: move inline telemetry to monkey patching in @blaxel/telemetry#261
Open
devin-ai-integration[bot] wants to merge 5 commits into
Open
refactor: move inline telemetry to monkey patching in @blaxel/telemetry#261devin-ai-integration[bot] wants to merge 5 commits into
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
- Remove startSpan/BlaxelSpan imports and inline span creation from: - BlAgent.run() in agents/index.ts - BlJob.run() in jobs/jobs.ts - McpTool.listTools() and McpTool.call() in tools/mcpTool.ts - BlaxelMcpServerTransport message/send handling in mcp/server.ts - Export BlAgent, BlJob classes and re-export McpTool from barrel - Create instrumentation/blaxel_core.ts in @blaxel/telemetry with monkey patching for all removed telemetry via prototype method wrapping - Call instrumentBlaxelCore() from TelemetryManager.instrumentApp() Co-Authored-By: cploujoux <cploujoux@blaxel.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…oved with telemetry Co-Authored-By: cploujoux <cploujoux@blaxel.ai>
The tracedHandler was calling handler(message) synchronously and immediately ending the span, but the MCP SDK's onmessage handler is async. Use await Promise.resolve(handler(message)) to properly wait for the handler to complete before ending the span. Co-Authored-By: cploujoux <cploujoux@blaxel.ai>
Contributor
There was a problem hiding this comment.
🤖 Code Review
Assessment ✅
All three previous comments have been addressed:
- Critical bug fixed —
throw errrestored in theonmessagecatch block (commit6b15edd), so handler errors are no longer silently swallowed. - Async handler fixed —
await Promise.resolve(handler(message))correctly awaits the async handler before ending the span (commit90b488e). - Double
response.text()consumption — implicitly fixed as a side effect of the refactor.
The incremental diff in this update is minimal and correct. No new issues introduced.
Note
Tag @mendral-app with feedback or questions. View session
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
refactor: move inline telemetry to monkey patching in @blaxel/telemetry
Summary
Separates telemetry concerns from business logic in
@blaxel/coreby moving all inlinestartSpancalls into@blaxel/telemetryvia prototype monkey patching — mirroring the pattern already used insdk-python'sBlaxelCoreInstrumentor.Core changes (
@blaxel/core):startSpan/BlaxelSpanimports and all inline span creation fromBlAgent.run(),BlJob.run(),McpTool.listTools(),McpTool.call(), andBlaxelMcpServerTransportmessage/send handlingBlAgent,BlJobclasses and re-exportedMcpToolfrom the tools barrel so the telemetry package can access prototypesTelemetry changes (
@blaxel/telemetry):instrumentation/blaxel_core.tswithinstrumentBlaxelCore()that monkey-patches all the above methods with span trackingTelemetryManager.instrumentApp()alongside existing HTTP instrumentationReview & Testing Checklist for Human
Map<string, BlaxelSpan>. The new approach wrapsonmessageandsend()independently — cross-request span correlation is lost. Verify this is acceptable.McpTool.call()error logging removed: The originalcall()had acatchblock withlogger.error(...)for MCP tool call failures. This was removed along with the telemetry code and NOT restored. This is a logging regression separate from telemetry.(this as any).namein McpTool patches:nameis a private property onMcpTool. The monkey patch bypasses TypeScript's type system to access it. Confirm this is the preferred approach vs. making it public.onmessageproperty descriptor patching: The MCP server patch usesObject.definePropertyto intercept the setter. Verify this interacts correctly with the MCP SDK's usage pattern (setsonmessagebefore callingstart()).@blaxel/telemetryenabled and verify spans appear correctly in your observability backend. CI alone cannot verify this.Notes
jobs/start.tsstill importsflush()from telemetry — this is intentional as it's cleanup logic, not span trackingmsg as nevercast inpatchMcpServeris a workaround forJSONRPCMessagebeing a private interface inmcp/server.tsLink to Devin session: https://app.devin.ai/sessions/2f5f61caaf1c4c4685b5037c7b10f14e
Requested by: @cploujoux
Note
Moves all inline
startSpantelemetry from@blaxel/core(BlAgent, BlJob, McpTool, BlaxelMcpServerTransport) into@blaxel/telemetryvia prototype monkey-patching, mirroring the Python SDK's BlaxelCoreInstrumentor pattern. Classes are exported from@blaxel/coreso the telemetry package can access their prototypes.Written by Mendral for commit 6b15edd.