Skip to content
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

docs(js): Add section on tracing at high concurrency in serverless envs #611

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,39 @@ const res = await tracedFn();

await langsmithClient.awaitPendingTraceBatches();
```

## Rate limits at high concurrency

By default, the LangSmith client will batch operations as your traced run executions, sending a new batch every few milliseconds.

This works well in most situations, but if your traced function is long-running and you have very high concurrency,
you may also hit rate limits related to overall request count.

If you are seeing rate limit errors related to this, you can try setting `manualFlushMode: true` in your client like this:

```ts
import { Client } from "langsmith";

const langsmithClient = new Client({
manualFlushMode: true,
});

const myTracedFunc = traceable(
async () => {
// Your logic here...
},
{ client: langsmithClient }
);
```

And then manually calling `client.flush()` like this before your serverless function closes:

```ts
try {
await myTracedFunc();
} finally {
await langsmithClient.flush();
}
```

Note that this will prevent runs from appearing in the LangSmith UI until you call `.flush()`.
Loading