Skip to content

Commit 5ffe171

Browse files
feat(trace): Assign default value to missing value (#225)
* feat(tracestats): Add default value for trace stats * fix(tests): Update test snapshot to use default value * docs(releasenotes): Add breaking change notice for snapshot updates
1 parent 311de54 commit 5ffe171

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

ddapm_test_agent/tracestats.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import List
2-
from typing import Optional
32
from typing import TypedDict
43

54
from ddsketch import DDSketch
@@ -13,8 +12,8 @@
1312
class StatsAggr(TypedDict):
1413
Name: str
1514
Resource: str
16-
Service: Optional[str]
17-
Type: Optional[str]
15+
Service: str
16+
Type: str
1817
HTTPStatusCode: int
1918
Synthetics: bool
2019
Hits: int
@@ -32,9 +31,9 @@ class StatsBucket(TypedDict):
3231

3332

3433
class v06StatsPayload(TypedDict):
35-
Hostname: Optional[str]
36-
Env: Optional[str]
37-
Version: Optional[str]
34+
Hostname: str
35+
Env: str
36+
Version: str
3837
Stats: List[StatsBucket]
3938

4039

@@ -47,9 +46,9 @@ def decode_v06(data: bytes) -> v06StatsPayload:
4746
stat = StatsAggr(
4847
Name=raw_stats["Name"],
4948
Resource=raw_stats["Resource"],
50-
Service=raw_stats.get("Service"),
51-
Type=raw_stats.get("Type"),
52-
HTTPStatusCode=raw_stats.get("HTTPStatusCode"),
49+
Service=raw_stats.get("Service") or "",
50+
Type=raw_stats.get("Type") or "",
51+
HTTPStatusCode=raw_stats.get("HTTPStatusCode") or 0,
5352
Synthetics=raw_stats["Synthetics"],
5453
Hits=raw_stats["Hits"],
5554
TopLevelHits=raw_stats["TopLevelHits"],
@@ -68,8 +67,8 @@ def decode_v06(data: bytes) -> v06StatsPayload:
6867
stats_buckets.append(bucket)
6968

7069
return v06StatsPayload(
71-
Hostname=payload.get("Hostname"),
72-
Env=payload.get("Env"),
73-
Version=payload.get("Version"),
70+
Hostname=payload.get("Hostname", ""),
71+
Env=payload.get("Env", ""),
72+
Version=payload.get("Version", ""),
7473
Stats=stats_buckets,
7574
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Use default value for null fields in tracestats. This aligns with the trace agent behaviors.
5+
upgrade:
6+
- |
7+
BREAKING CHANGE: Test snapshots must be updated as field comparisons on stats payload will fail between "" and None values.

tests/integration_snapshots/test_trace_stats_tracestats.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
{
77
"Name": "http.request",
88
"Resource": "/users/view",
9-
"Service": null,
10-
"Type": null,
9+
"Service": "",
10+
"Type": "",
1111
"HTTPStatusCode": 0,
1212
"Synthetics": false,
1313
"Hits": 5,

0 commit comments

Comments
 (0)