-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry abstraction to remove Sentry dep (round 2) (#47)
* 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`
- Loading branch information
1 parent
61c85a6
commit 123d46e
Showing
15 changed files
with
220 additions
and
100 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as Sentry from '@sentry/node'; | ||
|
||
/** | ||
* Configure Sentry for tracing. | ||
* Ensure to call this before importing any other modules! | ||
*/ | ||
Sentry.init({ | ||
dsn: process.env.SENTRY_DSN!, | ||
tracesSampleRate: 1.0, | ||
debug: true, | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import './instrument.js'; | ||
import 'dotenv/config'; | ||
import { ChatModel } from '@dexaai/dexter'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
const chatModel = new ChatModel({ | ||
// Send tracing data to Sentry | ||
telemetry: Sentry, | ||
params: { model: 'gpt-4o-mini' }, | ||
}); | ||
|
||
async function main() { | ||
const result = await chatModel.run({ | ||
messages: [{ role: 'user', content: 'Tell me a short joke' }], | ||
}); | ||
console.log(result); | ||
} | ||
|
||
main().catch(console.error); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,8 +98,5 @@ | |
"vite": "^5.2.11", | ||
"vitest": "^1.6.0" | ||
}, | ||
"peerDependencies": { | ||
"@sentry/node": "8.x" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Telemetry } from './types.js'; | ||
|
||
export const DefaultTelemetry: Telemetry.Provider = { | ||
startSpan<T>( | ||
_options: Telemetry.SpanOptions, | ||
callback: (span: Telemetry.Span) => T | ||
): T { | ||
return callback({ | ||
setAttribute() { | ||
// no-op | ||
return this; | ||
}, | ||
setAttributes() { | ||
// no-op | ||
return this; | ||
}, | ||
}); | ||
}, | ||
|
||
setTags() { | ||
// no-op | ||
}, | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type { Telemetry } from './types.js'; | ||
export { DefaultTelemetry } from './default-telemetry.js'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import type { Telemetry } from './types.js'; | ||
|
||
test('Sentry Telemetry Provider', () => { | ||
expectTypeOf(Sentry).toMatchTypeOf<Telemetry.Provider>(); | ||
}); |
Oops, something went wrong.