mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
I noticed that the `llm.chat.*_tokens` attributes weren't in spans, and it turns out none of the attributes from the wrapped function make it in. only those added synchronously from within `wrapWithSpan` do. A few things in play here: 1. Switch from `ZoneContextManager` (which doesn't work with native async/await) to `AsyncLocalStorageContextManager` (which does.) 2. (1) requires we use a pnpm patch, since wrangler requires that we import `async_hooks` statically, and the otel code `requires` it, and also requires that it's spelled `node:async_hooks`. 3. encode the payload we try to send _before_ doing the retry loop, so we don't re-encode for each attempt. 4. switch from `startActiveSpan` to `context.with` + `startSpan`. The latter allows us to wrap an async function. the former is for synchronous functions.
33 lines
1.8 KiB
Diff
33 lines
1.8 KiB
Diff
diff --git a/build/src/AsyncHooksContextManager.js b/build/src/AsyncHooksContextManager.js
|
|
index 3b8866855dd900570cbd126b9ca57bd91e1d7cb5..b55f3fb34b54695e06fea6a3e39dcbb133d0c594 100644
|
|
--- a/build/src/AsyncHooksContextManager.js
|
|
+++ b/build/src/AsyncHooksContextManager.js
|
|
@@ -14,10 +14,10 @@
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
+import * as asyncHooks from "node:async_hooks";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.AsyncHooksContextManager = void 0;
|
|
const api_1 = require("@opentelemetry/api");
|
|
-const asyncHooks = require("async_hooks");
|
|
const AbstractAsyncHooksContextManager_1 = require("./AbstractAsyncHooksContextManager");
|
|
class AsyncHooksContextManager extends AbstractAsyncHooksContextManager_1.AbstractAsyncHooksContextManager {
|
|
constructor() {
|
|
diff --git a/build/src/AsyncLocalStorageContextManager.js b/build/src/AsyncLocalStorageContextManager.js
|
|
index 86fe67194acd7af0b8e00fd0eb10dc2edf8945f0..65baff025a8d6a8fafbeae1f6f91906d08a657e6 100644
|
|
--- a/build/src/AsyncLocalStorageContextManager.js
|
|
+++ b/build/src/AsyncLocalStorageContextManager.js
|
|
@@ -14,10 +14,10 @@
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
+import * as async_hooks_1 from "node:async_hooks";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.AsyncLocalStorageContextManager = void 0;
|
|
const api_1 = require("@opentelemetry/api");
|
|
-const async_hooks_1 = require("async_hooks");
|
|
const AbstractAsyncHooksContextManager_1 = require("./AbstractAsyncHooksContextManager");
|
|
class AsyncLocalStorageContextManager extends AbstractAsyncHooksContextManager_1.AbstractAsyncHooksContextManager {
|
|
constructor() {
|