Skip to content

Conversation

@loks0n
Copy link
Contributor

@loks0n loks0n commented Jan 4, 2026

Summary by CodeRabbit

  • New Features

    • Added distributed tracing instrumentation for DNS server operations to enhance observability and monitoring capabilities.
  • Improvements

    • Enhanced error handling with improved error delegation to registered handlers.
    • Reduced verbose console logging for cleaner operation output.
  • Chores

    • Updated dependencies to support new tracing infrastructure.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

Walkthrough

The pull request replaces console-based logging with distributed tracing instrumentation using Span across the DNS Server implementation. The composer.json dependency is updated from utopia-php/console to utopia-php/span. The Server.php class is refactored to instrument packet processing with span-based metrics tracking decode, resolve, and encode operation durations. Error handling is restructured to delegate to registered handlers with span error recording. The test server setup is updated to initialize span storage and exporters with coroutine-based context. No changes are made to public method signatures or class interfaces.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'feat: spans' is vague and generic. While it refers to a real change (adding Span instrumentation), it does not clearly summarize the main purpose or scope of the changes. Consider a more descriptive title such as 'feat: add distributed tracing with Span instrumentation' or 'feat: integrate Span telemetry and replace Console logging' to better communicate the primary changes to reviewers.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
composer.json (1)

23-28: VCS repository is temporary.

The direct VCS repository reference suggests utopia-php/span is not yet published to Packagist. Ensure this is transitioned to a stable package release before merging to production.

src/DNS/Server.php (1)

239-249: Potential nested encoding failure.

If the fallback $response->encode() on Line 249 also throws an exception, it will propagate unhandled. While unlikely, consider whether a final catch or simpler error response (e.g., pre-encoded SERVFAIL bytes) would provide better resilience.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5daf8b6 and dd8928a.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • composer.json
  • src/DNS/Server.php
  • tests/resources/server.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Unit & E2E
🔇 Additional comments (7)
tests/resources/server.php (2)

63-66: LGTM!

The worker startup span instrumentation is appropriate and follows a complete lifecycle (init → set attributes → finish).


10-19: No issues found—Span API usage is correct.

All API calls in the code (Span::setStorage(), Span::addExporter(), Span::init(), $span->set(), and $span->finish()) are documented and properly supported in the utopia-php/span library. The Storage\Coroutine and Exporter\Stdout classes are valid built-in implementations. The integration is sound.

src/DNS/Server.php (5)

167-168: LGTM!

Span initialization with client IP tracking is well-placed at the start of packet processing. This provides good observability for DNS queries.


170-171: LGTM!

Pre-initializing $question and $response to null ensures safe access in the finally block for telemetry recording.


196-211: LGTM!

Question validation with proper error response (FORMERR) and span instrumentation for observability is well-implemented.


213-233: LGTM!

Resolve phase error handling properly returns a SERVFAIL response while recording span errors and metrics. This ensures clients receive appropriate DNS error responses.


258-271: LGTM!

The finally block ensures telemetry is always recorded and the span is properly finished, with appropriate null-safety checks for conditional metrics.

