File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
openhands-sdk/openhands/sdk/observability Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 1- from openhands .sdk .observability .laminar import maybe_init_laminar , observe
1+ from openhands .sdk .observability .laminar import (
2+ init_laminar_for_external ,
3+ maybe_init_laminar ,
4+ observe ,
5+ )
26
37
4- __all__ = ["maybe_init_laminar" , "observe" ]
8+ __all__ = ["init_laminar_for_external" , " maybe_init_laminar" , "observe" ]
Original file line number Diff line number Diff line change @@ -186,3 +186,39 @@ def end_active_span() -> None:
186186 except Exception :
187187 logger .debug ("Error ending active span" )
188188 pass
189+
190+
191+ def init_laminar_for_external ():
192+ """Initialize Laminar for external callers and return parent span context.
193+
194+ This is a convenience function for integrations (e.g., GitHub, Slack webhooks)
195+ that need to:
196+ 1. Initialize Laminar if env vars are set (via maybe_init_laminar)
197+ 2. Capture the parent span context from the external trigger
198+
199+ Returns:
200+ The parent span context if observability is enabled, None otherwise.
201+
202+ Example:
203+ ```python
204+ from openhands.sdk.observability import init_laminar_for_external
205+ from lmnr import Laminar
206+
207+ # At the start of handling an external event (webhook, etc.)
208+ laminar_span_context = init_laminar_for_external()
209+
210+ if laminar_span_context:
211+ with Laminar.start_as_current_span(
212+ name='my-integration',
213+ parent_span_context=laminar_span_context,
214+ ):
215+ # Do work - traces will be children of the external trigger
216+ await do_something()
217+ else:
218+ await do_something()
219+ ```
220+ """
221+ maybe_init_laminar ()
222+ if should_enable_observability ():
223+ return Laminar .get_laminar_span_context ()
224+ return None
You can’t perform that action at this time.
0 commit comments