Skip to content

fix: otel#221

Merged
echarles merged 14 commits intomainfrom
feat/otel-3
Apr 17, 2026
Merged

fix: otel#221
echarles merged 14 commits intomainfrom
feat/otel-3

Conversation

@echarles
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 16, 2026 03:57
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 16, 2026

Deploy Preview for datalayer-core failed.

Name Link
🔨 Latest commit da6ba10
🔍 Latest deploy log https://app.netlify.com/projects/datalayer-core/deploys/69e21e1722d1220009356c5f

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates OTEL client/auth handling across the TypeScript and Python implementations, focusing on stricter auth inputs, safer timestamp representation, and shared JWT user-uid decoding.

Changes:

  • TypeScript: make OTEL client token required, trim tokens during auth resolution, and preserve timestamp_unix_nano as a string.
  • TypeScript: improve base URL handling for WebSocket URL construction (support relative URLs in browser contexts).
  • Python: reuse a centralized decode_user_uid helper, make OTEL dependencies optional in the emitter, and allow unauthenticated ping/version calls.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/otel/types.ts Changes metric timestamp nano field type to string.
src/otel/client/OtelClient.ts Tightens client options (token required) and normalizes metric nano timestamps as strings.
src/otel/auth.ts Trims token, enhances base URL normalization for WebSocket URL building.
datalayer_core/otel/emitter.py Centralizes user UID decoding and makes OpenTelemetry imports optional at runtime.
datalayer_core/otel/client.py Centralizes user UID decoding and adds an option to skip auth headers for health endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread datalayer_core/otel/client.py
Comment thread src/otel/client/OtelClient.ts Outdated
if (Number.isFinite(parsed) && parsed > 0) {
timestampUnixNano = parsed;
const trimmed = rawNano.trim();
if (trimmed.length > 0) {
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizeMetric() now preserves timestamp_unix_nano string values by accepting any non-empty trimmed string. This can propagate non-numeric/negative values (e.g. API returning an error string) into OtelMetric.timestamp_unix_nano, which is supposed to be a nanosecond epoch timestamp for charting. Consider validating that the trimmed value is an integer-like string (digits only) and > 0 before assigning it (similar to the previous numeric parse/finite checks).

Suggested change
if (trimmed.length > 0) {
if (/^\d+$/.test(trimmed) && BigInt(trimmed) > 0n) {

Copilot uses AI. Check for mistakes.
Comment thread src/otel/client/OtelClient.ts
Comment thread src/otel/client/OtelClient.ts
Comment thread src/otel/types.ts
Comment on lines 68 to 70
/** Raw nanosecond timestamp preserved from the backend. */
timestamp_unix_nano?: number;
timestamp_unix_nano?: string;
attributes?: Record<string, unknown>;
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing timestamp_unix_nano from number to string is a public type change that may break downstream code doing numeric comparisons/arithmetic. Since upstream data can arrive as either a JSON number or string and JS numbers can’t safely represent 64-bit nanoseconds, consider typing this as string | number (or documenting explicitly that it is always a string to preserve precision).

Copilot uses AI. Check for mistakes.
Comment thread datalayer_core/otel/emitter.py Outdated
Comment thread datalayer_core/otel/emitter.py
@@ -72,42 +74,37 @@ def __init__(
def _decode_user_uid(token: str | None) -> str | None:
if not token:
return None
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_decode_user_uid() now delegates to logfire.decode_user_uid(), which emits a warning on decode failures. Because token may be a non-JWT API key, initializing OtelClient without an explicit user_uid can produce noisy warnings. Consider only attempting JWT decode when the token matches a JWT shape (3 dot-separated segments) or otherwise suppressing expected decode failures.

Suggested change
return None
return None
parts = token.split(".")
if len(parts) != 3 or not all(parts):
return None

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

@echarles echarles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@echarles echarles merged commit 6eb2e46 into main Apr 17, 2026
14 of 23 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