Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
efe02e3
test(discoveryengine): measure stock spans before any wrapper
nik13 Oct 5, 2026
6809239
test(discoveryengine): real-SDK tests for search, search_lite and ans…
nik13 Oct 5, 2026
4dae55c
test(discoveryengine): fit the 24 KB error through gRPC and pin more …
nik13 Oct 5, 2026
44332c5
feat(discoveryengine): trace search, search_lite and answer_query, sy…
nik13 Oct 5, 2026
39e9a59
feat(discoveryengine): add examples/search_and_answer.py
nik13 Oct 5, 2026
774e8bb
docs(discoveryengine): README with attributes, privacy, errors, limit…
nik13 Oct 5, 2026
e32e76d
docs: list traceAI-discoveryengine in the README package tables
nik13 Oct 5, 2026
b760080
test(discoveryengine): regression tests for review round 1 (RED)
nik13 Oct 5, 2026
fe305e3
fix(discoveryengine): read per-call metadata once and pass it on as a…
nik13 Oct 5, 2026
651c124
fix(discoveryengine): read credentials again when recording an error;…
nik13 Oct 5, 2026
ef7bf59
fix(discoveryengine): remove escaped copies of a hidden query from er…
nik13 Oct 5, 2026
19d5076
docs(discoveryengine): document the switch-on stock-span run; say the…
nik13 Oct 5, 2026
7ea99f1
fix(discoveryengine): match protobuf text format's octal escapes when…
nik13 Oct 5, 2026
c84fae4
chore(discoveryengine): ship py.typed like the sibling tracer packages
nik13 Oct 12, 2026
ab2ce66
fix(discoveryengine): use the repo span-kind key
nik13 Oct 12, 2026
7094721
docs: move the README catalog row to the TH-8103 catalog PR
nik13 Oct 12, 2026
1f04135
fix(discoveryengine): follow TraceConfig for the query; never export …
nik13 Oct 17, 2026
62f57d9
fix(discoveryengine): record the REST error status; test the REST tra…
nik13 Oct 17, 2026
4d49ef2
test(discoveryengine): replay the live API's REST error bodies
nik13 Oct 18, 2026
6834af2
docs(discoveryengine): live vendor verification (2026-10-18)
nik13 Oct 18, 2026
e64d7ed
Merge dev into feat/th-8332-discoveryengine
nik13 Oct 21, 2026
35ec747
docs(discoveryengine): README and CHANGELOG read as released (TH-8332)
nik13 Oct 21, 2026
10c028b
Merge dev into integration PR #224
nik13 Oct 28, 2026
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
36 changes: 36 additions & 0 deletions python/frameworks/discoveryengine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog

## 0.1.0

First release.

- Trace `google-cloud-discoveryengine` v1 `SearchServiceClient.search`,
`SearchServiceClient.search_lite` and
`ConversationalSearchServiceClient.answer_query`, and their async twins:
one span per call with `gen_ai.span.kind` = `RETRIEVER`, `discoveryengine.serving_config` and
`discoveryengine.result_count`; for answers also
`discoveryengine.answer.length`, `discoveryengine.answer.state` and
`discoveryengine.session`. No model name, tokens or cost.
- The query follows `TraceConfig`: recorded by default
(`gen_ai.retrieval.query`, `input.value`), hidden with `FI_HIDE_INPUTS` /
`hide_inputs`, and then also removed from error text, verbatim and in the
escaped copies the client libraries write. No package-specific switch (a
pre-release `capture_query` option is ignored with a warning). Results and
answer text are never recorded.
- The `exception` event carries the type and the cleaned message only; no
`exception.stacktrace` (traceback frames hold local file paths).
- REST transport: `discoveryengine.error.status` comes from the canonical
`status` of the JSON error body (`google-api-core` raises REST errors by
HTTP code, for example `Forbidden`, which has no gRPC status).
- Google credentials (transport credentials, read again when an error is
recorded; `client_options.api_key`; per-call auth metadata; and Google
token shapes, including JWTs) are removed from every recorded value.
Errors record the gRPC status and code, then re-raise.
- `TraceConfig` `hide_inputs` and `pii_redaction` apply, including to error
text. Spans come from `FITracer`, so `using_*` context attributes apply.
- Accepts `google-cloud-discoveryengine>=0.20.5,<1`; tested with 0.20.5 on
Python 3.10 to 3.13.
- Checked against the live v1 API (2026-10-18): `search` on the gRPC, REST
and gRPC asyncio transports, and real `NOT_FOUND` and
`FAILED_PRECONDITION` errors from `search`, `search_lite` and
`answer_query`. The REST tests replay those error bodies.
387 changes: 387 additions & 0 deletions python/frameworks/discoveryengine/README.md

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions python/frameworks/discoveryengine/examples/search_and_answer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Trace one Discovery Engine search and one grounded answer.

Set DISCOVERY_ENGINE_SERVING_CONFIG to a serving config resource name:

projects/PROJECT/locations/LOCATION/collections/default_collection/engines/ENGINE/servingConfigs/default_search

The Google clients read Application Default Credentials (ADC) themselves:
run ``gcloud auth application-default login`` or set
GOOGLE_APPLICATION_CREDENTIALS. register() reads FI_API_KEY, FI_SECRET_KEY
and FI_BASE_URL. The Future AGI project is not your GCP project.
"""

import os
from typing import Any, Dict, Optional

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
from google.cloud import discoveryengine_v1 as discoveryengine

from traceai_discoveryengine import DiscoveryEngineInstrumentor

QUERY = "open telemetry retrieval"
QUESTION = "What does OpenTelemetry trace?"


def client_options(serving_config: str) -> Dict[str, Any]:
"""A regional engine (``locations/eu`` or ``locations/us``) needs its regional endpoint."""
location = serving_config.split("/locations/", 1)[-1].split("/", 1)[0]
if location and location != "global" and "/locations/" in serving_config:
return {"api_endpoint": "{0}-discoveryengine.googleapis.com".format(location)}
return {}


def main(search_client: Optional[Any] = None, answer_client: Optional[Any] = None) -> None:
tracer_provider = register(
project_name="discoveryengine-example",
project_type=ProjectType.OBSERVE,
batch=False,
verbose=False,
)
DiscoveryEngineInstrumentor().instrument(tracer_provider=tracer_provider)

serving_config = os.environ["DISCOVERY_ENGINE_SERVING_CONFIG"]
options = client_options(serving_config)
search_client = search_client or discoveryengine.SearchServiceClient(client_options=options)
answer_client = answer_client or discoveryengine.ConversationalSearchServiceClient(
client_options=options
)

pager = search_client.search(
request={"serving_config": serving_config, "query": QUERY, "page_size": 5}
)
print("{0} results on the first page".format(len(pager.results)))

response = answer_client.answer_query(
request={"serving_config": serving_config, "query": {"text": QUESTION}}
)
print("answer state: {0}".format(response.answer.state.name))
tracer_provider.force_flush()


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions python/frameworks/discoveryengine/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[tool.poetry]
name = "traceAI-discoveryengine"
version = "0.1.0"
description = "OpenTelemetry instrumentation for Google Discovery Engine (Vertex AI Search) search and answer calls"
authors = ["Future AGI <no-reply@futureagi.com>"]
readme = "README.md"
packages = [
{ include = "traceai_discoveryengine" }
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
]

[tool.poetry.dependencies]
python = ">=3.10,<3.14"
fi-instrumentation-otel = ">=1.1.0"
google-cloud-discoveryengine = ">=0.20.5,<1"
wrapt = ">=1.0.0"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading
Loading