Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 19 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ jobs:
py310: "3.10"
py311: "3.11"
py312: "3.12"
# Baseline version of openai client we support
baseline: "1.2.0"
latest: ""
working_dir: "instrumentation/elastic-opentelemetry-instrumentation-openai"
strategy:
fail-fast: false
matrix:
working-dir: ['instrumentation/elastic-opentelemetry-instrumentation-openai']
python-version: [py38, py39, py310, py311, py312]
openai-version: [baseline, latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ env[matrix.python-version] }}
Expand All @@ -57,9 +61,20 @@ jobs:
architecture: "x64"
- if: ${{ env[matrix.python-version] == '3.8' || env[matrix.python-version] == '3.9' }}
run: pip install -r dev-requirements-3.9.txt
working-directory: ${{ matrix.working-dir }}
working-directory: ${{ env.working_dir }}
- if: ${{ env[matrix.python-version] != '3.8' && env[matrix.python-version] != '3.9' }}
run: pip install -r dev-requirements.txt
working-directory: ${{ matrix.working-dir }}
working-directory: ${{ env.working_dir }}
- if: ${{ env[matrix.openai-version] }}
name: update openai to required version if not latest
run:
pip install openai==${{ env[matrix.openai-version] }}
working-directory: ${{ env.working_dir }}
- run: pytest
working-directory: ${{ matrix.working-dir }}
working-directory: ${{ env.working_dir }}
- if: ${{ env[matrix.python-version] == '3.12' && !env[matrix.openai-version] }}
# Only run on latest python and openai client version because we are calling openai
run: pytest --integration-tests
working-directory: ${{ env.working_dir }}
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pip install -r dev-requirements.txt
pytest
```

To run integration tests doing real requests:

```
OPENAI_API_KEY=unused pytest --integration-tests
```

## Refreshing HTTP payloads

We use [VCR.py](https://vcrpy.readthedocs.io/en/latest/) to automatically record HTTP responses from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies = [
"opentelemetry-api ~= 1.28.1",
"opentelemetry-instrumentation ~= 0.49b1",
"opentelemetry-semantic-conventions ~= 0.49b1",
"wrapt >= 1.0.0, < 2.0.0",
]

[project.readme]
Expand All @@ -42,7 +43,7 @@ Homepage = "https://github.com/elastic/elastic-otel-python-instrumentations"
[project.optional-dependencies]
dev = ["pytest", "pip-tools", "openai", "numpy", "opentelemetry-test-utils", "vcrpy", "pytest-asyncio", "pytest-vcr"]
instruments = [
"openai >= 1.0.0",
"openai >= 1.2.0",
]

[project.entry-points.opentelemetry_instrumentor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

_instruments = ("openai >= 1.0.0",)
_instruments = ("openai >= 1.2.0",)
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def end(self, exc=None):
def process_chunk(self, chunk):
self.response_id = chunk.id
self.model = chunk.model
self.usage = chunk.usage
# usage with streaming is available since 1.26.0
if hasattr(chunk, "usage"):
self.usage = chunk.usage
# with `include_usage` in `stream_options` we will get a last chunk without choices
if chunk.choices:
self.choices += chunk.choices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,26 @@ def assert_token_usage_metric(
),
],
)


def pytest_addoption(parser):
parser.addoption(
"--integration-tests",
action="store_true",
default=False,
help="run integrations tests doing real requests",
)


def pytest_configure(config):
config.addinivalue_line("markers", "integration: mark integration tests")


def pytest_collection_modifyitems(config, items):
run_integration_tests = bool(config.getoption("integration_tests"))
reason = "running integrations tests only" if run_integration_tests else "skipping integration tests"
skip_mark = pytest.mark.skip(reason=reason)
for item in items:
test_is_integration = "integration" in item.keywords
if run_integration_tests != test_is_integration:
item.add_marker(skip_mark)
Loading