Skip to content

Commit 35c9e4e

Browse files
committed
feat: add CloudWatchSessionMapper for CW Logs Insights records
Add a new session mapper that converts CloudWatch Logs Insights OTEL log records into typed Session objects for evaluation. The mapper parses body.input/output messages, extracts tool calls/results, and builds InferenceSpan, ToolExecutionSpan, and AgentInvocationSpan instances grouped by traceId. Includes comprehensive unit tests.
1 parent 61599d2 commit 35c9e4e

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

tests_integ/test_cloudwatch_provider.py

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
"""Integration tests for CloudWatchProvider against real CloudWatch Logs data.
22
3-
Requires AWS credentials with CloudWatch Logs read access. Uses the
4-
'strands_github_bot' AWS profile if available, otherwise falls back to default credentials.
3+
Requires the following environment variables:
4+
CLOUDWATCH_TEST_LOG_GROUP — CW Logs group containing agent traces
5+
CLOUDWATCH_TEST_SESSION_ID — session ID with convertible spans
6+
AWS_REGION (optional) — defaults to us-east-1
7+
8+
AWS credentials must be configured via standard mechanisms (env vars, profile, instance role).
9+
510
Run with: pytest tests_integ/test_cloudwatch_provider.py -v
611
"""
712

8-
import boto3
13+
import os
14+
915
import pytest
1016

1117
from strands_evals import Case, Experiment
@@ -27,59 +33,29 @@
2733
Trace,
2834
)
2935

30-
LOG_GROUP = "/aws/bedrock-agentcore/runtimes/github_issue_handler-zf6fZR2saQ-DEFAULT"
31-
32-
KNOWN_SESSION_IDS = [
33-
"github_issue_68_20260218_172558_d27beb07",
34-
"github-issue-68-1771435544179-d5gc8kk4xan",
35-
]
36-
37-
EXPECTED_ACCOUNT_ID = "249746592913"
38-
AWS_PROFILE = "strands_github_bot"
39-
AWS_REGION = "us-east-1"
40-
41-
42-
def _create_logs_client() -> boto3.client | None:
43-
"""Try the named profile first, then fall back to default credentials."""
44-
for profile in [AWS_PROFILE, None]:
45-
try:
46-
session = boto3.Session(profile_name=profile, region_name=AWS_REGION)
47-
sts = session.client("sts")
48-
identity = sts.get_caller_identity()
49-
if identity["Account"] == EXPECTED_ACCOUNT_ID:
50-
return session.client("logs")
51-
except Exception:
52-
continue
53-
return None
54-
5536

5637
@pytest.fixture(scope="module")
5738
def provider():
58-
"""Create a CloudWatchProvider targeting the correct AWS account."""
59-
client = _create_logs_client()
60-
if client is None:
61-
pytest.skip(f"No AWS credentials found for account {EXPECTED_ACCOUNT_ID}")
39+
"""Create a CloudWatchProvider using env var configuration."""
40+
log_group = os.environ.get("CLOUDWATCH_TEST_LOG_GROUP")
41+
if not log_group:
42+
pytest.skip("CLOUDWATCH_TEST_LOG_GROUP not set")
43+
44+
region = os.environ.get("AWS_REGION", "us-east-1")
6245

6346
try:
64-
cw = CloudWatchProvider(log_group=LOG_GROUP, region=AWS_REGION)
47+
return CloudWatchProvider(log_group=log_group, region=region)
6548
except ProviderError as e:
6649
pytest.skip(f"CloudWatch provider creation failed: {e}")
6750

68-
# Inject the verified client
69-
cw._client = client
70-
return cw
71-
7251

7352
@pytest.fixture(scope="module")
74-
def session_id(provider):
75-
"""Try known session IDs; skip if none found."""
76-
for sid in KNOWN_SESSION_IDS:
77-
try:
78-
provider.get_evaluation_data(sid)
79-
return sid
80-
except (SessionNotFoundError, ProviderError):
81-
continue
82-
pytest.skip("No known sessions found in CloudWatch")
53+
def session_id():
54+
"""Get a test session ID from environment variable."""
55+
sid = os.environ.get("CLOUDWATCH_TEST_SESSION_ID")
56+
if not sid:
57+
pytest.skip("CLOUDWATCH_TEST_SESSION_ID not set")
58+
return sid
8359

8460

8561
@pytest.fixture(scope="module")

0 commit comments

Comments
 (0)