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

[MLOB-1561] LLM Observability SDK API #4773

Merged
merged 36 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a451f5d
wip
sabrenner Oct 3, 2024
c57f22a
type definitions
sabrenner Oct 3, 2024
8507034
active + try/catch eval metric writer append
sabrenner Oct 3, 2024
e58f30e
test ts
sabrenner Oct 6, 2024
3a50ca4
use tagger map and processor as a channel subscriber
sabrenner Oct 8, 2024
e11d5ae
change decorate and add in dev changes
sabrenner Oct 10, 2024
031559b
Merge branch 'sabrenner/llmobs-sdk-release' of github.com:DataDog/dd-…
sabrenner Oct 10, 2024
db8e2eb
try some api changes
sabrenner Oct 11, 2024
a4001d5
add decorate to noop
sabrenner Oct 11, 2024
ca22dff
fix breaking proxy tests
sabrenner Oct 11, 2024
e02c993
experimental decorators for TS docs
sabrenner Oct 11, 2024
bcebeac
api changes, fix unit + e2e tests
sabrenner Oct 15, 2024
b2d4216
try removing global log mocks
sabrenner Oct 15, 2024
622f54f
add some util tests
sabrenner Oct 15, 2024
dbe664d
remove logger mocks
sabrenner Oct 15, 2024
00d4572
add module tests + do not enable when not specified
sabrenner Oct 15, 2024
ad28001
fix eval metric integration test
sabrenner Oct 16, 2024
9d68a0c
wip
sabrenner Oct 16, 2024
20a5ab1
memoize getFunctionArguments
sabrenner Oct 16, 2024
b400b1c
move any subscriber and global writer to the module enablement level …
sabrenner Oct 16, 2024
d902720
Merge branch 'sabrenner/llmobs-sdk-release' of github.com:DataDog/dd-…
sabrenner Oct 16, 2024
4c167ed
should fix TS tests
sabrenner Oct 16, 2024
3c8b1d7
add ts integration test and fix decorator
sabrenner Oct 16, 2024
9ed2f5e
Merge branch 'sabrenner/llmobs-sdk-release' into sabrenner/llmobs-sdk…
sabrenner Oct 16, 2024
8a0374a
devex for ts versions
sabrenner Oct 16, 2024
040d04a
add noop typescript test
sabrenner Oct 17, 2024
745d4ae
remove startSpan
sabrenner Oct 17, 2024
79f0d07
remove unneeded change
sabrenner Oct 17, 2024
7c7a328
dedup decorator code
sabrenner Oct 17, 2024
49c20e8
Update index.d.ts
sabrenner Oct 24, 2024
24396eb
map metrics names
sabrenner Oct 24, 2024
af823ba
change validKind to validateKind and throw
sabrenner Oct 24, 2024
854afef
tagger for metrics follow-up
sabrenner Oct 24, 2024
379fbf7
review feedback
sabrenner Oct 24, 2024
c65b8b0
Merge branch 'sabrenner/llmobs-sdk-sdk' of github.com:DataDog/dd-trac…
sabrenner Oct 24, 2024
e6562f0
add some tests for not auto-annotating in certain cases
sabrenner Oct 24, 2024
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
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"private": true,
"devDependencies": {
"typedoc": "^0.25.8",
"typescript": "^4.6"
"typescript": "^5.0"
}
}
102 changes: 102 additions & 0 deletions docs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,105 @@ const otelTraceId: string = spanContext.traceId
const otelSpanId: string = spanContext.spanId
const otelTraceFlags: number = spanContext.traceFlags
const otelTraceState: opentelemetry.TraceState = spanContext.traceState!

// -- LLM Observability --
const llmobsEnableOptions = {
apiKey: 'dd-api-key',
mlApp: 'mlApp',
agentlessEnabled: true
}
tracer.init({
llmobs: llmobsEnableOptions,
experimental: {
llmobs: llmobsEnableOptions
}
})
const llmobs = tracer.llmobs
const enabled = llmobs.enabled

// manually enable
llmobs.enable({
apiKey: 'dd-api-key',
mlApp: 'mlApp',
agentlessEnabled: true
})

// manually disable
llmobs.disable()

// start span in current context
llmobs.startSpan({ name: 'name', kind: 'llm' })
llmobs.startSpan({ name: 'name', kind: 'embedding'})
llmobs.startSpan({ name: 'name', kind: 'agent'})
llmobs.startSpan({ name: 'name', kind: 'retrieval'})
llmobs.startSpan({ name: 'name', kind: 'task'})
llmobs.startSpan({ name: 'name', kind: 'tool'})
llmobs.startSpan({ name: 'name', kind: 'workflow'})

// trace block of code
llmobs.trace({ name: 'name', kind: 'llm' }, () => {})
llmobs.trace({ kind: 'llm', name: 'myLLM', modelName: 'myModel', modelProvider: 'myProvider' }, () => {})
llmobs.trace({ name: 'name', kind: 'llm' }, (span, cb) => {
llmobs.annotate(span, {})
span.setTag('foo', 'bar')
cb(new Error('boom'))
})

// wrap a function
llmobs.wrap({ kind: 'llm' }, function myLLM () {
const s = llmobs.active()
llmobs.annotate(s, {})
})()
llmobs.wrap({ kind: 'llm', name: 'myLLM', modelName: 'myModel', modelProvider: 'myProvider' }, function myFunction () {})()

// decorate a function
class MyClass {
@llmobs.decorate({ kind: 'llm' })
myLLM () {}

@llmobs.decorate({ kind: 'llm', name: 'myOtherLLM', modelName: 'myModel', modelProvider: 'myProvider' })
myOtherLLM () {}
}

const cls = new MyClass()
cls.myLLM()
cls.myOtherLLM()

// export a span
llmobs.enable({ mlApp: 'myApp' })
llmobs.exportSpan()
const llmobsSpanCtx = llmobs.exportSpan(llmobs.startSpan({ name: 'name', kind: 'llm' }))
llmobsSpanCtx.traceId;
llmobsSpanCtx.spanId;

// annotate a span
llmobs.annotate({
inputData: 'input',
outputData: 'output',
metadata: {},
metrics: {},
tags: {}
})
llmobs.annotate(span, {
inputData: 'input',
outputData: 'output',
metadata: {},
metrics: {},
tags: {}
})

// submit evaluation
llmobs.disable()
llmobs.submitEvaluation(llmobsSpanCtx, {
label: 'my-eval-metric',
metricType: 'categorical',
value: 'good',
mlApp: 'myApp',
tags: {},
timestampMs: Date.now()
})

// flush
llmobs.flush()

const llmobsSpan: Span | undefined = llmobs.active()
2 changes: 1 addition & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"moduleResolution": "node",
"module": "commonjs",
"baseUrl": ".",
"strict": true
"strict": true,
},
"files": [
"../index.d.ts"
Expand Down
8 changes: 4 additions & 4 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ typedoc@^0.25.8:
minimatch "^9.0.3"
shiki "^0.14.7"

typescript@^4.6:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
typescript@^5.0:
version "5.6.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b"
integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==

vscode-oniguruma@^1.7.0:
version "1.7.0"
Expand Down
Loading
Loading