Skip to content

Commit 17edad3

Browse files
committed
elastic-opentelemetry-instrumentation-openai: rewrite tests in pytest style
And start testing against azure openai. I've simplified env variables needed for vcr recordings to these: * `OPENAI_API_KEY`, with project tokens no need for the others And for azure these ones that are available for cut and paste from the interface: * `AZURE_CHAT_COMPLETIONS_DEPLOYMENT_URL` * `AZURE_CHAT_COMPLETIONS_API_KEY` * `AZURE_EMBEDDINGS_DEPLOYMENT_URL` * `AZURE_EMBEDDINGS_API_KEY`
1 parent e02823b commit 17edad3

File tree

67 files changed

+6869
-3545
lines changed

Some content is hidden

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

67 files changed

+6869
-3545
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
test:
3939
runs-on: ubuntu-latest
4040
env:
41-
py38: 3.8
42-
py39: 3.9
41+
py38: "3.8"
42+
py39: "3.9"
4343
py310: "3.10"
4444
py311: "3.11"
4545
py312: "3.12"
@@ -55,7 +55,11 @@ jobs:
5555
with:
5656
python-version: ${{ env[matrix.python-version] }}
5757
architecture: "x64"
58-
- run: pip install -r dev-requirements.txt
58+
- if: ${{ env[matrix.python-version] == "3.8" && env[matrix.python-version] == "3.9" }}
59+
run: pip install -r dev-requirements-3.9.txt
60+
working-directory: ${{ matrix.working-dir }}
61+
- if: ${{ env[matrix.python-version] != "3.8" && env[matrix.python-version] != "3.9" }}
62+
run: pip install -r dev-requirements.txt
5963
working-directory: ${{ matrix.working-dir }}
6064
- run: pytest
6165
working-directory: ${{ matrix.working-dir }}

instrumentation/elastic-opentelemetry-instrumentation-openai/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ However, unit test recordings should use the authoritative OpenAI platform unles
8585
about a specific portability corner case.
8686

8787
To refresh a test, delete its cassette file in tests/cassettes and make sure you have the
88-
following environment variables set:
88+
following environment variables set for OpenAI recordings:
8989

9090
* `OPENAI_API_KEY` - from https://platform.openai.com/settings/profile?tab=api-keys
9191
* It should look like `sk-...`
92-
* `OPENAI_ORG_ID` - from https://platform.openai.com/settings/organization/general
93-
* It should look like `org-...`
94-
* `OPENAI_PROJECT_ID` - from https://platform.openai.com/settings/profile (click Project)
95-
* It should look like `proj_...`
92+
93+
and the following for Azure recordings, deployment url and api key are available for each deployment
94+
in https://oai.azure.com/resource/deployments:
95+
96+
* `AZURE_CHAT_COMPLETIONS_DEPLOYMENT_URL`
97+
* `AZURE_CHAT_COMPLETIONS_API_KEY`
98+
* `AZURE_EMBEDDINGS_DEPLOYMENT_URL`
99+
* `AZURE_EMBEDDINGS_API_KEY`
96100

