mirror of https://github.com/langgenius/dify.git
**Problem:**
The telemetry system had unnecessary abstraction layers and bad practices
from the last 3 commits introducing the gateway implementation:
- TelemetryFacade class wrapper around emit() function
- String literals instead of SignalType enum
- Dictionary mapping enum → string instead of enum → enum
- Unnecessary ENTERPRISE_TELEMETRY_GATEWAY_ENABLED feature flag
- Duplicate guard checks scattered across files
- Non-thread-safe TelemetryGateway singleton pattern
- Missing guard in ops_trace_task.py causing RuntimeError spam
**Solution:**
1. Deleted TelemetryFacade - replaced with thin emit() function in core/telemetry/__init__.py
2. Added SignalType enum ('trace' | 'metric_log') to enterprise/telemetry/contracts.py
3. Replaced CASE_TO_TRACE_TASK_NAME dict with CASE_TO_TRACE_TASK: dict[TelemetryCase, TraceTaskName]
4. Deleted is_gateway_enabled() and _emit_legacy() - using existing ENTERPRISE_ENABLED + ENTERPRISE_TELEMETRY_ENABLED instead
5. Extracted _should_drop_ee_only_event() helper to eliminate duplicate checks
6. Moved TelemetryGateway singleton to ext_enterprise_telemetry.py:
- Init once in init_app() for thread-safety
- Access via get_gateway() function
7. Re-added guard to ops_trace_task.py to prevent RuntimeError when EE=OFF but CE tracing enabled
8. Updated 11 caller files to import 'emit as telemetry_emit' instead of 'TelemetryFacade'
**Result:**
- 322 net lines deleted (533 removed, 211 added)
- All 91 tests pass
- Thread-safe singleton pattern
- Cleaner API surface: from TelemetryFacade.emit() to telemetry_emit()
- Proper enum usage throughout
- No RuntimeError spam in EE=OFF + CE=ON scenario
|
||
|---|---|---|
| .. | ||
| annotation | ||
| rag_pipeline | ||
| workflow_cfs_scheduler | ||
| __init__.py | ||
| add_document_to_index_task.py | ||
| async_workflow_tasks.py | ||
| batch_clean_document_task.py | ||
| batch_create_segment_to_index_task.py | ||
| clean_dataset_task.py | ||
| clean_document_task.py | ||
| clean_notion_document_task.py | ||
| create_segment_to_index_task.py | ||
| deal_dataset_index_update_task.py | ||
| deal_dataset_vector_index_task.py | ||
| delete_account_task.py | ||
| delete_conversation_task.py | ||
| delete_segment_from_index_task.py | ||
| disable_segment_from_index_task.py | ||
| disable_segments_from_index_task.py | ||
| document_indexing_sync_task.py | ||
| document_indexing_task.py | ||
| document_indexing_update_task.py | ||
| duplicate_document_indexing_task.py | ||
| enable_segment_to_index_task.py | ||
| enable_segments_to_index_task.py | ||
| enterprise_telemetry_task.py | ||
| generate_summary_index_task.py | ||
| mail_account_deletion_task.py | ||
| mail_change_mail_task.py | ||
| mail_email_code_login.py | ||
| mail_inner_task.py | ||
| mail_invite_member_task.py | ||
| mail_owner_transfer_task.py | ||
| mail_register_task.py | ||
| mail_reset_password_task.py | ||
| ops_trace_task.py | ||
| process_tenant_plugin_autoupgrade_check_task.py | ||
| recover_document_indexing_task.py | ||
| regenerate_summary_index_task.py | ||
| remove_app_and_related_data_task.py | ||
| remove_document_from_index_task.py | ||
| retry_document_indexing_task.py | ||
| sync_website_document_indexing_task.py | ||
| trigger_processing_tasks.py | ||
| trigger_subscription_refresh_tasks.py | ||
| workflow_draft_var_tasks.py | ||
| workflow_execution_tasks.py | ||
| workflow_node_execution_tasks.py | ||
| workflow_schedule_tasks.py | ||