Skip to content

fix: use Z suffix for UTC timestamps and omit null trace_id#4

Merged
Polliog merged 1 commit intologtide-dev:mainfrom
TomatoInOil:fix/datetime-and-null-trace-id
Apr 5, 2026
Merged

fix: use Z suffix for UTC timestamps and omit null trace_id#4
Polliog merged 1 commit intologtide-dev:mainfrom
TomatoInOil:fix/datetime-and-null-trace-id

Conversation

@TomatoInOil
Copy link
Copy Markdown
Contributor

Summary

The Python SDK produces payloads that the LogTide server rejects with HTTP 400 (Validation error). Two issues in LogEntry:

  1. time uses +00:00 instead of Zdatetime.now(timezone.utc).isoformat() produces 2026-04-05T08:00:00.123456+00:00, but the server's Zod schema (z.string().datetime()) only accepts Z. The JS SDK uses new Date().toISOString() which always produces Z.

  2. trace_id serialized as nullto_dict() always includes trace_id. When None, JSON produces "trace_id": null, but the server's Zod schema (z.string().optional()) rejects null — only omitted or string are valid. The JS SDK uses optional chaining (scope?.traceId) → undefined → omitted by JSON.stringify.

Changes

  • LogEntry.__post_init__: use strftime("%Y-%m-%dT%H:%M:%S.%fZ") instead of .isoformat()
  • LogEntry.__post_init__: normalize caller-supplied +00:00 offset to Z
  • LogEntry.to_dict(): omit trace_id from payload when it is None instead of serializing it as null
  • Added tests for all three cases

Test plan

  • All existing tests pass (32/32, excluding 2 pre-existing async import failures)
  • Verified against a live LogTide 0.8.4 server — 4 logs ingested successfully (direct client + logging handler)

- LogEntry.__post_init__: use strftime with Z suffix instead of
  isoformat() which produces +00:00. The server's Zod schema
  (z.string().datetime()) only accepts the Z suffix.
- Normalize caller-supplied +00:00 offset to Z as well.
- LogEntry.to_dict(): only include trace_id when it is not None.
  The server's Zod schema (z.string().optional()) rejects null;
  only undefined (omitted) or a string value are valid.
@TomatoInOil TomatoInOil force-pushed the fix/datetime-and-null-trace-id branch from c9e1d15 to e0f4964 Compare April 5, 2026 12:19
@Polliog
Copy link
Copy Markdown
Contributor

Polliog commented Apr 5, 2026

Hi thank you for the changes, I will merge this and release a new version of the package

@Polliog Polliog merged commit 4e89ef0 into logtide-dev:main Apr 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants