2024-11-08 06:43:47 +00:00
|
|
|
import json
|
2024-06-27 16:24:37 +00:00
|
|
|
import logging
|
|
|
|
|
|
2025-08-24 15:07:22 +00:00
|
|
|
from celery import shared_task
|
2024-06-27 16:24:37 +00:00
|
|
|
from flask import current_app
|
|
|
|
|
|
2024-11-08 06:43:47 +00:00
|
|
|
from core.ops.entities.config_entity import OPS_FILE_PATH, OPS_TRACE_FAILED_KEY
|
2024-06-27 16:24:37 +00:00
|
|
|
from core.ops.entities.trace_entity import trace_info_info_map
|
|
|
|
|
from core.rag.models.document import Document
|
2024-11-08 06:43:47 +00:00
|
|
|
from extensions.ext_redis import redis_client
|
|
|
|
|
from extensions.ext_storage import storage
|
2024-06-27 16:24:37 +00:00
|
|
|
from models.model import Message
|
|
|
|
|
from models.workflow import WorkflowRun
|
|
|
|
|
|
2025-08-26 10:10:31 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2024-06-27 16:24:37 +00:00
|
|
|
|
2024-08-26 05:38:37 +00:00
|
|
|
@shared_task(queue="ops_trace")
|
2024-11-08 06:43:47 +00:00
|
|
|
def process_trace_tasks(file_info):
|
2024-06-27 16:24:37 +00:00
|
|
|
"""
|
|
|
|
|
Async process trace tasks
|
|
|
|
|
Usage: process_trace_tasks.delay(tasks_data)
|
|
|
|
|
"""
|
|
|
|
|
from core.ops.ops_trace_manager import OpsTraceManager
|
|
|
|
|
|
2024-11-08 06:43:47 +00:00
|
|
|
app_id = file_info.get("app_id")
|
|
|
|
|
file_id = file_info.get("file_id")
|
|
|
|
|
file_path = f"{OPS_FILE_PATH}{app_id}/{file_id}.json"
|
|
|
|
|
file_data = json.loads(storage.load(file_path))
|
|
|
|
|
trace_info = file_data.get("trace_info")
|
|
|
|
|
trace_info_type = file_data.get("trace_info_type")
|
2024-08-03 16:05:51 +00:00
|
|
|
trace_instance = OpsTraceManager.get_ops_trace_instance(app_id)
|
2024-06-27 16:24:37 +00:00
|
|
|
|
2024-08-26 05:38:37 +00:00
|
|
|
if trace_info.get("message_data"):
|
|
|
|
|
trace_info["message_data"] = Message.from_dict(data=trace_info["message_data"])
|
|
|
|
|
if trace_info.get("workflow_data"):
|
|
|
|
|
trace_info["workflow_data"] = WorkflowRun.from_dict(data=trace_info["workflow_data"])
|
|
|
|
|
if trace_info.get("documents"):
|
2025-10-10 08:30:13 +00:00
|
|
|
trace_info["documents"] = [Document.model_validate(doc) for doc in trace_info["documents"]]
|
2024-06-27 16:24:37 +00:00
|
|
|
|
|
|
|
|
try:
|
feat(telemetry): add enterprise OTEL telemetry with gateway, traces, metrics, and logs
Enterprise-only observability layer that emits OpenTelemetry traces, metrics,
and logs for workflow executions, LLM calls, message processing, and node runs.
Key components:
- core/telemetry: CE-safe gateway and event facade (no-ops when EE disabled)
- enterprise/telemetry: full trace/metric/log pipeline with OTLP exporter
- extensions/ext_enterprise_telemetry: Flask extension for lifecycle management
- tasks/enterprise_telemetry_task: Celery task for async metric dispatch
Wiring changes:
- app_factory: register ext_enterprise_telemetry extension
- ext_celery: conditionally import enterprise_telemetry_task
- configs/enterprise: add EnterpriseTelemetryConfig with OTLP settings
- ops_trace_manager: add enterprise telemetry hooks with lazy imports
- trace_entity: add new trace types (WorkflowNode, PromptGeneration, DraftNode)
- ext_otel: improve gRPC TLS auto-detection and optional auth headers
All enterprise imports are guarded behind ENTERPRISE_ENABLED +
ENTERPRISE_TELEMETRY_ENABLED feature flags with graceful fallbacks.
2026-03-24 03:53:14 +00:00
|
|
|
trace_type = trace_info_info_map.get(trace_info_type)
|
|
|
|
|
if trace_type:
|
|
|
|
|
trace_info = trace_type(**trace_info)
|
|
|
|
|
|
|
|
|
|
from extensions.ext_enterprise_telemetry import is_enabled as is_ee_telemetry_enabled
|
|
|
|
|
|
|
|
|
|
if is_ee_telemetry_enabled():
|
|
|
|
|
from enterprise.telemetry.enterprise_trace import EnterpriseOtelTrace
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
EnterpriseOtelTrace().trace(trace_info)
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.exception("Enterprise trace failed for app_id: %s", app_id)
|
|
|
|
|
|
2024-06-27 16:24:37 +00:00
|
|
|
if trace_instance:
|
|
|
|
|
with current_app.app_context():
|
|
|
|
|
trace_instance.trace(trace_info)
|
feat(telemetry): add enterprise OTEL telemetry with gateway, traces, metrics, and logs
Enterprise-only observability layer that emits OpenTelemetry traces, metrics,
and logs for workflow executions, LLM calls, message processing, and node runs.
Key components:
- core/telemetry: CE-safe gateway and event facade (no-ops when EE disabled)
- enterprise/telemetry: full trace/metric/log pipeline with OTLP exporter
- extensions/ext_enterprise_telemetry: Flask extension for lifecycle management
- tasks/enterprise_telemetry_task: Celery task for async metric dispatch
Wiring changes:
- app_factory: register ext_enterprise_telemetry extension
- ext_celery: conditionally import enterprise_telemetry_task
- configs/enterprise: add EnterpriseTelemetryConfig with OTLP settings
- ops_trace_manager: add enterprise telemetry hooks with lazy imports
- trace_entity: add new trace types (WorkflowNode, PromptGeneration, DraftNode)
- ext_otel: improve gRPC TLS auto-detection and optional auth headers
All enterprise imports are guarded behind ENTERPRISE_ENABLED +
ENTERPRISE_TELEMETRY_ENABLED feature flags with graceful fallbacks.
2026-03-24 03:53:14 +00:00
|
|
|
|
2025-08-26 10:10:31 +00:00
|
|
|
logger.info("Processing trace tasks success, app_id: %s", app_id)
|
2025-04-26 11:28:30 +00:00
|
|
|
except Exception as e:
|
feat(telemetry): add enterprise OTEL telemetry with gateway, traces, metrics, and logs
Enterprise-only observability layer that emits OpenTelemetry traces, metrics,
and logs for workflow executions, LLM calls, message processing, and node runs.
Key components:
- core/telemetry: CE-safe gateway and event facade (no-ops when EE disabled)
- enterprise/telemetry: full trace/metric/log pipeline with OTLP exporter
- extensions/ext_enterprise_telemetry: Flask extension for lifecycle management
- tasks/enterprise_telemetry_task: Celery task for async metric dispatch
Wiring changes:
- app_factory: register ext_enterprise_telemetry extension
- ext_celery: conditionally import enterprise_telemetry_task
- configs/enterprise: add EnterpriseTelemetryConfig with OTLP settings
- ops_trace_manager: add enterprise telemetry hooks with lazy imports
- trace_entity: add new trace types (WorkflowNode, PromptGeneration, DraftNode)
- ext_otel: improve gRPC TLS auto-detection and optional auth headers
All enterprise imports are guarded behind ENTERPRISE_ENABLED +
ENTERPRISE_TELEMETRY_ENABLED feature flags with graceful fallbacks.
2026-03-24 03:53:14 +00:00
|
|
|
logger.exception("Processing trace tasks failed, app_id: %s", app_id)
|
2024-11-08 06:43:47 +00:00
|
|
|
failed_key = f"{OPS_TRACE_FAILED_KEY}_{app_id}"
|
|
|
|
|
redis_client.incr(failed_key)
|
|
|
|
|
finally:
|
feat(telemetry): add enterprise OTEL telemetry with gateway, traces, metrics, and logs
Enterprise-only observability layer that emits OpenTelemetry traces, metrics,
and logs for workflow executions, LLM calls, message processing, and node runs.
Key components:
- core/telemetry: CE-safe gateway and event facade (no-ops when EE disabled)
- enterprise/telemetry: full trace/metric/log pipeline with OTLP exporter
- extensions/ext_enterprise_telemetry: Flask extension for lifecycle management
- tasks/enterprise_telemetry_task: Celery task for async metric dispatch
Wiring changes:
- app_factory: register ext_enterprise_telemetry extension
- ext_celery: conditionally import enterprise_telemetry_task
- configs/enterprise: add EnterpriseTelemetryConfig with OTLP settings
- ops_trace_manager: add enterprise telemetry hooks with lazy imports
- trace_entity: add new trace types (WorkflowNode, PromptGeneration, DraftNode)
- ext_otel: improve gRPC TLS auto-detection and optional auth headers
All enterprise imports are guarded behind ENTERPRISE_ENABLED +
ENTERPRISE_TELEMETRY_ENABLED feature flags with graceful fallbacks.
2026-03-24 03:53:14 +00:00
|
|
|
try:
|
|
|
|
|
storage.delete(file_path)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.warning(
|
|
|
|
|
"Failed to delete trace file %s for app_id %s: %s",
|
|
|
|
|
file_path,
|
|
|
|
|
app_id,
|
|
|
|
|
e,
|
|
|
|
|
)
|