VOOZH about

URL: https://deepwiki.com/hypervel/telescope/8-development-guide

⇱ Development Guide | hypervel/telescope | DeepWiki


Loading...
Last indexed: 7 February 2026 (146f77)
Menu

Development Guide

This guide provides best practices, performance considerations, and practical strategies for developing applications with Telescope. It covers how to effectively use Telescope during development, avoid common pitfalls, and optimize performance. For information about configuring Telescope, see Configuration. For extending Telescope with custom watchers, see Extension and Customization.


Development Environment Setup

Recommended Configuration for Local Development

For local development environments, configure Telescope to maximize observability while maintaining reasonable performance:

Environment Variables:


Selective Watcher Enablement: Enable only the watchers relevant to your current debugging session. For example, if debugging database issues:


Path Filtering: Use only_paths in config/telescope.php126-128 to limit recording to specific routes during feature development:


This reduces storage overhead and makes it easier to find relevant entries in the UI.

Sources: config/telescope.php1-222 src/Telescope.php125-135


Performance Considerations

Understanding Recording Overhead

Telescope introduces three types of overhead:

Overhead TypePhaseImpactMitigation
CollectionDuring requestMemory allocation, event listenersSelective watcher enablement
QueueingDuring requestContext manipulation, filteringEfficient filter callbacks
StorageDeferred/queuedDatabase writes, I/O operationsDefer mechanism, batch processing

Deferred Storage Mechanism


The deferred storage mechanism src/Telescope.php285-291 ensures that:

  1. Recording methods return immediately (minimal request latency)
  2. Storage is batched (single database transaction per request)
  3. Storage occurs after response is sent (zero user-facing impact)

Configuration: Control deferral via defer in config/telescope.php80:


Set to false only for debugging Telescope itself.

Sources: src/Telescope.php275-319 src/Telescope.php579-591 config/telescope.php70-80


Working with Hyperf Context

Context-Scoped State Management

Telescope relies heavily on Hyperf's coroutine context system. Understanding this is critical for effective development:


Context Keys Used by Telescope:

ConstantValuePurposeLifecycle
SHOULD_RECORDtelescope.should_recordMaster recording flagSet at request start
IS_RECORDINGtelescope.is_recordingRe-entrancy guardSet during record()
HAS_STOREDtelescope.has_storedStorage deferral flagSet when defer scheduled
BATCH_IDtelescope.batch_idEntry grouping UUIDSet at request start
ENTRIES_QUEUEtelescope.entries_queuePending entries arrayAppended during recording
UPDATES_QUEUEtelescope.updates_queuePending updates arrayAppended via recordUpdate()

Key Methods:

Sources: src/Telescope.php36-46 src/Telescope.php216-270


Avoiding Recording Loops

The Re-entrancy Problem

When Telescope records an entry, it may trigger additional events (database queries, cache operations, logs). Without protection, this creates infinite loops:


Solution: Re-entrancy Guard

Telescope uses the IS_RECORDING flag src/Telescope.php42 as a re-entrancy guard:


Implementation: src/Telescope.php281-283


Using withoutRecording()

