Skip to content
Open
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
13 changes: 12 additions & 1 deletion .github/scripts/test_python_test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,15 @@ def test_every_run_step_uses_bash_with_pipefail(self):
(
"install_poetry",
"Install the package and its dev dependencies (poetry)",
"if: matrix.package.backend == 'poetry'",
"if: matrix.package.backend == 'poetry' && matrix.package.name != 'openai' && matrix.package.name != 'vllm'",
"poetry install --no-interaction",
),
(
"install_local_core",
"Install privacy-dependent OpenAI packages with the local core",
"if: matrix.package.name == 'openai' || matrix.package.name == 'vllm'",
'.venv/bin/pip install "$GITHUB_WORKSPACE/python" . pytest==8.4.2 pytest-asyncio==0.24.0 pytest-mock==3.14.0 httpx==0.27.2',
),
(
"install_hatch",
"Install the package and its dev dependencies (hatch)",
Expand Down Expand Up @@ -677,6 +683,11 @@ def test_every_run_step_uses_bash_with_pipefail(self):
"fi",
"done",
],
"install_local_core": [
"python -m venv .venv",
'.venv/bin/pip install "$GITHUB_WORKSPACE/python" . pytest==8.4.2 pytest-asyncio==0.24.0 pytest-mock==3.14.0 httpx==0.27.2',
".venv/bin/pip check",
],
"install_hatch": [
"python -m venv .venv",
'.venv/bin/pip install -e ".[dev]"',
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/ollama-provider-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- 'python/frameworks/openai/**'
- 'python/frameworks/vllm/**'
- 'python/fi_instrumentation/**'
- 'python/tests/test_granular_privacy_copies.py'
- 'python/tests/test_structured_content_privacy.py'
- 'python/pyproject.toml'
- '.github/workflows/ollama-provider-tests.yml'
push:
Expand All @@ -15,6 +17,8 @@ on:
- 'python/frameworks/openai/**'
- 'python/frameworks/vllm/**'
- 'python/fi_instrumentation/**'
- 'python/tests/test_granular_privacy_copies.py'
- 'python/tests/test_structured_content_privacy.py'
- 'python/pyproject.toml'
- '.github/workflows/ollama-provider-tests.yml'
workflow_dispatch:
Expand All @@ -30,19 +34,19 @@ jobs:
strategy:
fail-fast: false
matrix:
openai: ['1.69.0', '3.42.0']
openai: ['1.69.0', '3.42.1']
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.11'
- name: Install SDK and test dependencies
- name: Install built wheels and SDK test dependencies
env:
OPENAI_VERSION: ${{ matrix.openai }}
run: >-
python -m pip install -e python -e python/frameworks/openai -e python/frameworks/vllm
python -m pip install ./python ./python/frameworks/openai ./python/frameworks/vllm
"openai==$OPENAI_VERSION" 'pytest==8.4.2' 'pytest-asyncio==0.24.0' 'pytest-socket==0.7.0'
- name: Test attribution over localhost OTLP
env:
Expand All @@ -57,6 +61,9 @@ jobs:
--allow-hosts=127.0.0.1 --allow-unix-socket
"$1" -m pytest "$2/python/frameworks/vllm/tests" \
-q -o addopts="" -p no:cacheprovider --disable-socket --allow-unix-socket
"$1" -m pytest "$2/python/tests/test_granular_privacy_copies.py" \
"$2/python/tests/test_structured_content_privacy.py" \
-q -o addopts="" -p no:cacheprovider --disable-socket --allow-unix-socket
' _ "$(command -v python)" "$PWD"

legacy:
Expand All @@ -70,9 +77,9 @@ jobs:
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.10'
- name: Install legacy package without the shared instrumentor
- name: Install legacy wheels without the shared instrumentor
run: >-
python -m pip install -e python -e python/frameworks/vllm
python -m pip install ./python ./python/frameworks/vllm
'openai==1.0.0' 'httpx==0.27.2' 'pytest==8.4.2'
'pytest-asyncio==0.24.0' 'pytest-socket==0.7.0'
- name: Test legacy SDK with outbound network disabled
Expand All @@ -81,4 +88,7 @@ jobs:
ip link set lo up
"$1" -m pytest "$2/python/frameworks/vllm/tests" \
-q -o addopts="" -p no:cacheprovider --disable-socket --allow-unix-socket
"$1" -m pytest "$2/python/tests/test_granular_privacy_copies.py" \
"$2/python/tests/test_structured_content_privacy.py" \
-q -o addopts="" -p no:cacheprovider --disable-socket --allow-unix-socket
' _ "$(command -v python)" "$PWD"
5 changes: 3 additions & 2 deletions .github/workflows/parallel-python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ jobs:
run: |
python -m venv .parallel-test-venv
.parallel-test-venv/bin/pip install build
.parallel-test-venv/bin/python -m build "--$DISTRIBUTION" python
.parallel-test-venv/bin/python -m build "--$DISTRIBUTION" python/frameworks/parallel
.parallel-test-venv/bin/python -m build "--$DISTRIBUTION" python/frameworks/openai
if [ "$DISTRIBUTION" = wheel ]; then
packages=(python/frameworks/{parallel,openai}/dist/*.whl)
packages=(python/dist/*.whl python/frameworks/{parallel,openai}/dist/*.whl)
else
packages=(python/frameworks/{parallel,openai}/dist/*.tar.gz)
packages=(python/dist/*.tar.gz python/frameworks/{parallel,openai}/dist/*.tar.gz)
fi
.parallel-test-venv/bin/pip install "${packages[@]}" \
"parallel-web==$PARALLEL_VERSION" "openai==$OPENAI_VERSION" pytest pytest-asyncio
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:

- name: Install the package and its dev dependencies (poetry)
id: install_poetry
if: matrix.package.backend == 'poetry'
if: matrix.package.backend == 'poetry' && matrix.package.name != 'openai' && matrix.package.name != 'vllm'
working-directory: ${{ matrix.package.dir }}
run: |
pip install "poetry==$POETRY_VERSION"
Expand All @@ -193,6 +193,17 @@ jobs:
fi
done

- name: Install privacy-dependent OpenAI packages with the local core
id: install_local_core
if: matrix.package.name == 'openai' || matrix.package.name == 'vllm'
working-directory: ${{ matrix.package.dir }}
run: |
# These packages require the core release prepared in the same PR.
# Resolve built wheels together, never an older core from PyPI/poetry.lock.
python -m venv .venv
.venv/bin/pip install "$GITHUB_WORKSPACE/python" . pytest==8.4.2 pytest-asyncio==0.24.0 pytest-mock==3.14.0 httpx==0.27.2
.venv/bin/pip check

- name: Install the package and its dev dependencies (hatch)
id: install_hatch
if: matrix.package.backend == 'hatch'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/vercel-gateway-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.13'
- name: Install the SDK and published tracing core
- name: Install the SDK and tracing wheels
env:
SDK_VERSION: ${{ matrix.sdk }}
run: python -m pip install "openai==$SDK_VERSION" 'fi-instrumentation-otel==1.2.2' pytest pytest-socket
run: python -m pip install "openai==$SDK_VERSION" ./python ./python/frameworks/openai pytest pytest-socket
- name: Run SDK-to-OTLP contracts with non-local sockets blocked
env:
PYTHONPATH: python/frameworks/openai
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"go/lambda": "0.1.0",
"go/openai": "0.1.0",
"csharp/src/FIInstrumentation": "1.0.0",
"python": "1.2.2",
"python": "1.2.3",
"typescript/packages/traceai_elevenlabs": "0.1.0",
"go/bedrock": "0.1.0"
}
22 changes: 21 additions & 1 deletion python/fi_instrumentation/instrumentation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,24 @@ def mask(
and key == SpanAttributes.GEN_AI_REQUEST_PARAMETERS
):
return None
# Opaque aggregate copies cannot be filtered by message-part type. Hide
# the whole copy when any contained input/output category is private;
# typed message attributes below still preserve the other categories.
elif (
self.hide_input_messages or self.hide_input_text or self.hide_input_images
) and _has_content_prefix(
key,
(
SpanAttributes.INPUT_VALUE,
SpanAttributes.RAW_INPUT,
SpanAttributes.GEN_AI_REQUEST_PARAMETERS,
),
):
value = REDACTED_VALUE
elif (
self.hide_output_messages or self.hide_output_text
) and _has_content_prefix(key, (SpanAttributes.OUTPUT_VALUE, SpanAttributes.RAW_OUTPUT)):
value = REDACTED_VALUE
elif self.hide_inputs and _has_content_prefix(key, (SpanAttributes.INPUT_VALUE,)):
value = REDACTED_VALUE
elif self.hide_inputs and key == SpanAttributes.INPUT_MIME_TYPE:
Expand Down Expand Up @@ -432,7 +450,9 @@ def mask(
) and _is_embedding_text_key(key):
# Embedding input text is input content for all three flags.
value = REDACTED_VALUE
elif self.hide_input_images and _has_content_prefix(key, (SpanAttributes.INPUT_IMAGES,)):
elif (self.hide_input_images or self.hide_input_messages) and _has_content_prefix(
key, (SpanAttributes.INPUT_IMAGES,)
):
return None
elif (
self.hide_input_images
Expand Down
2 changes: 1 addition & 1 deletion python/fi_instrumentation/instrumentation/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.2" # x-release-please-version
__version__ = "1.2.3" # x-release-please-version
14 changes: 5 additions & 9 deletions python/frameworks/deepseek/tests/test_privacy_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,24 @@ def respond(request):
tool_key = "deepseek.tool_calls.0.function.arguments"
content_key = "gen_ai.output.messages.0.message.content"
if hide_content:
if policy == "hide_outputs":
assert attributes["output.value"] == REDACTED_VALUE
assert attributes["output.value"] == REDACTED_VALUE
if policy == "hide_output_text":
for key in (*reasoning_keys, tool_key, content_key):
assert attributes[key] == REDACTED_VALUE
else:
assert not any(key.startswith("gen_ai.output.messages") for key in attributes)
for key in (*reasoning_keys, tool_key):
assert key not in attributes
# Text/message policies intentionally do not hide the separate raw
# output.value field. Everything else must be free of private output.
masked_attributes = dict(attributes)
if policy != "hide_outputs":
masked_attributes.pop("output.value")
# Granular policies must also hide opaque raw copies: excluding
# output.value here would let the same private answer leak again.
for private in (answer, reasoning, arguments, "PRIVATE_TOOL_ARGUMENTS_6823"):
assert private not in json.dumps(masked_attributes)
assert private not in json.dumps(attributes)
else:
for key in reasoning_keys:
assert attributes[key] == reasoning
assert attributes[tool_key] == arguments
assert attributes[content_key] == answer
if not hide_content or policy != "hide_outputs":
if not hide_content:
payload = json.loads(attributes["output.value"])
output = payload if streaming else payload["choices"][0]["message"]
assert output["content"] == answer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,17 @@ def test_hide_outputs_changes_nothing_because_no_output_text_is_recorded(fake):
@pytest.mark.parametrize("source", ["config", "env"])
@pytest.mark.parametrize("flag", OTHER_CONTENT_HIDE_FLAGS)
def test_other_content_hide_flags_follow_core_error_policy(fake, monkeypatch, flag, source):
# These flags do not hide a retrieval query, but native core derives error
# privacy from all content-hide flags, not only hide_inputs. No opt-out.
# Granular input policies also hide the opaque input.value copy. Output
# policies leave it visible; all content-hide flags derive error privacy.
plain = _denied(fake, {})
options = {}
if source == "config":
options["config"] = _config(**{flag: True})
else:
monkeypatch.setenv("FI_" + flag.upper(), "true")
span = _denied(fake, options)
assert attrs(span)["input.value"] == DENIED_QUERY
expected_query = REDACTED_VALUE if flag in ("hide_input_messages", "hide_input_text") else DENIED_QUERY
assert attrs(span)["input.value"] == expected_query
assert attrs(span)["discoveryengine.error.code"] == 403
assert attrs(span)["discoveryengine.error.status"] == "PERMISSION_DENIED"
assert span.status.status_code is StatusCode.ERROR
Expand Down
2 changes: 1 addition & 1 deletion python/frameworks/openai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [

[tool.poetry.dependencies]
python = ">3.9,<3.14"
fi-instrumentation-otel = ">=0.1.11"
fi-instrumentation-otel = ">=1.2.3"
openai = ">=1.69.0"

[tool.poetry.urls]
Expand Down
7 changes: 4 additions & 3 deletions python/frameworks/openai/tests/test_deepseek_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,15 @@ def test_responses_plaintext_reasoning(
a = attrs(spans)
assert a["gen_ai.usage.output_tokens"] == 7
assert spans[0].status.code == 1
if policy != "hide_outputs":
if policy in ("hide_output_messages", "hide_output_text"):
# The shared privacy filter also protects the aggregate output value.
assert a["output.value"] == "__REDACTED__"
elif policy is None:
if streaming:
assert a["output.value"] == ANSWER
else:
assert json.loads(a["output.value"])["output_text"] == ANSWER
if policy:
if policy != "hide_outputs":
a.pop("output.value", None) # Raw output has an independent policy.
encoded = json.dumps(a)
assert REASONING not in encoded
assert summary not in encoded
Expand Down
2 changes: 1 addition & 1 deletion python/frameworks/openai/traceai_openai/_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def __call__(
request_parameters=request_parameters,
instance=instance,
)
except Exception as e:
except BaseException as e:
status = trace_api.Status(
status_code=trace_api.StatusCode.ERROR,
description=f"{type(e).__name__}: {e}",
Expand Down
4 changes: 4 additions & 0 deletions python/frameworks/openai/traceai_openai/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ async def close(self) -> Any:
finally:
_finish_on_exit(self, error)

async def aclose(self) -> Any:
# The SDK binds this alias to its own close method; route through ours.
return await self.close()

def __aiter__(self):
return self

Expand Down
2 changes: 1 addition & 1 deletion python/frameworks/vllm/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [

[tool.poetry.dependencies]
python = ">3.9,<3.14"
fi-instrumentation-otel = ">=0.1.11"
fi-instrumentation-otel = ">=1.2.3"
openai = ">=1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
25 changes: 25 additions & 0 deletions python/frameworks/vllm/tests/test_core_privacy_dependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Installed metadata must require the core that protects duplicate content."""

from importlib.metadata import PackageNotFoundError, requires, version

import pytest
from packaging.requirements import Requirement
from packaging.version import Version


@pytest.mark.parametrize("package", ["traceAI-vllm", "traceAI-openai"])
def test_instrumentor_requires_privacy_fixed_core(package):
try:
dependencies = requires(package)
except PackageNotFoundError:
pytest.skip(
"Shared instrumentor is intentionally absent at the legacy SDK floor"
)
core = next(
Requirement(value)
for value in dependencies
if Requirement(value).name == "fi-instrumentation-otel"
)
assert Version("1.2.2") not in core.specifier
assert Version("1.2.3") in core.specifier
assert Version(version("fi-instrumentation-otel")) in core.specifier
Loading
Loading