Skip to content

Commit 535ce33

Browse files
CopilotnikhilNava
andcommitted
refactor: Address code review feedback - move imports to module level
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
1 parent e3efbb0 commit 535ce33

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import Any, Generic, TypeVar, cast
1616

1717
from opentelemetry import context
18+
from opentelemetry.propagate import extract
1819
from opentelemetry.semconv.attributes.exception_attributes import (
1920
EXCEPTION_MESSAGE,
2021
EXCEPTION_STACKTRACE,
@@ -50,8 +51,6 @@ def extract_trace_context(headers: dict[str, str]) -> context.Context:
5051
>>> with InferenceScope.start(details, agent, tenant, parent_context=parent_context):
5152
... pass
5253
"""
53-
from opentelemetry.propagate import extract
54-
5554
return extract(headers)
5655

5756

tests/observability/core/test_trace_context_propagation.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
"""Tests for trace context propagation functionality."""
55

66
import os
7-
import sys
87
import unittest
9-
from pathlib import Path
8+
from urllib.parse import urlparse
109

1110
import pytest
1211
from microsoft_agents_a365.observability.core import (
@@ -212,12 +211,6 @@ def test_inject_headers_for_http_propagation(self):
212211
headers = scope.inject_trace_context()
213212
scope.dispose()
214213

215-
# Parse the traceparent to get trace_id and span_id
216-
traceparent = headers["traceparent"]
217-
parts = traceparent.split("-")
218-
trace_id = parts[1]
219-
span_id = parts[2]
220-
221214
# Simulate receiving these headers and creating a child scope
222215
parent_ctx = extract_trace_context(headers)
223216

@@ -249,8 +242,6 @@ def test_inject_headers_for_http_propagation(self):
249242

250243
def test_invoke_agent_scope_with_parent_context(self):
251244
"""Test InvokeAgentScope with parent_context parameter."""
252-
from urllib.parse import urlparse
253-
254245
parent_trace_id = "1234567890abcdef1234567890abcdef"
255246
parent_span_id = "abcdefabcdef1234"
256247
traceparent = f"00-{parent_trace_id}-{parent_span_id}-01"
@@ -285,4 +276,7 @@ def test_invoke_agent_scope_with_parent_context(self):
285276

286277

287278
if __name__ == "__main__":
279+
import sys
280+
from pathlib import Path
281+
288282
sys.exit(pytest.main([str(Path(__file__))] + sys.argv[1:]))

0 commit comments

Comments
 (0)