mirror of
https://github.com/langgenius/dify.git
synced 2026-09-21 05:11:22 +08:00
feat: knowledge add more trace (#38959)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from extensions.otel.context import propagate_context
|
||||
from extensions.otel.decorators.base import trace_span
|
||||
from extensions.otel.decorators.handler import SpanHandler
|
||||
from extensions.otel.decorators.handlers.generate_handler import AppGenerateHandler
|
||||
@@ -7,5 +8,6 @@ __all__ = [
|
||||
"AppGenerateHandler",
|
||||
"SpanHandler",
|
||||
"WorkflowAppRunnerHandler",
|
||||
"propagate_context",
|
||||
"trace_span",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
"""Utilities for propagating OpenTelemetry context across execution boundaries."""
|
||||
|
||||
import functools
|
||||
from collections.abc import Callable
|
||||
|
||||
from opentelemetry import context as otel_context
|
||||
|
||||
|
||||
def propagate_context[**P, R](func: Callable[P, R]) -> Callable[P, R]:
|
||||
"""Capture the current context and attach it whenever ``func`` executes."""
|
||||
captured_context = otel_context.get_current()
|
||||
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
||||
token = otel_context.attach(captured_context)
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
finally:
|
||||
otel_context.detach(token)
|
||||
|
||||
return wrapper
|
||||
Reference in New Issue
Block a user