dify/api/extensions
GareArc 4a9b74f86b
refactor(telemetry): simplify by eliminating TelemetryFacade
**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
2026-02-05 22:41:09 -08:00
..
logstore revert: revert human input relevant code (#31766) 2026-01-30 19:18:49 +08:00
otel feat(telemetry): add input/output token split to enterprise OTEL traces 2026-02-05 20:12:30 -08:00
storage refactor: port api/controllers/console/app/audio.py api/controllers/console/app/message.py api/controllers/console/auth/data_source_oauth.py api/controllers/console/auth/forgot_password.py api/controllers/console/workspace/endpoint.py (#30680) 2026-02-02 18:03:07 +09:00
__init__.py feat: mypy for all type check (#10921) 2024-12-24 18:38:51 +08:00
ext_app_metrics.py Removes the 'extensions' directory from pyrightconfig.json and fixes … (#26512) 2025-10-05 15:57:42 +09:00
ext_blueprints.py fix: allow unauthenticated CORS preflight for embedded bots (#30587) 2026-01-06 11:40:34 +08:00
ext_celery.py revert: revert human input relevant code (#31766) 2026-01-30 19:18:49 +08:00
ext_code_based_extension.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_commands.py feat: archive workflow run logs backend (#31310) 2026-01-23 13:11:56 +08:00
ext_compress.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
ext_database.py fix: fix db env not work (#30541) 2026-01-05 11:10:45 +08:00
ext_enterprise_telemetry.py refactor(telemetry): simplify by eliminating TelemetryFacade 2026-02-05 22:41:09 -08:00
ext_fastopenapi.py refactor: init_validate.py to v3 (#31457) 2026-01-30 22:39:02 +09:00
ext_forward_refs.py feat(api): automatically `NODE_TYPE_CLASSES_MAPPING` generation from node class definitions (#28525) 2025-12-01 14:14:19 +08:00
ext_hosting_provider.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_import_modules.py Removes the 'extensions' directory from pyrightconfig.json and fixes … (#26512) 2025-10-05 15:57:42 +09:00
ext_logging.py feat(refactoring): Support Structured Logging (JSON) (#30170) 2026-01-04 11:46:46 +08:00
ext_login.py revert: "security/fix-swagger-info-leak-m02" (#29721) 2025-12-16 14:19:33 +08:00
ext_logstore.py fix(logstore): prevent SQL injection, fix serialization issues, and optimize initialization (#30697) 2026-01-14 10:21:26 +08:00
ext_mail.py chore: add ast-grep rule to convert Optional[T] to T | None (#25560) 2025-09-15 13:06:33 +08:00
ext_migrate.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
ext_orjson.py remove bare list, dict, Sequence, None, Any (#25058) 2025-09-06 03:32:23 +08:00
ext_otel.py add service layer OTel Span (#28582) 2025-12-05 21:58:32 +08:00
ext_proxy_fix.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
ext_redis.py revert: revert human input relevant code (#31766) 2026-01-30 19:18:49 +08:00
ext_request_logging.py feat: add x-trace-id to http responses and logs (#29015) 2025-12-02 17:22:34 +08:00
ext_sentry.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
ext_session_factory.py refactor: admin api using session factory (#29628) 2025-12-15 12:01:41 +08:00
ext_set_secretkey.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_storage.py Fixes session scope bug in FileService.delete_file (#27911) 2025-11-26 16:21:33 +08:00
ext_timezone.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_warnings.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00