Module: PlatformSdk::Observability::Langfuse::Traceable::PerformWrapper
- Defined in:
- lib/platform_sdk/observability/langfuse/traceable.rb
Overview
PerformWrapper is prepended into the including class so that its perform override runs before the class’s own perform definition, regardless of the order in which include and def appear.
Constant Summary collapse
- REENTRY_KEY =
:platform_sdk_langfuse_traceable_active
Instance Method Summary collapse
Instance Method Details
#perform(*args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/platform_sdk/observability/langfuse/traceable.rb', line 17 def perform(*args) return super(*args) unless PlatformSdk::Observability::Langfuse.enabled? # Re-entry guard: subclass `inherited` re-prepends PerformWrapper at # every level of the ancestry, so a subclass `perform` that calls # `super` would otherwise hit the wrapper at each intermediate class # and open one span per level. Only the outermost wrapper opens a # span; inner re-entries just delegate. return super(*args) if Thread.current[REENTRY_KEY] Thread.current[REENTRY_KEY] = true begin tracer = PlatformSdk::Observability::Langfuse.tracer tracer.in_span(self.class.langfuse_span_name, attributes: safe_langfuse_span_attributes(args)) do super(*args) end ensure Thread.current[REENTRY_KEY] = false PlatformSdk::Observability::Langfuse.clear_tracked_thread_locals! end end |