Skip to content

Commit 62ad471

Browse files
authored
Merge pull request #2120 from tisnik/lcore-2861-refactored-observability-documentation
LCORE-2861: Refactored observability package documentation
2 parents 0a4f858 + 35577f8 commit 62ad471

3 files changed

Lines changed: 100 additions & 95 deletions

File tree

src/observability/README.md

Lines changed: 5 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,8 @@
1-
# Observability Module
1+
# List of source files stored in `src/observability` directory
22

3-
This module provides telemetry capabilities for sending inference events to external systems like Splunk HEC.
3+
## [__init__.py](__init__.py)
4+
Observability module for telemetry and event collection.
45

5-
## Architecture
6+
## [splunk.py](splunk.py)
7+
Async Splunk HEC client for sending telemetry events.
68

7-
```
8-
observability/
9-
├── __init__.py # Public API exports
10-
├── splunk.py # Async Splunk HEC client
11-
└── formats/
12-
├── __init__.py # Format exports
13-
└── rlsapi.py # rlsapi v1 event format
14-
```
15-
16-
## Usage
17-
18-
### Sending Events to Splunk
19-
20-
```python
21-
from fastapi import BackgroundTasks
22-
from observability import send_splunk_event, build_inference_event, InferenceEventData
23-
24-
# Build the event payload
25-
event_data = InferenceEventData(
26-
question="How do I configure SSH?",
27-
response="To configure SSH...",
28-
inference_time=2.34,
29-
model="granite-3-8b-instruct",
30-
org_id="12345678",
31-
system_id="abc-def-123",
32-
request_id="req_xyz789",
33-
cla_version="CLA/0.6.0rc2",
34-
system_os="RHEL",
35-
system_version="9.3",
36-
system_arch="x86_64",
37-
)
38-
39-
event = build_inference_event(event_data)
40-
41-
# Queue for async sending via BackgroundTasks
42-
background_tasks.add_task(send_splunk_event, event, "infer_with_llm")
43-
```
44-
45-
### Source Types
46-
47-
| Source Type | Description |
48-
|-------------|-------------|
49-
| `infer_with_llm` | Successful inference requests |
50-
| `infer_error` | Failed inference requests |
51-
52-
## Creating Custom Event Formats
53-
54-
To add a new event format for a different endpoint:
55-
56-
1. Create a new module in `observability/formats/`:
57-
58-
```python
59-
# observability/formats/my_endpoint.py
60-
from dataclasses import dataclass
61-
from typing import Any
62-
63-
@dataclass
64-
class MyEventData:
65-
field1: str
66-
field2: int
67-
68-
def build_my_event(data: MyEventData) -> dict[str, Any]:
69-
return {
70-
"field1": data.field1,
71-
"field2": data.field2,
72-
}
73-
```
74-
75-
2. Export from `observability/formats/__init__.py`
76-
77-
3. Use with `send_splunk_event()`:
78-
79-
```python
80-
from observability import send_splunk_event
81-
from observability.formats.my_endpoint import build_my_event, MyEventData
82-
83-
event = build_my_event(MyEventData(field1="value", field2=42))
84-
background_tasks.add_task(send_splunk_event, event, "my_sourcetype")
85-
```
86-
87-
## Graceful Degradation
88-
89-
The Splunk client is designed to never block or fail the main request:
90-
91-
- Skips sending when Splunk is disabled or not configured
92-
- Logs warnings on HTTP errors (does not raise exceptions)
93-
- Token is read from file on each request (supports rotation without restart)
94-
95-
## Configuration
96-
97-
See [docs/splunk.md](../../docs/splunk.md) for configuration options.

src/observability/__init__.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,100 @@
66
The splunk module provides a format-agnostic send_splunk_event() function.
77
Event formats are in the formats subpackage - see formats.rlsapi for the
88
default implementation, or create your own format module.
9+
10+
## Architecture
11+
12+
```
13+
observability/
14+
├── __init__.py # Public API exports
15+
├── splunk.py # Async Splunk HEC client
16+
└── formats/
17+
├── __init__.py # Format exports
18+
├── rlsapi.py # rlsapi v1 event format
19+
└── responses.py # responses event format
20+
21+
## Usage
22+
23+
### Sending Events to Splunk
24+
25+
```python
26+
from fastapi import BackgroundTasks
27+
from observability import send_splunk_event, build_inference_event, InferenceEventData
28+
29+
# Build the event payload
30+
event_data = InferenceEventData(
31+
question="How do I configure SSH?",
32+
response="To configure SSH...",
33+
inference_time=2.34,
34+
model="granite-3-8b-instruct",
35+
org_id="12345678",
36+
system_id="abc-def-123",
37+
request_id="req_xyz789",
38+
cla_version="CLA/0.6.0rc2",
39+
system_os="RHEL",
40+
system_version="9.3",
41+
system_arch="x86_64",
42+
)
43+
44+
event = build_inference_event(event_data)
45+
46+
# Queue for async sending via BackgroundTasks
47+
background_tasks.add_task(send_splunk_event, event, "infer_with_llm")
48+
```
49+
50+
### Source Types
51+
52+
| Source Type | Description |
53+
|-------------|-------------|
54+
| `infer_with_llm` | Successful inference requests |
55+
| `infer_error` | Failed inference requests |
56+
57+
## Creating Custom Event Formats
58+
59+
To add a new event format for a different endpoint:
60+
61+
1. Create a new module in `observability/formats/`:
62+
63+
```python
64+
# observability/formats/my_endpoint.py
65+
from dataclasses import dataclass
66+
from typing import Any
67+
68+
@dataclass
69+
class MyEventData:
70+
field1: str
71+
field2: int
72+
73+
def build_my_event(data: MyEventData) -> dict[str, Any]:
74+
return {
75+
"field1": data.field1,
76+
"field2": data.field2,
77+
}
78+
```
79+
80+
2. Export from `observability/formats/__init__.py`
81+
82+
3. Use with `send_splunk_event()`:
83+
84+
```python
85+
from observability import send_splunk_event
86+
from observability.formats.my_endpoint import build_my_event, MyEventData
87+
88+
event = build_my_event(MyEventData(field1="value", field2=42))
89+
background_tasks.add_task(send_splunk_event, event, "my_sourcetype")
90+
```
91+
92+
## Graceful Degradation
93+
94+
The Splunk client is designed to never block or fail the main request:
95+
96+
- Skips sending when Splunk is disabled or not configured
97+
- Logs warnings on HTTP errors (does not raise exceptions)
98+
- Token is read from file on each request (supports rotation without restart)
99+
100+
## Configuration
101+
102+
See [docs/splunk.md](../../docs/splunk.md) for configuration options.
9103
"""
10104

11105
from observability.formats import (

src/utils/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Utility function to dump schema with list of models into OpenAPI-compatible JSON
5757
## [prompts.py](prompts.py)
5858
Utility functions for system prompts.
5959

60-
## [pydantic_ai.py](pydantic_ai.py)
60+
## [pydantic_ai_helpers.py](pydantic_ai_helpers.py)
6161
Helpers for running Pydantic AI agents against Llama Stack (Responses API compatibility).
6262

6363
## [query.py](query.py)

0 commit comments

Comments
 (0)