-
Notifications
You must be signed in to change notification settings - Fork 586
feat(instrumentation-openai): add instrumentation of openai SDK #2941
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
base: main
Are you sure you want to change the base?
Conversation
}) | ||
).rejects.toThrow(OpenAI.APIConnectionError); | ||
|
||
// TODO: Figure out why it takes so long to get this span. trace.getTracerProvider()._delegate.forceFlush() didn't help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use some help debugging this
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2941 +/- ##
==========================================
- Coverage 89.06% 89.03% -0.03%
==========================================
Files 188 191 +3
Lines 9219 9550 +331
Branches 1900 1977 +77
==========================================
+ Hits 8211 8503 +292
- Misses 1008 1047 +39
🚀 New features to boost your workflow:
|
nx.json
Outdated
@@ -31,6 +31,9 @@ | |||
] | |||
}, | |||
"lint": { | |||
"dependsOn": [ | |||
"version:update", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure on this infrastructure change but I couldn't think of another way to solve
> npx --yes [email protected] --dependencies --production --tags=-knipignore
Unresolved imports (1)
./version packages/instrumentation-openai/src/instrumentation.ts:70:9
Error: Process completed with exit code 1.
I notice there's some cache setup so I wonder if the existing projects are passing thanks to caching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what has been done for the other packages:
diff --git a/packages/instrumentation-openai/src/instrumentation.ts b/packages/instrumentation-openai/src/instrumentation.ts
index 6b7d3abf..c448b918 100644
--- a/packages/instrumentation-openai/src/instrumentation.ts
+++ b/packages/instrumentation-openai/src/instrumentation.ts
@@ -67,6 +67,7 @@ import {
METRIC_GEN_AI_CLIENT_OPERATION_DURATION,
METRIC_GEN_AI_CLIENT_TOKEN_USAGE,
} from './semconv';
+/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import { getEnvBool, getAttrsFromBaseURL } from './utils';
import { OpenAIInstrumentationConfig } from './types';
Let's do that instead so we can avoid the version:update
time for linting in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting this, Anuraag. This is just a quick start at looking. I haven't looked at src/ or test/ yet.
}, | ||
"scripts": { | ||
"clean": "rimraf build/*", | ||
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-sdk", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-sdk", | |
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-openai", |
"lint:readme": "node ../../scripts/lint-readme.js", | ||
"prepublishOnly": "npm run compile", | ||
"tdd": "npm run test -- --watch-extensions ts --watch", | ||
"test": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't dug into the tests yet. Are the tests relying on the require-hook environment setup from contrib-test-utils? Or could this be copy-pasta?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah they currently are. When debugging #2941 (comment) too TBH I did find it a bit confusing to be out-of-control of the lifecycle of the tracer provider but thought it's the pattern for the repo. Let me know if it's better to manually set it up
"@opentelemetry/api": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"@opentelemetry/api": "^1.9.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if dev usage really does require the newer API version than the runtime (peerDep).
}, | ||
"devDependencies": { | ||
"@opentelemetry/api": "^1.9.0", | ||
"@opentelemetry/context-async-hooks": "^2.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"@opentelemetry/context-async-hooks": "^2.0.0", |
"cross-env": "7.0.3", | ||
"nock": "^14.0.0", | ||
"nyc": "17.1.0", | ||
"openai": "4.57.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps bump this to 4.104.0
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/open-telemetry/opentelemetry-js-contrib.git", | ||
"directory": "packages/instrumentation-oracledb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"directory": "packages/instrumentation-oracledb" | |
"directory": "packages/instrumentation-openai" |
nx.json
Outdated
@@ -31,6 +31,9 @@ | |||
] | |||
}, | |||
"lint": { | |||
"dependsOn": [ | |||
"version:update", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what has been done for the other packages:
diff --git a/packages/instrumentation-openai/src/instrumentation.ts b/packages/instrumentation-openai/src/instrumentation.ts
index 6b7d3abf..c448b918 100644
--- a/packages/instrumentation-openai/src/instrumentation.ts
+++ b/packages/instrumentation-openai/src/instrumentation.ts
@@ -67,6 +67,7 @@ import {
METRIC_GEN_AI_CLIENT_OPERATION_DURATION,
METRIC_GEN_AI_CLIENT_TOKEN_USAGE,
} from './semconv';
+/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import { getEnvBool, getAttrsFromBaseURL } from './utils';
import { OpenAIInstrumentationConfig } from './types';
Let's do that instead so we can avoid the version:update
time for linting in CI.
Which problem is this PR solving?
Short description of the changes
Future PRs will add support for responses API and SDK 5
/cc @trentm if you can help review
/cc @lmolkova because I heard you are also interested in this instrumentation. Notably, I'd like this instrumentation to exist upstream so people can use it but need potential component owners I believe
This instrumentation is adapted from the one in https://github.com/elastic/elastic-otel-node/tree/main/packages/instrumentation-openai