-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into run-stores
- Loading branch information
Showing
95 changed files
with
4,762 additions
and
246 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
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,50 @@ | ||
'use strict' | ||
|
||
const { | ||
channel, | ||
addHook | ||
} = require('./helpers/instrument') | ||
const shimmer = require('../../datadog-shimmer') | ||
|
||
const startCh = channel('apm:openai:request:start') | ||
const finishCh = channel('apm:openai:request:finish') | ||
const errorCh = channel('apm:openai:request:error') | ||
|
||
addHook({ name: 'openai', file: 'dist/api.js', versions: ['>=3.0.0'] }, exports => { | ||
const methodNames = Object.getOwnPropertyNames(exports.OpenAIApi.prototype) | ||
methodNames.shift() // remove leading 'constructor' method | ||
|
||
for (const methodName of methodNames) { | ||
shimmer.wrap(exports.OpenAIApi.prototype, methodName, fn => function () { | ||
if (!startCh.hasSubscribers) { | ||
return fn.apply(this, arguments) | ||
} | ||
|
||
startCh.publish({ | ||
methodName, | ||
args: arguments, | ||
basePath: this.basePath, | ||
apiKey: this.configuration.apiKey | ||
}) | ||
|
||
return fn.apply(this, arguments) | ||
.then((response) => { | ||
finishCh.publish({ | ||
headers: response.headers, | ||
body: response.data, | ||
path: response.request.path, | ||
method: response.request.method | ||
}) | ||
|
||
return response | ||
}) | ||
.catch((err) => { | ||
errorCh.publish({ err }) | ||
|
||
throw err | ||
}) | ||
}) | ||
} | ||
|
||
return exports | ||
}) |
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
Oops, something went wrong.