Skip to content

Commit b5c9edc

Browse files
Kyle-Verhooglievankayayaraignufede
authored
feat(openai): add OpenAI integration [backport #5488 to 1.13] (#5674)
Add an integration for the [OpenAI library](https://github.com/openai/openai-python). This integration provides tracing for the completion, embeddings and chat completion endpoints along with cost estimation metrics and prompt/completion sampling logs. Each log, metric and trace are tagged with service, env, version, OpenAI model, OpenAI endpoint and OpenAI organization. [Docs preview](https://output.circle-artifacts.com/output/job/fe3599b8-952e-4ceb-ac4f-0f15503e9c0d/artifacts/0/tmp/docs/integrations.html#openai) ## Design ### Logs A new log writer implementation is added to submit logs. Logs are submitted direct to intake following a similar approach that [kyle-verhoog/datadog-python](https://github.com/Kyle-Verhoog/datadog-python/blob/main/datadog/_logging.py) and the [.NET tracer](DataDog/dd-trace-dotnet#2240) have taken already. ### Metrics A statsd client is used specifically for the OpenAI integration. ## Testing Testing is done using VCR to record requests made to OpenAI to ensure ease, consistency and reliability in test cases. Logs and metrics are tested using mocking of the clients. Several integration tests using snapshots and subprocess testing ensure that the integration works in a real world OpenAI application. A manual test app was also used: https://gist.github.com/Kyle-Verhoog/1f263ed0aade076b313167d1ba3bfa16 ## Risk - Currently, logs, traces and metrics are all collected, buffered and sent individually through their respective pipelines. Due to this, there is risk that disparity occurs between the tagging and submission of the data. There is also a performance risk as this data is not aggregated or batched when submitted. - Prompts and completions are captured on spans by default with a default limit on the length of the data. This limit only applies to each prompt/completion individually but requests can contain several prompts and completions. If there are many prompts and completions of great length then there is a risk of performance overhead of encoding and transmitting the data. - Logs and metrics clients are specified specifically for this integration. If another integration were to introduce logs then there would be a need for another log writer. Having several log writers could induce thread contention and high memory usage. Co-authored-by: lievan <[email protected]> Co-authored-by: Kari Halsted <[email protected]> Co-authored-by: Federico Mon <[email protected]>
1 parent b1a1212 commit b5c9edc

File tree

66 files changed

+5618
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5618
-3
lines changed

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ jobs:
372372
- run_test:
373373
pattern: "debugger"
374374

375+
openai:
376+
<<: *machine_executor
377+
parallelism: 4
378+
steps:
379+
- run_test:
380+
pattern: 'openai'
381+
snapshot: true
382+
375383
opentracer:
376384
<<: *contrib_job
377385
steps:
@@ -1072,6 +1080,7 @@ requires_tests: &requires_tests
10721080
- mongoengine
10731081
- mysqlconnector
10741082
- mysqlpython
1083+
- openai
10751084
- opentracer
10761085
- opentelemetry
10771086
- psycopg
@@ -1171,6 +1180,7 @@ workflows:
11711180
- mongoengine: *requires_base_venvs
11721181
- mysqlconnector: *requires_base_venvs
11731182
- mysqlpython: *requires_base_venvs
1183+
- openai: *requires_base_venvs
11741184
- opentracer: *requires_base_venvs
11751185
- opentelemetry: *requires_base_venvs
11761186
- psycopg: *requires_base_venvs

.riot/requirements/11fafab.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/11fafab.in
6+
#
7+
aiohttp==3.8.4
8+
aiosignal==1.3.1
9+
async-timeout==4.0.2
10+
attrs==23.1.0
11+
certifi==2022.12.7
12+
charset-normalizer==3.1.0
13+
contourpy==1.0.7
14+
coverage[toml]==7.2.3
15+
cycler==0.11.0
16+
et-xmlfile==1.1.0
17+
exceptiongroup==1.1.1
18+
fonttools==4.39.3
19+
frozenlist==1.3.3
20+
hypothesis==6.45.0
21+
idna==3.4
22+
iniconfig==2.0.0
23+
joblib==1.2.0
24+
kiwisolver==1.4.4
25+
matplotlib==3.7.1
26+
mock==5.0.2
27+
multidict==6.0.4
28+
numpy==1.24.3
29+
openai[embeddings]==0.27.2
30+
openpyxl==3.1.2
31+
opentracing==2.4.0
32+
packaging==23.1
33+
pandas==2.0.1
34+
pandas-stubs==2.0.0.230412
35+
pillow==9.5.0
36+
plotly==5.14.1
37+
pluggy==1.0.0
38+
pyparsing==3.0.9
39+
pytest==7.3.1
40+
pytest-asyncio==0.21.0
41+
pytest-cov==4.0.0
42+
pytest-mock==3.10.0
43+
python-dateutil==2.8.2
44+
pytz==2023.3
45+
pyyaml==6.0
46+
requests==2.29.0
47+
scikit-learn==1.2.2
48+
scipy==1.10.1
49+
six==1.16.0
50+
sortedcontainers==2.4.0
51+
tenacity==8.2.2
52+
threadpoolctl==3.1.0
53+
tomli==2.0.1
54+
tqdm==4.65.0
55+
types-pytz==2023.3.0.0
56+
tzdata==2023.3
57+
urllib3==1.26.15
58+
vcrpy==4.2.1
59+
wrapt==1.15.0
60+
yarl==1.9.2

.riot/requirements/1522688.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1522688.in
6+
#
7+
aiohttp==3.8.4
8+
aiosignal==1.3.1
9+
async-timeout==4.0.2
10+
attrs==23.1.0
11+
certifi==2022.12.7
12+
charset-normalizer==3.1.0
13+
contourpy==1.0.7
14+
coverage[toml]==7.2.3
15+
cycler==0.11.0
16+
et-xmlfile==1.1.0
17+
fonttools==4.39.3
18+
frozenlist==1.3.3
19+
hypothesis==6.45.0
20+
idna==3.4
21+
iniconfig==2.0.0
22+
joblib==1.2.0
23+
kiwisolver==1.4.4
24+
matplotlib==3.7.1
25+
mock==5.0.2
26+
multidict==6.0.4
27+
numpy==1.24.3
28+
openai[embeddings]==0.27.3
29+
openpyxl==3.1.2
30+
opentracing==2.4.0
31+
packaging==23.1
32+
pandas==2.0.1
33+
pandas-stubs==2.0.0.230412
34+
pillow==9.5.0
35+
plotly==5.14.1
36+
pluggy==1.0.0
37+
pyparsing==3.0.9
38+
pytest==7.3.1
39+
pytest-asyncio==0.21.0
40+
pytest-cov==4.0.0
41+
pytest-mock==3.10.0
42+
python-dateutil==2.8.2
43+
pytz==2023.3
44+
pyyaml==6.0
45+
requests==2.29.0
46+
scikit-learn==1.2.2
47+
scipy==1.10.1
48+
six==1.16.0
49+
sortedcontainers==2.4.0
50+
tenacity==8.2.2
51+
threadpoolctl==3.1.0
52+
tqdm==4.65.0
53+
types-pytz==2023.3.0.0
54+
tzdata==2023.3
55+
urllib3==1.26.15
56+
vcrpy==4.2.1
57+
wrapt==1.15.0
58+
yarl==1.9.2

.riot/requirements/16cc6d6.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/16cc6d6.in
6+
#
7+
aiohttp==3.8.4
8+
aiosignal==1.3.1
9+
async-timeout==4.0.2
10+
attrs==23.1.0
11+
certifi==2022.12.7
12+
charset-normalizer==3.1.0
13+
contourpy==1.0.7
14+
coverage[toml]==7.2.3
15+
cycler==0.11.0
16+
et-xmlfile==1.1.0
17+
fonttools==4.39.3
18+
frozenlist==1.3.3
19+
hypothesis==6.45.0
20+
idna==3.4
21+
iniconfig==2.0.0
22+
joblib==1.2.0
23+
kiwisolver==1.4.4
24+
matplotlib==3.7.1
25+
mock==5.0.2
26+
multidict==6.0.4
27+
numpy==1.24.3
28+
openai[embeddings]==0.27.4
29+
openpyxl==3.1.2
30+
opentracing==2.4.0
31+
packaging==23.1
32+
pandas==2.0.1
33+
pandas-stubs==2.0.0.230412
34+
pillow==9.5.0
35+
plotly==5.14.1
36+
pluggy==1.0.0
37+
pyparsing==3.0.9
38+
pytest==7.3.1
39+
pytest-asyncio==0.21.0
40+
pytest-cov==4.0.0
41+
pytest-mock==3.10.0
42+
python-dateutil==2.8.2
43+
pytz==2023.3
44+
pyyaml==6.0
45+
requests==2.29.0
46+
scikit-learn==1.2.2
47+
scipy==1.10.1
48+
six==1.16.0
49+
sortedcontainers==2.4.0
50+
tenacity==8.2.2
51+
threadpoolctl==3.1.0
52+
tqdm==4.65.0
53+
types-pytz==2023.3.0.0
54+
tzdata==2023.3
55+
urllib3==1.26.15
56+
vcrpy==4.2.1
57+
wrapt==1.15.0
58+
yarl==1.9.2

.riot/requirements/17ab8b6.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/17ab8b6.in
6+
#
7+
aiohttp==3.8.4
8+
aiosignal==1.3.1
9+
async-timeout==4.0.2
10+
attrs==23.1.0
11+
certifi==2022.12.7
12+
charset-normalizer==3.1.0
13+
contourpy==1.0.7
14+
coverage[toml]==7.2.3
15+
cycler==0.11.0
16+
et-xmlfile==1.1.0
17+
exceptiongroup==1.1.1
18+
fonttools==4.39.3
19+
frozenlist==1.3.3
20+
hypothesis==6.45.0
21+
idna==3.4
22+
importlib-resources==5.12.0
23+
iniconfig==2.0.0
24+
joblib==1.2.0
25+
kiwisolver==1.4.4
26+
matplotlib==3.7.1
27+
mock==5.0.2
28+
multidict==6.0.4
29+
numpy==1.24.3
30+
openai[embeddings]==0.27.3
31+
openpyxl==3.1.2
32+
opentracing==2.4.0
33+
packaging==23.1
34+
pandas==2.0.1
35+
pandas-stubs==2.0.0.230412
36+
pillow==9.5.0
37+
plotly==5.14.1
38+
pluggy==1.0.0
39+
pyparsing==3.0.9
40+
pytest==7.3.1
41+
pytest-asyncio==0.21.0
42+
pytest-cov==4.0.0
43+
pytest-mock==3.10.0
44+
python-dateutil==2.8.2
45+
pytz==2023.3
46+
pyyaml==6.0
47+
requests==2.29.0
48+
scikit-learn==1.2.2
49+
scipy==1.10.1
50+
six==1.16.0
51+
sortedcontainers==2.4.0
52+
tenacity==8.2.2
53+
threadpoolctl==3.1.0
54+
tomli==2.0.1
55+
tqdm==4.65.0
56+
types-pytz==2023.3.0.0
57+
tzdata==2023.3
58+
urllib3==1.26.15
59+
vcrpy==4.2.1
60+
wrapt==1.15.0
61+
yarl==1.9.2
62+
zipp==3.15.0

.riot/requirements/180d9c4.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/180d9c4.in
6+
#
7+
aiohttp==3.8.4
8+
aiosignal==1.3.1
9+
async-timeout==4.0.2
10+
attrs==23.1.0
11+
certifi==2022.12.7
12+
charset-normalizer==3.1.0
13+
contourpy==1.0.7
14+
coverage[toml]==7.2.3
15+
cycler==0.11.0
16+
et-xmlfile==1.1.0
17+
exceptiongroup==1.1.1
18+
fonttools==4.39.3
19+
frozenlist==1.3.3
20+
hypothesis==6.45.0
21+
idna==3.4
22+
importlib-resources==5.12.0
23+
iniconfig==2.0.0
24+
joblib==1.2.0
25+
kiwisolver==1.4.4
26+
matplotlib==3.7.1
27+
mock==5.0.2
28+
multidict==6.0.4
29+
numpy==1.24.3
30+
openai[embeddings]==0.27.2
31+
openpyxl==3.1.2
32+
opentracing==2.4.0
33+
packaging==23.1
34+
pandas==2.0.1
35+
pandas-stubs==2.0.0.230412
36+
pillow==9.5.0
37+
plotly==5.14.1
38+
pluggy==1.0.0
39+
pyparsing==3.0.9
40+
pytest==7.3.1
41+
pytest-asyncio==0.21.0
42+
pytest-cov==4.0.0
43+
pytest-mock==3.10.0
44+
python-dateutil==2.8.2
45+
pytz==2023.3
46+
pyyaml==6.0
47+
requests==2.29.0
48+
scikit-learn==1.2.2
49+
scipy==1.10.1
50+
six==1.16.0
51+
sortedcontainers==2.4.0
52+
tenacity==8.2.2
53+
threadpoolctl==3.1.0
54+
tomli==2.0.1
55+
tqdm==4.65.0
56+
types-pytz==2023.3.0.0
57+
tzdata==2023.3
58+
urllib3==1.26.15
59+
vcrpy==4.2.1
60+
wrapt==1.15.0
61+
yarl==1.9.2
62+
zipp==3.15.0

.riot/requirements/1a7e69a.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1a7e69a.in
6+
#
7+
aiohttp==3.8.4
8+
aiosignal==1.3.1
9+
async-timeout==4.0.2
10+
attrs==23.1.0
11+
certifi==2022.12.7
12+
charset-normalizer==3.1.0
13+
contourpy==1.0.7
14+
coverage[toml]==7.2.3
15+
cycler==0.11.0
16+
et-xmlfile==1.1.0
17+
exceptiongroup==1.1.1
18+
fonttools==4.39.3
19+
frozenlist==1.3.3
20+
hypothesis==6.45.0
21+
idna==3.4
22+
importlib-resources==5.12.0
23+
iniconfig==2.0.0
24+
joblib==1.2.0
25+
kiwisolver==1.4.4
26+
matplotlib==3.7.1
27+
mock==5.0.2
28+
multidict==6.0.4
29+
numpy==1.24.3
30+
openai[embeddings]==0.26.5
31+
openpyxl==3.1.2
32+
opentracing==2.4.0
33+
packaging==23.1
34+
pandas==2.0.1
35+
pandas-stubs==2.0.0.230412
36+
pillow==9.5.0
37+
plotly==5.14.1
38+
pluggy==1.0.0
39+
pyparsing==3.0.9
40+
pytest==7.3.1
41+
pytest-asyncio==0.21.0
42+
pytest-cov==4.0.0
43+
pytest-mock==3.10.0
44+
python-dateutil==2.8.2
45+
pytz==2023.3
46+
pyyaml==6.0
47+
requests==2.29.0
48+
scikit-learn==1.2.2
49+
scipy==1.10.1
50+
six==1.16.0
51+
sklearn==0.0.post4
52+
sortedcontainers==2.4.0
53+
tenacity==8.2.2
54+
threadpoolctl==3.1.0
55+
tomli==2.0.1
56+
tqdm==4.65.0
57+
types-pytz==2023.3.0.0
58+
tzdata==2023.3
59+
urllib3==1.26.15
60+
vcrpy==4.2.1
61+
wrapt==1.15.0
62+
yarl==1.9.2
63+
zipp==3.15.0

0 commit comments

Comments
 (0)