ioc-scope-norm 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ioc_scope_norm-1.0.0/.gitignore +1 -0
- ioc_scope_norm-1.0.0/PKG-INFO +27 -0
- ioc_scope_norm-1.0.0/README.md +97 -0
- ioc_scope_norm-1.0.0/data/otel_traces_export.jsonl +89 -0
- ioc_scope_norm-1.0.0/pyproject.toml +69 -0
- ioc_scope_norm-1.0.0/scripts/generate_kg.py +148 -0
- ioc_scope_norm-1.0.0/src/norm/__init__.py +39 -0
- ioc_scope_norm-1.0.0/src/norm/compare.py +372 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/__init__.py +6 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/build.py +88 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/fields.py +109 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/handlers/__init__.py +18 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/handlers/agent.py +141 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/handlers/chat.py +135 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/handlers/graph.py +89 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/handlers/session.py +89 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/handlers/tool.py +103 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/heuristics/__init__.py +16 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/heuristics/capability_chain.py +90 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/heuristics/container_boundary_states.py +57 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/heuristics/handoff.py +145 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/otel_io.py +36 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/registry.py +109 -0
- ioc_scope_norm-1.0.0/src/norm/ioa_observe/trajectory.py +199 -0
- ioc_scope_norm-1.0.0/src/norm/normalizer.py +79 -0
- ioc_scope_norm-1.0.0/src/norm/ontology.py +112 -0
- ioc_scope_norm-1.0.0/src/norm/verifier.py +806 -0
- ioc_scope_norm-1.0.0/tests/__init__.py +2 -0
- ioc_scope_norm-1.0.0/tests/fixtures/currency_demo.otel_export.jsonl +10 -0
- ioc_scope_norm-1.0.0/tests/fixtures/noa_trip_planner.otel_export.jsonl +98 -0
- ioc_scope_norm-1.0.0/tests/test_api_boundaries.py +13 -0
- ioc_scope_norm-1.0.0/tests/test_compare.py +63 -0
- ioc_scope_norm-1.0.0/tests/test_normalizer.py +71 -0
- ioc_scope_norm-1.0.0/tests/test_otel_io.py +85 -0
- ioc_scope_norm-1.0.0/tests/test_pipeline_functional.py +105 -0
- ioc_scope_norm-1.0.0/tests/test_state_continuity.py +215 -0
- ioc_scope_norm-1.0.0/tests/test_validate_trace.py +36 -0
- ioc_scope_norm-1.0.0/tests/test_verifier.py +88 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
reference/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ioc-scope-norm
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: OTel(ioa_observe) span -> Knowledge Graph normalization.
|
|
5
|
+
Author-email: Outshift Open <oss-github@cisco.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: ioc-scope-ontology>=1.1.0
|
|
9
|
+
Requires-Dist: neo4j>=6.3.1
|
|
10
|
+
Requires-Dist: pydantic>=2.0.0
|
|
11
|
+
Provides-Extra: all
|
|
12
|
+
Requires-Dist: pyshacl>=0.25.0; extra == 'all'
|
|
13
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'all'
|
|
14
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'all'
|
|
15
|
+
Requires-Dist: pytest>=7.0; extra == 'all'
|
|
16
|
+
Requires-Dist: rdflib>=6.0.0; extra == 'all'
|
|
17
|
+
Requires-Dist: ruff>=0.12.10; extra == 'all'
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pyshacl>=0.25.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: rdflib>=6.0.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: ruff>=0.12.10; extra == 'dev'
|
|
25
|
+
Provides-Extra: graph
|
|
26
|
+
Requires-Dist: pyshacl>=0.25.0; extra == 'graph'
|
|
27
|
+
Requires-Dist: rdflib>=6.0.0; extra == 'graph'
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Normalization
|
|
2
|
+
|
|
3
|
+
This library is the normalization library of SCOPE, which converts raw OpenTelemetry spans into a normalized, ontology-verified KG documents (`{"nodes": [...], "edges": [...]}`) that conform to the [SCOPE ontology](https://ioc-project.github.io/scope/).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Each raw OTel span (a ClickHouse `otel_traces`-shaped dict: `SpanId`, `ParentSpanId`, `SpanName`,
|
|
8
|
+
`SpanAttributes`, `Timestamp`, `Duration`, ...) is dispatched straight to a handler by its
|
|
9
|
+
`SpanName`, and every value a handler needs is read directly off that span's own `SpanAttributes`
|
|
10
|
+
— there is no intermediate span shape, no per-span field-inference layer, and no
|
|
11
|
+
placeholder/"unknown" node fabricated for data a span doesn't carry. A span whose name matches
|
|
12
|
+
nothing is silently skipped.
|
|
13
|
+
|
|
14
|
+
A small set of best-effort, idempotent post-processing passes then bridge or share trajectory
|
|
15
|
+
state across agent handoffs, sibling capability calls within one agent invocation, and container
|
|
16
|
+
(`MASCall`/`Session`) boundaries.
|
|
17
|
+
|
|
18
|
+
`norm` is the normalization layer run by [norm-worker](../workers/norm-worker.md) at the start of
|
|
19
|
+
the [ingestion pipeline](../architecture/pipelines.md).
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Install (from norm/)
|
|
25
|
+
uv pip install -e ".[all]"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
|
|
31
|
+
from norm import dump_jsonld, infer_run_id, load_otel_export, normalize, verify_kg
|
|
32
|
+
|
|
33
|
+
trace = Path(__file__).resolve().parent / "data" / "otel_traces_export.jsonl"
|
|
34
|
+
spans = load_otel_export(trace)
|
|
35
|
+
run_id = infer_run_id(spans)
|
|
36
|
+
|
|
37
|
+
nodes, edges = normalize(spans)
|
|
38
|
+
report = verify_kg(nodes, edges, run_id)
|
|
39
|
+
|
|
40
|
+
dump_jsonld(nodes, edges, Path("out/kg.jsonld"))
|
|
41
|
+
print(f"nodes={len(nodes)} edges={len(edges)} ok={report['ok']}")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or generate a KG straight from the CLI (file output, or a direct Neo4j push):
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
python scripts/generate_kg.py data/otel_traces_export.jsonl \
|
|
48
|
+
--nodes-out /tmp/nodes.json --edges-out /tmp/edges.json
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Code structure
|
|
52
|
+
|
|
53
|
+
`norm` is split into an OTel/`ioa_observe`-specific layer and a format-agnostic core, all under the
|
|
54
|
+
single installable package `src/norm` (a second, empty `src/normalization` directory in the repo is
|
|
55
|
+
unused legacy scaffolding — not part of the built package).
|
|
56
|
+
|
|
57
|
+
**`norm.ioa_observe` (OTel span → KG):**
|
|
58
|
+
|
|
59
|
+
| Module | Role |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `otel_io.py` | `load_otel_export` (ClickHouse JSONL) and `infer_run_id` — operate on raw span dicts directly |
|
|
62
|
+
| `fields.py` | Span field derivation (`attrs`, `get_session_id`, `get_agent_id`, `get_start_time`, `get_duration_ms`, ...) read straight off `SpanAttributes` |
|
|
63
|
+
| `registry.py` | Generic `(type, id)`-keyed node/edge store (`add`, `upsert`, `add_if_not_exists`, `add_edge`, `find`, `edge_target`, `edge_source`, `edges_from`, `all_of`) — no domain knowledge of its own |
|
|
64
|
+
| `trajectory.py` | `add_state_pair_transition` (fresh State pair + Transition for one ExecutionElement), `bridge_states_if_mismatched` (synthesize a `ProcessingCall` bridge between two States only if their content differs), `adopt_boundary_states` (share an existing State directly, for pure containers) |
|
|
65
|
+
| `build.py` | `build_kg(spans)` — dispatches each span to a handler by `SpanName`, then runs the post-processing heuristics |
|
|
66
|
+
| `handlers/` | One handler per `SpanName` shape |
|
|
67
|
+
| `heuristics/` | Best-effort post-processing passes that need the full span/KG picture |
|
|
68
|
+
|
|
69
|
+
**Format-agnostic core:**
|
|
70
|
+
|
|
71
|
+
| Module | Role |
|
|
72
|
+
|---|---|
|
|
73
|
+
| `normalizer.py` | `normalize()`, `Normalizer` (thin file-loading wrapper), `dump_jsonld()` |
|
|
74
|
+
| `ontology.py` | Resolves ontology TTL/SHACL shape paths from the installed `scope-ontology` package — no vendored TTL copies |
|
|
75
|
+
| `verifier.py` | Structural checks (`check_unknown_node_types`, `check_unknown_edge_types`, `check_edge_domain_range`, `check_orphaned_edges`), SHACL (`run_shacl_validation`), `nodes_edges_to_jsonld`, `verify_kg()` |
|
|
76
|
+
| `compare.py` | KG structural regression diff (`compare_kg`, `read_kg_json`/`write_kg_json`) — a standalone comparison utility, not currently wired into norm-worker |
|
|
77
|
+
|
|
78
|
+
## Public API
|
|
79
|
+
|
|
80
|
+
| Function / class | Purpose |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `load_otel_export(path)` | ClickHouse JSONL → raw span dicts |
|
|
83
|
+
| `infer_run_id(spans)` | Session id for use as `run_id` |
|
|
84
|
+
| `normalize(spans)` | **Main entry** → `(nodes, edges)` |
|
|
85
|
+
| `verify_kg(nodes, edges, run_id)` | Structural + SHACL validation |
|
|
86
|
+
| `compare_kg(candidate, reference)` | Structural regression diff between two KGs |
|
|
87
|
+
| `dump_jsonld(nodes, edges, path)` | JSON-LD export |
|
|
88
|
+
| `Normalizer` | Thin file-loading wrapper around `normalize()` |
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
### Running it in the pipeline
|
|
92
|
+
|
|
93
|
+
`norm` is normally not invoked directly — it's run by the standalone
|
|
94
|
+
[`norm-worker`](../workers/norm-worker.md), which depends on `ioc-scope-norm[graph]` and calls
|
|
95
|
+
`normalize()` on spans it fetches from [scope-api](api.md). Adapting scope-api's
|
|
96
|
+
`SpanMetadataItem` rows to the raw span-dict shape `normalize()` expects is norm-worker's own job
|
|
97
|
+
(a straight field rename — both are sourced from the same ClickHouse `otel_traces` columns).
|