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

Add Telemetry abstraction and remove Sentry as a peer dep #46

Closed

Conversation

transitive-bullshit
Copy link
Collaborator

Desc

Extends #38 to no longer depend on @sentry/node, but rather a flexible, base, sentry-like telemetry provider.

By default, models will use a DefaultTelemetry if not given a telemetry provider like @sentry/node.

I added a unit test to ensure that at least the types of @sentry/node match the expected Telemetry.Base provider type.

@rileytomasek I'm sure there may be a cleaner way to do this, but I felt like the telemetry provider belonged outside of model since it could theoretically be used for datastore in the future. At the very least, this change lets us continue iterating on Dexter without it being dependent on Sentry, which I think is a net win.

Example

import { ChatModel } from '@dexaai/dexter'
import * as Sentry from '@sentry/node'

const model = new ChatModel({ telemetry: Sentry })

Copy link

vercel bot commented Aug 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dexter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 7, 2024 7:54am

@transitive-bullshit
Copy link
Collaborator Author

Note: the pnpm lockfile was also updated to the latest v9.

>;

export class ChatModel<
CustomCtx extends Model.Ctx = Model.Ctx,
MTelemetry extends Telemetry.Base = Telemetry.Base,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rileytomasek I tried both ways with the Ctx generic coming before telemetry and after, and I think after is the right call. Most of the time you want telemetry to be inferred by the compiler, whereas it's more common to customize the context type.

);
return response;
}
return this.telemetry.startSpan(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the only reason this block looks like a bigger change than it is is due to spacing. it's just replacing Sentry with this.telemetry.


await Promise.allSettled(
this.events.onComplete?.map((event) =>
this.events.onStart?.map((event) =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

github's diff is off here; these lines don't actually match

@transitive-bullshit
Copy link
Collaborator Author

transitive-bullshit commented Aug 7, 2024

@rileytomasek maybe we don't even need all of the Telemetry generics, and we just KISS? I was just trying to follow the existing pattern.

Copy link
Contributor

@rileytomasek rileytomasek left a comment

Choose a reason for hiding this comment

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

This is amazing — thanks @transitive-bullshit! I'll test it out locally in Dexa's codebase to see how it goes.

I'd rather drop all of the generics if possible, but will see if we actually need them and report back.

rileytomasek added a commit that referenced this pull request Aug 8, 2024
This is a simplified version of #46. It was easier to copy the important
parts and start clean than try and delete all of the generics code.

Replace the direct dependency on Sentry with the abstract `Telemetry`
interface from @transitive-bullshit. This should have no impact on
users who weren't using the Sentry integration, and requires passing
Sentry as an argument when creating a model instance.

```ts
import { ChatModel } from '@dexaai/dexter'
import * as Sentry from '@sentry/node'

const model = new ChatModel({ telemetry: Sentry })
```
@rileytomasek
Copy link
Contributor

@transitive-bullshit I tested locally against Dexa source and there were no issues 👌🏻.

I can't think of a scenario where we need the generics for Telemetry and it makes a pretty big mess of the code. It was easier to start from scratch so I just opened #47 with the simplified version.

rileytomasek added a commit that referenced this pull request Aug 9, 2024
* Add telemetry abstraction to remove Sentry dep

This is a simplified version of #46. It was easier to copy the important
parts and start clean than try and delete all of the generics code.

Replace the direct dependency on Sentry with the abstract `Telemetry`
interface from @transitive-bullshit. This should have no impact on
users who weren't using the Sentry integration, and requires passing
Sentry as an argument when creating a model instance.

```ts
import { ChatModel } from '@dexaai/dexter'
import * as Sentry from '@sentry/node'

const model = new ChatModel({ telemetry: Sentry })
```

* Rename `Telemetry.Base` to `Telemetry.Provider`
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.

2 participants