Skip to content

Commit d19e256

Browse files
committed
added test skipping if no AWS keys are found
1 parent 23e0f2c commit d19e256

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test-opentelemetry-instrumentation-langchain-v2/test_agents.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,35 @@
77

88
import boto3
99
import pytest
10+
from botocore.exceptions import ClientError, NoCredentialsError
1011
from langchain import hub
1112
from langchain.agents import AgentExecutor, create_tool_calling_agent
1213
from langchain_aws import ChatBedrock
1314
from langchain_community.tools import DuckDuckGoSearchResults
1415

1516

17+
def has_aws_credentials():
18+
"""Check if AWS credentials are available."""
19+
# Check for environment variables first
20+
if os.environ.get("AWS_ACCESS_KEY_ID") and os.environ.get("AWS_SECRET_ACCESS_KEY"):
21+
return True
22+
23+
# Try to create a boto3 client and make a simple call
24+
try:
25+
# Using STS for a lightweight validation
26+
sts = boto3.client("sts")
27+
sts.get_caller_identity()
28+
return True
29+
except (NoCredentialsError, ClientError):
30+
return False
31+
32+
33+
aws_credentials_required = pytest.mark.skipif(
34+
not has_aws_credentials(), reason="AWS credentials not available for testing"
35+
)
36+
37+
38+
@aws_credentials_required
1639
@pytest.mark.vcr(filter_headers=["Authorization", "X-Amz-Date", "X-Amz-Security-Token"], record_mode="all")
1740
def test_agents(instrument_langchain, span_exporter):
1841
search = DuckDuckGoSearchResults()
@@ -63,6 +86,7 @@ def test_agents(instrument_langchain, span_exporter):
6386
}
6487

6588

89+
@aws_credentials_required
6690
@pytest.mark.vcr
6791
def test_agents_with_events_with_content(instrument_with_content, span_exporter, log_exporter):
6892
search = DuckDuckGoSearchResults()
@@ -103,6 +127,7 @@ def test_agents_with_events_with_content(instrument_with_content, span_exporter,
103127
}
104128

105129

130+
@aws_credentials_required
106131
@pytest.mark.vcr
107132
def test_agents_with_events_with_no_content(instrument_langchain, span_exporter):
108133
search = DuckDuckGoSearchResults()

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test-opentelemetry-instrumentation-langchain-v2/test_langgraph_agent.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,36 @@
88

99
import boto3
1010
import pytest
11+
from botocore.exceptions import ClientError, NoCredentialsError
1112
from langchain_aws import ChatBedrock
1213
from langgraph.graph import StateGraph
1314

1415
from opentelemetry import trace
1516
from opentelemetry.trace import INVALID_SPAN
1617

1718

19+
def has_aws_credentials():
20+
"""Check if AWS credentials are available."""
21+
# Check for environment variables first
22+
if os.environ.get("AWS_ACCESS_KEY_ID") and os.environ.get("AWS_SECRET_ACCESS_KEY"):
23+
return True
24+
25+
# Try to create a boto3 client and make a simple call
26+
try:
27+
# Using STS for a lightweight validation
28+
sts = boto3.client("sts")
29+
sts.get_caller_identity()
30+
return True
31+
except (NoCredentialsError, ClientError):
32+
return False
33+
34+
35+
aws_credentials_required = pytest.mark.skipif(
36+
not has_aws_credentials(), reason="AWS credentials not available for testing"
37+
)
38+
39+
40+
@aws_credentials_required
1841
@pytest.mark.vcr(filter_headers=["Authorization", "X-Amz-Date", "X-Amz-Security-Token"], record_mode="once")
1942
def test_langgraph_invoke(instrument_langchain, span_exporter):
2043
span_exporter.clear()
@@ -86,6 +109,7 @@ def calculate(state: State):
86109
assert response in langgraph_span.attributes["gen_ai.completion"]
87110

88111

112+
@aws_credentials_required
89113
@pytest.mark.vcr
90114
@pytest.mark.asyncio
91115
# @pytest.mark.xfail(reason="Context propagation is not yet supported for async LangChain callbacks", strict=True)
@@ -127,6 +151,7 @@ def calculate(state: State):
127151
assert llm_span.parent.span_id == calculate_task_span.context.span_id
128152

129153

154+
@aws_credentials_required
130155
@pytest.mark.vcr
131156
def test_langgraph_double_invoke(instrument_langchain, span_exporter):
132157
span_exporter.clear()
@@ -169,6 +194,7 @@ def build_graph():
169194
] == [span.name for span in spans]
170195

171196

197+
@aws_credentials_required
172198
@pytest.mark.vcr
173199
@pytest.mark.asyncio
174200
async def test_langgraph_double_ainvoke(instrument_langchain, span_exporter):

0 commit comments

Comments
 (0)