"require": {
"php": ">=8.3",
"utopia-php/console": "0.0.*",
"utopia-php/span": "dev-main",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Version constraint conflicts with minimum stability.

Using "dev-main" for utopia-php/span conflicts with "minimum-stability": "stable" (Line 7). This may cause Composer to fail or require manual intervention during installation.

Recommended fixes:

  1. Use a tagged version with semantic versioning (e.g., "^1.0") once available, OR
  2. Add @dev flag: "utopia-php/span": "dev-main@dev", OR
  3. Change minimum-stability to "dev" with "prefer-stable": true
🔎 Proposed fix using @dev flag
-        "utopia-php/span": "dev-main",
+        "utopia-php/span": "dev-main@dev",
🤖 Prompt for AI Agents
In composer.json around line 31, the dependency "utopia-php/span": "dev-main"
conflicts with "minimum-stability": "stable" (line 7); update the constraint to
a stable tag if available (e.g., "^1.0"), or append the @dev stability flag
("dev-main@dev") to allow this dev branch, or change composer settings to
"minimum-stability": "dev" and add "prefer-stable": true; pick one of these
fixes and apply it consistently to resolve installation failures.

Comment on lines +187 to +191
} catch (Throwable $e) {
$span->setError($e);
$this->handleError($e);
return '';
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the full method context around lines 187-191 in Server.php
cat -n src/DNS/Server.php | sed -n '165,200p'

Repository: utopia-php/dns

Length of output: 1580


🏁 Script executed:

#!/bin/bash
# Search for resolve/encode error handling to understand the pattern
rg -n "SERVFAIL|setError" src/DNS/Server.php | head -20

Repository: utopia-php/dns

Length of output: 278


🏁 Script executed:

#!/bin/bash
# Check how resolve errors are handled
rg -nB5 -A5 "resolve.*catch" src/DNS/Server.php | head -40

Repository: utopia-php/dns

Length of output: 40


🏁 Script executed:

#!/bin/bash
# Get context for lines 210-250 to see resolve/encode error handling
cat -n src/DNS/Server.php | sed -n '210,250p'

Repository: utopia-php/dns

Length of output: 1806


🏁 Script executed:

#!/bin/bash
# Also check what happens after line 190 - is there a caller that handles empty string?
cat -n src/DNS/Server.php | sed -n '145,165p'

Repository: utopia-php/dns

Length of output: 674


🏁 Script executed:

#!/bin/bash
# Check how onPacket is used - see who calls it and what they do with the return value
rg -n "onPacket" src/DNS/Server.php

Repository: utopia-php/dns

Length of output: 344


🏁 Script executed:

#!/bin/bash
# See if there's special handling for empty string returns anywhere in the flow
rg -n "onPacket\|return ''" src/DNS/Server.php -B2 -A2

Repository: utopia-php/dns

Length of output: 40


🏁 Script executed:

#!/bin/bash
# Check the Message::response method to see if it can construct a response without header
fd "Message.php" -t f | xargs cat -n | grep -A20 "function response\|public static function response"

Repository: utopia-php/dns

Length of output: 941


🏁 Script executed:

#!/bin/bash
# Check the PartialDecodingException to see if it extends or relates to other exceptions
fd "PartialDecodingException.php" -t f | head -1 | xargs cat -n

Repository: utopia-php/dns

Length of output: 819


🏁 Script executed:

#!/bin/bash
# Look for other exceptions that might be thrown by Message::decode
rg -n "class.*Exception" src/ --type=php | head -20

Repository: utopia-php/dns

Length of output: 377


🏁 Script executed:

#!/bin/bash
# Check Message::decode to understand what exceptions it can throw
fd "Message.php" -t f | head -1 | xargs cat -n | grep -A50 "public static function decode"

Repository: utopia-php/dns

Length of output: 2157


🏁 Script executed:

#!/bin/bash
# Check the DecodingException class
fd "DecodingException.php" -t f --path "*/Exception/Message/*" | xargs cat -n

Repository: utopia-php/dns

Length of output: 291


🏁 Script executed:

#!/bin/bash
# See how onPacket return value is used in the adapter
fd "Server.php" -t f | xargs cat -n | sed -n '270,285p'

Repository: utopia-php/dns

Length of output: 593


🏁 Script executed:

#!/bin/bash
# Check the adapter to see what happens with empty string returns
rg -n "onPacket|adapter" src/DNS/Server.php | tail -20

Repository: utopia-php/dns

Length of output: 647


🏁 Script executed:

#!/bin/bash
# Find the Adapter interface/class to understand what it expects
fd "Adapter.php" -t f | head -5 | xargs cat -n | head -80

Repository: utopia-php/dns

Length of output: 1077


🏁 Script executed:

#!/bin/bash
# Check if there are any tests for this behavior
fd ".*Test.php|*test.php" -t f | xargs rg -l "onPacket\|decode.*error" | head -5

Repository: utopia-php/dns

Length of output: 368


🏁 Script executed:

#!/bin/bash
# Look for usage of DecodingException vs PartialDecodingException
rg -n "DecodingException" src/ --type=php -C2

Repository: utopia-php/dns

Length of output: 16279


Returning an empty string for fatal decode errors is inconsistent with error handling elsewhere and should be reconsidered.

When decoding fails before the message header can be extracted (e.g., packet too short), the code returns an empty string, meaning no DNS response is sent to the client. This differs from resolve/encode errors, which return a SERVFAIL response. While a SERVFAIL response cannot be constructed without a header, returning an empty string leaves the client without any response, potentially causing timeouts.

Consider whether a minimal response (even just a header) or an alternative error handling strategy would be more appropriate for fatal decode errors.

* @param Throwable $error
* @return void
*/
protected function handleError(Throwable $error): void
Copy link
Member

Choose a reason for hiding this comment

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

do we still need this method?

@loks0n loks0n merged commit 0e0791f into main Jan 4, 2026
4 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.

4 participants