Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions openhands-sdk/openhands/sdk/observability/laminar.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def maybe_init_laminar():

To force HTTP instead of gRPC for Laminar communication:
LMNR_FORCE_HTTP=true # or 1, yes, on

To initialize only selected Laminar integrations:
LMNR_INSTRUMENTS=litellm,mcp
"""
if not should_enable_observability():
logger.debug(
Expand All @@ -99,17 +102,25 @@ def maybe_init_laminar():

base_url = get_env("LMNR_BASE_URL") or None
force_http = _get_bool_env("LMNR_FORCE_HTTP")
instruments_env = get_env("LMNR_INSTRUMENTS")
instruments = (
{Instruments(value.strip()) for value in instruments_env.split(",")}
Comment thread
Shimada666 marked this conversation as resolved.
Outdated
if instruments_env
else None
)

if _is_otel_backend_laminar():
Laminar.initialize(
base_url=base_url,
http_port=_get_int_env("LMNR_HTTP_PORT"),
grpc_port=_get_int_env("LMNR_GRPC_PORT"),
instruments=instruments,
force_http=force_http,
)
else:
# Do not enable browser session replays for non-laminar backends
Laminar.initialize(
instruments=instruments,
disabled_instruments=[
Instruments.BROWSER_USE_SESSION,
Instruments.PATCHRIGHT,
Expand Down
30 changes: 30 additions & 0 deletions tests/sdk/observability/test_laminar.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,36 @@ def test_lmnr_force_http_passed_to_laminar(force_http_value, expected_force_http
del os.environ["LMNR_FORCE_HTTP"]


@pytest.mark.parametrize("is_laminar_backend", [True, False])
def test_lmnr_instruments_passed_to_laminar(is_laminar_backend):
"""LMNR_INSTRUMENTS limits Laminar to the selected integrations."""
from lmnr import Instruments

with patch.dict(
os.environ,
{
"LMNR_PROJECT_API_KEY": "test-key",
"LMNR_INSTRUMENTS": "litellm,mcp",
},
):
with (
patch("lmnr.Laminar") as mock_laminar,
patch(
"openhands.sdk.observability.laminar._is_otel_backend_laminar",
return_value=is_laminar_backend,
),
):
mock_laminar.is_initialized.return_value = False
from openhands.sdk.observability.laminar import maybe_init_laminar

maybe_init_laminar()

assert mock_laminar.initialize.call_args.kwargs["instruments"] == {
Instruments.LITELLM,
Instruments.MCP,
}


# ---------------------------------------------------------------------------
# Cross-context root-span propagation
# ---------------------------------------------------------------------------
Expand Down
Loading