ddapm-test-agent 1.33.1__py3-none-any.whl → 1.34.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ddapm_test_agent/agent.py CHANGED
@@ -831,7 +831,6 @@ class Agent:
831
831
  "peer_tags": ["db.name", "mongodb.db", "messaging.system"],
832
832
  "span_events": True, # Advertise support for the top-level Span field for Span Events
833
833
  },
834
- headers={"Datadog-Agent-State": "03e868b3ecdd62a91423cc4c3917d0d151fb9fa486736911ab7f5a0750c63824"},
835
834
  )
836
835
 
837
836
  async def _handle_traces(self, request: Request, version: Literal["v0.4", "v0.5", "v0.7", "v1"]) -> web.Response:
@@ -1356,6 +1355,7 @@ def make_app(
1356
1355
  snapshot_removed_attrs: List[str],
1357
1356
  snapshot_regex_placeholders: Dict[str, str],
1358
1357
  vcr_cassettes_directory: str,
1358
+ vcr_ci_mode: bool,
1359
1359
  ) -> web.Application:
1360
1360
  agent = Agent()
1361
1361
  app = web.Application(
@@ -1417,7 +1417,7 @@ def make_app(
1417
1417
  web.route(
1418
1418
  "*",
1419
1419
  "/vcr/{path:.*}",
1420
- lambda request: proxy_request(request, vcr_cassettes_directory),
1420
+ lambda request: proxy_request(request, vcr_cassettes_directory, vcr_ci_mode),
1421
1421
  ),
1422
1422
  ]
1423
1423
  )
@@ -1582,6 +1582,12 @@ def main(args: Optional[List[str]] = None) -> None:
1582
1582
  default=os.environ.get("VCR_CASSETTES_DIRECTORY", os.path.join(os.getcwd(), "vcr-cassettes")),
1583
1583
  help="Directory to read and store third party API cassettes.",
1584
1584
  )
1585
+ parser.add_argument(
1586
+ "--vcr-ci-mode",
1587
+ type=bool,
1588
+ default=os.environ.get("VCR_CI_MODE", False),
1589
+ help="Will change the test agent to record VCR cassettes in CI mode, throwing an error if a cassette is not found on /vcr/{provider}",
1590
+ )
1585
1591
  parsed_args = parser.parse_args(args=args)
1586
1592
  logging.basicConfig(level=parsed_args.log_level)
1587
1593
 
@@ -1625,6 +1631,7 @@ def main(args: Optional[List[str]] = None) -> None:
1625
1631
  snapshot_removed_attrs=parsed_args.snapshot_removed_attrs,
1626
1632
  snapshot_regex_placeholders=parsed_args.snapshot_regex_placeholders,
1627
1633
  vcr_cassettes_directory=parsed_args.vcr_cassettes_directory,
1634
+ vcr_ci_mode=parsed_args.vcr_ci_mode,
1628
1635
  )
1629
1636
 
1630
1637
  # Validate port configuration
@@ -146,7 +146,7 @@ def generate_cassette_name(path: str, method: str, body: bytes, vcr_cassette_pre
146
146
  )
147
147
 
148
148
 
149
- async def proxy_request(request: Request, vcr_cassettes_directory: str) -> Response:
149
+ async def proxy_request(request: Request, vcr_cassettes_directory: str, vcr_ci_mode: bool) -> Response:
150
150
  path = request.match_info["path"]
151
151
  if request.query_string:
152
152
  path = path + "?" + request.query_string
@@ -159,15 +159,22 @@ async def proxy_request(request: Request, vcr_cassettes_directory: str) -> Respo
159
159
  if provider not in PROVIDER_BASE_URLS:
160
160
  return Response(body=f"Unsupported provider: {provider}", status=400)
161
161
 
162
- target_url = url_path_join(PROVIDER_BASE_URLS[provider], remaining_path)
163
-
164
- headers = {key: value for key, value in request.headers.items() if key != "Host"}
165
-
166
162
  body_bytes = await request.read()
167
163
 
168
164
  vcr_cassette_prefix = request.pop("vcr_cassette_prefix", None)
169
165
  cassette_name = generate_cassette_name(path, request.method, body_bytes, vcr_cassette_prefix)
170
166
  cassette_file_name = f"{cassette_name}.yaml"
167
+ cassette_file_path = os.path.join(vcr_cassettes_directory, provider, cassette_file_name)
168
+ cassette_exists = os.path.exists(cassette_file_path)
169
+
170
+ if vcr_ci_mode and not cassette_exists:
171
+ return Response(
172
+ body=f"Cassette {cassette_file_name} not found while running in CI mode. Please generate the cassette locally and commit it.",
173
+ status=500,
174
+ )
175
+
176
+ target_url = url_path_join(PROVIDER_BASE_URLS[provider], remaining_path)
177
+ headers = {key: value for key, value in request.headers.items() if key != "Host"}
171
178
 
172
179
  request_kwargs: Dict[str, Any] = {
173
180
  "method": request.method,
@@ -179,9 +186,7 @@ async def proxy_request(request: Request, vcr_cassettes_directory: str) -> Respo
179
186
  "stream": True,
180
187
  }
181
188
 
182
- if provider in AWS_SERVICES and not os.path.exists(
183
- os.path.join(vcr_cassettes_directory, provider, cassette_file_name)
184
- ):
189
+ if provider in AWS_SERVICES and not cassette_exists:
185
190
  if not AWS_SECRET_ACCESS_KEY:
186
191
  return Response(
187
192
  body="AWS_SECRET_ACCESS_KEY environment variable not set for aws signature recalculation",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ddapm-test-agent
3
- Version: 1.33.1
3
+ Version: 1.34.0
4
4
  Summary: Test agent for Datadog APM client libraries
5
5
  Home-page: https://github.com/Datadog/dd-apm-test-agent
6
6
  Author: Kyle Verhoog
@@ -240,6 +240,10 @@ And pass in a valid API key (if needed) in the way that provider expects.
240
240
 
241
241
  To redact api keys, modify the `filter_headers` list in the `get_vcr` function in `ddapm_test_agent/vcr_proxy.py`. This can be confirmed by viewing cassettes in the `vcr-cassettes` directory (or the otherwise specified directory), and verifying that any new cassettes do not contain the api key.
242
242
 
243
+ #### Running in CI
244
+
245
+ To have the vcr proxy throw a 404 error if a cassette is not found in CI mode to ensure that all cassettes are generated locally and committed, set the `VCR_CI_MODE` environment variable or the `--vcr-ci-mode` flag in the cli tool to `true` (this value defaults to `false`).
246
+
243
247
  ## Configuration
244
248
 
245
249
  The test agent can be configured via command-line options or via environment variables.
@@ -1,5 +1,5 @@
1
1
  ddapm_test_agent/__init__.py,sha256=IEYMDM-xI0IoHYSYw4Eva5263puB_crrrbLstOCScRw,106
2
- ddapm_test_agent/agent.py,sha256=296wweDNsF7cw5QuGdSzbKa4vWrVpea3rvZU4Laddkc,74000
2
+ ddapm_test_agent/agent.py,sha256=Wt1L-z9g8pSc22FWa6rGfUaTpGIk7_GBwLl3c94RD6o,74240
3
3
  ddapm_test_agent/apmtelemetry.py,sha256=w_9-yUDh1dgox-FfLqeOHU2C14GcjOjen-_SVagiZrc,861
4
4
  ddapm_test_agent/checks.py,sha256=pBa4YKZQVA8qaTVJ_XgMA6TmlUZNh99YOrCFJA7fwo0,6865
5
5
  ddapm_test_agent/client.py,sha256=ViEmiRX9Y3SQ-KBhSc-FdzBmIVIe8Ij9jj-Q6VGyzLY,7359
@@ -16,11 +16,11 @@ ddapm_test_agent/trace_snapshot.py,sha256=ayOUcCFo6xyotFRm0fSNdeA91_T447W5ShlkRv
16
16
  ddapm_test_agent/tracerflare.py,sha256=uoSjhPCOKZflgJn5JLv1Unh4gUdAR1-YbC9_1n1iH9w,954
17
17
  ddapm_test_agent/tracestats.py,sha256=q_WQZnh2kXSSN3fRIBe_0jMYCBQHcaS3fZmJTge4lWc,2073
18
18
  ddapm_test_agent/tracestats_snapshot.py,sha256=VsB6MVnHPjPWHVWnnDdCXJcVKL_izKXEf9lvJ0qbjNQ,3609
19
- ddapm_test_agent/vcr_proxy.py,sha256=jTm9Q0LeWOUJrwlDrG632WrQB6ScWvjb3dLR7oSFa6o,6808
20
- ddapm_test_agent-1.33.1.dist-info/licenses/LICENSE.BSD3,sha256=J9S_Tq-hhvteDV2W8R0rqht5DZHkmvgdx3gnLZg4j6Q,1493
21
- ddapm_test_agent-1.33.1.dist-info/licenses/LICENSE.apache2,sha256=5V2RruBHZQIcPyceiv51DjjvdvhgsgS4pnXAOHDuZkQ,11342
22
- ddapm_test_agent-1.33.1.dist-info/METADATA,sha256=fPwXRZgry4efp28Ft0jEWhzxwW8rZx134I01GBFHt0c,28104
23
- ddapm_test_agent-1.33.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
- ddapm_test_agent-1.33.1.dist-info/entry_points.txt,sha256=ulayVs6YJ-0Ej2kxbwn39wOHDVXbyQgFgsbRQmXydcs,250
25
- ddapm_test_agent-1.33.1.dist-info/top_level.txt,sha256=A9jiKOrrg6VjFAk-mtlSVYN4wr0VsZe58ehGR6IW47U,17
26
- ddapm_test_agent-1.33.1.dist-info/RECORD,,
19
+ ddapm_test_agent/vcr_proxy.py,sha256=2OmwCxd9kGBxRGoM7wYQx2H8XiRM3ADsrFlpMsBNfTs,7137
20
+ ddapm_test_agent-1.34.0.dist-info/licenses/LICENSE.BSD3,sha256=J9S_Tq-hhvteDV2W8R0rqht5DZHkmvgdx3gnLZg4j6Q,1493
21
+ ddapm_test_agent-1.34.0.dist-info/licenses/LICENSE.apache2,sha256=5V2RruBHZQIcPyceiv51DjjvdvhgsgS4pnXAOHDuZkQ,11342
22
+ ddapm_test_agent-1.34.0.dist-info/METADATA,sha256=XRVBSQse9hAtcu0cWS8ccFXErpUfXc_B2M9bYPAp5rM,28400
23
+ ddapm_test_agent-1.34.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ ddapm_test_agent-1.34.0.dist-info/entry_points.txt,sha256=ulayVs6YJ-0Ej2kxbwn39wOHDVXbyQgFgsbRQmXydcs,250
25
+ ddapm_test_agent-1.34.0.dist-info/top_level.txt,sha256=A9jiKOrrg6VjFAk-mtlSVYN4wr0VsZe58ehGR6IW47U,17
26
+ ddapm_test_agent-1.34.0.dist-info/RECORD,,