Skip to content

Commit 7d72915

Browse files
debug: log more chars, check for embedded newlines, fix scrubbing (#39)
1 parent 70aa48c commit 7d72915

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/policyengine_api/api/agent.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,17 @@ def stream_reader():
183183
logfire.info("reader_started")
184184
for line in process.stdout:
185185
lines_received += 1
186-
# Log line length and first 100 chars (avoid scrubbing)
186+
# Log line length and first 500 chars (avoid scrubbing)
187187
line_preview = (
188-
line[:100].replace("session", "sess1on") if line else None
188+
line[:500].replace("session", "sess1on") if line else None
189189
)
190+
# Check if multiple JSON objects concatenated (embedded newlines)
191+
newline_count = line.count("\n") if line else 0
190192
logfire.info(
191193
"raw_line",
192194
line_num=lines_received,
193195
line_len=len(line) if line else 0,
196+
newline_count=newline_count,
194197
line_preview=line_preview,
195198
)
196199
line_queue.put(("line", line))

src/policyengine_api/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@
1818

1919
# Configure Logfire (only if token is set)
2020
if settings.logfire_token:
21+
22+
def _scrubbing_callback(m: logfire.ScrubMatch):
23+
"""Allow 'session' through for Claude stream debugging."""
24+
if m.path in (("attributes", "line"), ("attributes", "line_preview")):
25+
if m.pattern_match.group(0) == "session":
26+
return m.value
27+
2128
logfire.configure(
2229
service_name="policyengine-api",
2330
token=settings.logfire_token,
2431
environment=settings.logfire_environment,
2532
console=False,
33+
scrubbing=logfire.ScrubbingOptions(callback=_scrubbing_callback),
2634
)
2735
logfire.instrument_httpx()
2836

0 commit comments

Comments
 (0)