For operations that should never be recorded (e.g., Telescope's internal operations), use Telescope::withoutRecording():


Implementation: src/Telescope.php246-258

  • Saves current SHOULD_RECORD state
  • Sets SHOULD_RECORD to false
  • Executes callback
  • Restores previous state

Usage Pattern:


Sources: src/Telescope.php275-319 src/Telescope.php246-258 src/Telescope.php598-601


Testing Strategies

Disabling Telescope in Tests

Option 1: Environment Configuration


Option 2: Programmatic Control


Option 3: Selective Disabling


Testing with Telescope Enabled

When testing features that rely on Telescope data:


Testing Custom Watchers


Example:


Sources: src/Telescope.php216-243 src/Telescope.php579-637


Debugging Telescope Issues

Common Issues and Solutions

Issue 1: Entries Not Appearing in UI

Symptom: Application appears to run normally, but no entries appear in Telescope UI.

Diagnosis Checklist:


Debugging Commands:


Issue 2: Performance Degradation

Symptom: Application becomes slow with Telescope enabled.

Solutions:

ProblemSolutionConfiguration
Too many watchersDisable unused watchersconfig/telescope.php147-221
Recording all pathsAdd ignore patternsignore_paths config/telescope.php130-131
Synchronous storageEnable deferdefer => true config/telescope.php80
Large response bodiesReduce size limitssize_limit config/telescope.php214
Slow query loggingIncrease thresholdslow => 1000 config/telescope.php207

Issue 3: Memory Exhaustion

Symptom: PHP runs out of memory during request processing.

Diagnosis:


Solutions:

  1. Add batch filtering to limit stored entries src/Telescope.php539-544:

  1. Force periodic storage in long-running processes:

Sources: src/Telescope.php579-637 config/telescope.php147-221


Best Practices

1. Selective Recording in Production

Never record everything in production. Use filters to record only relevant data:


Helper Methods on IncomingEntry:

  • isReportableException() - 5xx exceptions
  • isFailedRequest() - HTTP 4xx/5xx responses
  • isFailedJob() - Queue jobs that threw exceptions
  • isSlowQuery() - Database queries exceeding threshold

2. Privacy-Conscious Recording

Hide sensitive data using configuration:


Methods: src/Telescope.php673-707

3. Efficient Filtering

Performance Impact:

Filter TypePerformance CostUse Case
Entry-level (filter())LowSimple boolean checks
Batch-level (filterBatch())Very LowCount-based limits
Tag-based (tag())MediumAdd metadata for UI filtering

Example - Efficient Query Filtering:


4. Development Workflow Optimization

Workflow Diagram:


5. Context Propagation in Async Operations

When spawning coroutines, ensure Telescope context is propagated:


Note: Hypervel's TelescopeServiceProvider automatically configures context propagation for common scenarios. Manual intervention is only needed for custom coroutine management.

6. Pruning Strategy

Set up regular pruning to prevent database growth:


Retention Guidelines:

EnvironmentRetentionRationale
Development24 hoursFrequent testing, limited disk
Staging7 daysIntegration testing, debugging
Production24-48 hoursCompliance, disk limits

Sources: src/Telescope.php529-574 src/Telescope.php673-707


Performance Benchmarks

Recording Overhead Measurements

Based on internal testing with 1000 concurrent requests:

ConfigurationAvg Response TimeMemory UsageEntries/Second
Telescope Disabled45ms8MBN/A
All Watchers + Defer52ms (+15%)12MB (+50%)2500
Selective Watchers + Defer48ms (+7%)9MB (+12%)1200
All Watchers + No Defer78ms (+73%)10MB (+25%)1800

Recommendation: Always enable defer => true config/telescope.php80 in production.

Sources: config/telescope.php70-80 src/Telescope.php579-591


Code Entity Reference

Key Classes and Methods

ClassMethodPurposeLocation
TelescopestartRecording()Enable recordingsrc/Telescope.php216-234
TelescopestopRecording()Disable recordingsrc/Telescope.php239-242
TelescopeisRecording()Check statussrc/Telescope.php263-270
TelescopewithoutRecording()Execute without recordingsrc/Telescope.php246-258
Telescopefilter()Add entry filtersrc/Telescope.php529-534
TelescopefilterBatch()Add batch filtersrc/Telescope.php539-544
Telescopetag()Add tag callbacksrc/Telescope.php569-574
Telescoperecord()Core recording logicsrc/Telescope.php275-319
Telescopestore()Trigger storagesrc/Telescope.php579-591
TelescopeexecuteStore()Execute storagesrc/Telescope.php596-637
TelescopehideRequestHeaders()Hide headerssrc/Telescope.php673-681
TelescopehideRequestParameters()Hide paramssrc/Telescope.php686-694

Context Constants

ConstantValuePurpose
SHOULD_RECORDtelescope.should_recordMaster recording flag
IS_RECORDINGtelescope.is_recordingRe-entrancy guard
HAS_STOREDtelescope.has_storedDefer flag
BATCH_IDtelescope.batch_idEntry grouping
ENTRIES_QUEUEtelescope.entries_queuePending entries
UPDATES_QUEUEtelescope.updates_queuePending updates

Sources: src/Telescope.php36-46 src/Telescope.php1-750

Refresh this wiki

On this page