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-1524] feat(llmobs): Introduce LLM Observability SDK #4742

Merged
merged 20 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
30 changes: 30 additions & 0 deletions .github/workflows/llmobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: LLMObs
sabrenner marked this conversation as resolved.
Show resolved Hide resolved

on:
pull_request:
push:
branches: [master]
schedule:
- cron: '0 4 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
sabrenner marked this conversation as resolved.
Show resolved Hide resolved
- uses: ./.github/actions/testagent/start
- uses: ./.github/actions/node/setup
- uses: ./.github/actions/install
- uses: ./.github/actions/node/18
- run: yarn test:llmobs:ci
- uses: ./.github/actions/node/20
- run: yarn test:llmobs:ci
- uses: ./.github/actions/node/latest
- run: yarn test:llmobs:ci
- if: always()
uses: ./.github/actions/testagent/logs
- uses: codecov/codecov-action@v3
sabrenner marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
/packages/dd-trace/src/service-naming/ @Datadog/apm-idm-js
/packages/dd-trace/test/service-naming/ @Datadog/apm-idm-js

/packages/dd-trace/src/llmobs/ @DataDog/ml-observability
/packages/dd-trace/test/llmobs/ @DataDog/ml-observability

# CI
/.github/workflows/appsec.yml @DataDog/asm-js
/.github/workflows/ci-visibility-performance.yml @DataDog/ci-app-libraries
Expand Down
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"
}
}
90 changes: 90 additions & 0 deletions docs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,93 @@ 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 = {
mlApp: 'mlApp',
agentlessEnabled: true
}
tracer.init({
llmobs: llmobsEnableOptions,
})
const llmobs = tracer.llmobs
const enabled = llmobs.enabled

// manually enable
llmobs.enable({
mlApp: 'mlApp',
agentlessEnabled: true
})

// manually disable
llmobs.disable()

// 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 () {})()
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.trace({ kind: 'llm', name: 'myLLM' }, (span) => {
const llmobsSpanCtx = llmobs.exportSpan(span)
llmobsSpanCtx.traceId;
llmobsSpanCtx.spanId;

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

// annotate a span
llmobs.annotate({
inputData: 'input',
outputData: 'output',
metadata: {},
metrics: {
inputTokens: 10,
outputTokens: 5,
totalTokens: 15
},
tags: {}
})
llmobs.annotate(span, {
inputData: 'input',
outputData: 'output',
metadata: {},
metrics: {},
tags: {}
})



// flush
llmobs.flush()
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