|
| 1 | +from unittest.mock import patch |
| 2 | + |
| 3 | + |
| 4 | +from agentops.sdk.core import tracer |
| 5 | +from agentops.sdk.attributes import get_global_resource_attributes |
| 6 | +from agentops.semconv.resource import ResourceAttributes |
| 7 | + |
| 8 | + |
| 9 | +@patch("agentops.sdk.attributes.get_imported_libraries", return_value=["agentops"]) |
| 10 | +def test_global_resource_attributes_no_system(mock_libs): |
| 11 | + attrs = get_global_resource_attributes("svc", project_id="proj") |
| 12 | + assert attrs[ResourceAttributes.SERVICE_NAME] == "svc" |
| 13 | + assert attrs[ResourceAttributes.PROJECT_ID] == "proj" |
| 14 | + assert ResourceAttributes.IMPORTED_LIBRARIES in attrs |
| 15 | + assert ResourceAttributes.HOST_MACHINE not in attrs |
| 16 | + assert ResourceAttributes.CPU_COUNT not in attrs |
| 17 | + |
| 18 | + |
| 19 | +@patch("agentops.sdk.core.get_system_resource_attributes") |
| 20 | +def test_system_metadata_only_for_session(mock_sys_attrs, instrumentation): |
| 21 | + mock_sys_attrs.return_value = {ResourceAttributes.HOST_MACHINE: "test"} |
| 22 | + |
| 23 | + ctx = tracer.start_trace("session") |
| 24 | + tracer.end_trace(ctx, end_state="Success") |
| 25 | + spans = instrumentation.get_finished_spans() |
| 26 | + assert len(spans) == 1 |
| 27 | + assert spans[0].attributes.get(ResourceAttributes.HOST_MACHINE) == "test" |
| 28 | + |
| 29 | + instrumentation.clear_spans() |
| 30 | + |
| 31 | + ctx = tracer.start_trace("custom") |
| 32 | + tracer.end_trace(ctx, end_state="Success") |
| 33 | + spans = instrumentation.get_finished_spans() |
| 34 | + assert len(spans) == 1 |
| 35 | + assert ResourceAttributes.HOST_MACHINE not in spans[0].attributes |
0 commit comments