97101
If writing a new test, start with the test logic with no assertions. If extending an existing unit test
98102
rather than writing a new one, remove the corresponding recorded response from [cassettes](./tests/cassettes/)
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --extra=dev --output-file=dev-requirements-3.9.txt --strip-extras pyproject.toml
6+
#
7+
annotated-types==0.7.0
8+
# via pydantic
9+
anyio==4.5.2
10+
# via
11+
# httpx
12+
# openai
13+
asgiref==3.8.1
14+
# via opentelemetry-test-utils
15+
build==1.2.2.post1
16+
# via pip-tools
17+
certifi==2024.8.30
18+
# via
19+
# httpcore
20+
# httpx
21+
click==8.1.7
22+
# via pip-tools
23+
deprecated==1.2.14
24+
# via
25+
# opentelemetry-api
26+
# opentelemetry-semantic-conventions
27+
distro==1.9.0
28+
# via openai
29+
exceptiongroup==1.2.2
30+
# via
31+
# anyio
32+
# pytest
33+
h11==0.14.0
34+
# via httpcore
35+
httpcore==1.0.6
36+
# via httpx
37+
httpx==0.27.2
38+
# via openai
39+
idna==3.10
40+
# via
41+
# anyio
42+
# httpx
43+
# yarl
44+
importlib-metadata==8.5.0
45+
# via
46+
# build
47+
# opentelemetry-api
48+
iniconfig==2.0.0
49+
# via pytest
50+
jiter==0.7.1
51+
# via openai
52+
multidict==6.1.0
53+
# via yarl
54+
numpy==1.24.4
55+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
56+
openai==1.54.4
57+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
58+
opentelemetry-api==1.28.1
59+
# via
60+
# elastic-opentelemetry-instrumentation-openai (pyproject.toml)
61+
# opentelemetry-instrumentation
62+
# opentelemetry-sdk
63+
# opentelemetry-semantic-conventions
64+
# opentelemetry-test-utils
65+
opentelemetry-instrumentation==0.49b1
66+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
67+
opentelemetry-sdk==1.28.1
68+
# via opentelemetry-test-utils
69+
opentelemetry-semantic-conventions==0.49b1
70+
# via
71+
# elastic-opentelemetry-instrumentation-openai (pyproject.toml)
72+
# opentelemetry-instrumentation
73+
# opentelemetry-sdk
74+
opentelemetry-test-utils==0.49b1
75+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
76+
packaging==24.2
77+
# via
78+
# build
79+
# opentelemetry-instrumentation
80+
# pytest
81+
pip-tools==7.4.1
82+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
83+
pluggy==1.5.0
84+
# via pytest
85+
propcache==0.2.0
86+
# via yarl
87+
pydantic==2.9.2
88+
# via openai
89+
pydantic-core==2.23.4
90+
# via pydantic
91+
pyproject-hooks==1.2.0
92+
# via
93+
# build
94+
# pip-tools
95+
pytest==8.3.3
96+
# via
97+
# elastic-opentelemetry-instrumentation-openai (pyproject.toml)
98+
# pytest-asyncio
99+
# pytest-vcr
100+
pytest-asyncio==0.24.0
101+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
102+
pytest-vcr==1.0.2
103+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
104+
pyyaml==6.0.2
105+
# via vcrpy
106+
sniffio==1.3.1
107+
# via
108+
# anyio
109+
# httpx
110+
# openai
111+
tomli==2.1.0
112+
# via
113+
# build
114+
# pip-tools
115+
# pytest
116+
tqdm==4.67.0
117+
# via openai
118+
typing-extensions==4.12.2
119+
# via
120+
# annotated-types
121+
# anyio
122+
# asgiref
123+
# multidict
124+
# openai
125+
# opentelemetry-sdk
126+
# pydantic
127+
# pydantic-core
128+
urllib3==1.26.20
129+
# via vcrpy
130+
vcrpy==6.0.2
131+
# via
132+
# elastic-opentelemetry-instrumentation-openai (pyproject.toml)
133+
# pytest-vcr
134+
wheel==0.45.0
135+
# via pip-tools
136+
wrapt==1.16.0
137+
# via
138+
# deprecated
139+
# opentelemetry-instrumentation
140+
# vcrpy
141+
yarl==1.15.2
142+
# via vcrpy
143+
zipp==3.20.2
144+
# via importlib-metadata
145+
146+
# The following packages are considered to be unsafe in a requirements file:
147+
# pip
148+
# setuptools

instrumentation/elastic-opentelemetry-instrumentation-openai/dev-requirements.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jiter==0.5.0
4949
# via openai
5050
multidict==6.1.0
5151
# via yarl
52+
numpy==2.1.3
53+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
5254
openai==1.50.2
5355
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
5456
opentelemetry-api==1.27.0
@@ -85,6 +87,13 @@ pyproject-hooks==1.1.0
8587
# build
8688
# pip-tools
8789
pytest==8.3.3
90+
# via
91+
# elastic-opentelemetry-instrumentation-openai (pyproject.toml)
92+
# pytest-asyncio
93+
# pytest-vcr
94+
pytest-asyncio==0.24.0
95+
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
96+
pytest-vcr==1.0.2
8897
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
8998
pyyaml==6.0.2
9099
# via vcrpy
@@ -110,7 +119,9 @@ typing-extensions==4.12.2
110119
# pydantic
111120
# pydantic-core
112121
vcrpy==6.0.1
113-
# via elastic-opentelemetry-instrumentation-openai (pyproject.toml)
122+
# via
123+
# elastic-opentelemetry-instrumentation-openai (pyproject.toml)
124+
# pytest-vcr
114125
wheel==0.44.0
115126
# via pip-tools
116127
wrapt==1.16.0

instrumentation/elastic-opentelemetry-instrumentation-openai/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Homepage = "https://github.com/elastic/elastic-otel-python-instrumentations"
4040
"Bug Tracker" = "https://github.com/elastic/elastic-otel-python-instrumentations/issues"
4141

4242
[project.optional-dependencies]
43-
dev = ["pytest", "pip-tools", "openai", "opentelemetry-test-utils", "vcrpy"]
43+
dev = ["pytest", "pip-tools", "openai", "numpy", "opentelemetry-test-utils", "vcrpy", "pytest-asyncio", "pytest-vcr"]
4444
instruments = [
4545
"openai >= 1.0.0",
4646
]

0 commit comments

Comments
 (0)