|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import itertools |
2 | 4 | import math |
3 | 5 | import os |
4 | 6 | import typing as t |
5 | 7 |
|
| 8 | +from envier import Env |
| 9 | + |
6 | 10 | from ddtrace.ext.git import COMMIT_SHA |
7 | 11 | from ddtrace.ext.git import MAIN_PACKAGE |
8 | 12 | from ddtrace.ext.git import REPOSITORY_URL |
|
19 | 23 | logger = get_logger(__name__) |
20 | 24 |
|
21 | 25 |
|
22 | | -def _derive_default_heap_sample_size(heap_config, default_heap_sample_size=1024 * 1024): |
23 | | - # type: (ProfilingConfigHeap, int) -> int |
| 26 | +def _derive_default_heap_sample_size( |
| 27 | + heap_config: Env, |
| 28 | + default_heap_sample_size: int = 1024 * 1024, |
| 29 | +) -> int: |
| 30 | + assert isinstance(heap_config, ProfilingConfigHeap) # nosec: assert is used for type checking |
24 | 31 | heap_sample_size = heap_config._sample_size |
25 | 32 | if heap_sample_size is not None: |
26 | | - return heap_sample_size |
| 33 | + return t.cast(int, heap_sample_size) |
27 | 34 |
|
28 | 35 | if not heap_config.enabled: |
29 | 36 | return 0 |
@@ -363,28 +370,28 @@ class ProfilingConfigPytorch(DDConfig): |
363 | 370 | logger.warning("Failed to load ddup module (%s), disabling profiling", msg) |
364 | 371 | telemetry_writer.add_log( |
365 | 372 | TELEMETRY_LOG_LEVEL.ERROR, |
366 | | - "Failed to load ddup module (%s), disabling profiling" % ddup_failure_msg, |
| 373 | + f"Failed to load ddup module ({ddup_failure_msg}), disabling profiling", |
367 | 374 | ) |
368 | | - config.enabled = False |
| 375 | + config.enabled = False # pyright: ignore[reportAttributeAccessIssue] |
369 | 376 |
|
370 | 377 | # We also need to check if stack_v2 module is available, and turn if off |
371 | 378 | # if it s not. |
372 | 379 | stack_v2_failure_msg, stack_v2_is_available = _check_for_stack_v2_available() |
373 | | -if config.stack.enabled and not stack_v2_is_available: |
| 380 | +if config.stack.enabled and not stack_v2_is_available: # pyright: ignore[reportAttributeAccessIssue] |
374 | 381 | msg = stack_v2_failure_msg or "stack_v2 not available" |
375 | 382 | logger.warning("Failed to load stack_v2 module (%s), falling back to v1 stack sampler", msg) |
376 | 383 | telemetry_writer.add_log( |
377 | 384 | TELEMETRY_LOG_LEVEL.ERROR, |
378 | 385 | "Failed to load stack_v2 module (%s), disabling profiling" % msg, |
379 | 386 | ) |
380 | | - config.stack.enabled = False |
| 387 | + config.stack.enabled = False # pyright: ignore[reportAttributeAccessIssue] |
381 | 388 |
|
382 | 389 | # Enrich tags with git metadata and DD_TAGS |
383 | | -config.tags = _enrich_tags(config.tags) |
| 390 | +config.tags = _enrich_tags(config.tags) # pyright: ignore[reportAttributeAccessIssue] |
384 | 391 |
|
385 | 392 |
|
386 | | -def config_str(config): |
387 | | - configured_features = [] |
| 393 | +def config_str(config) -> str: |
| 394 | + configured_features: list[str] = [] |
388 | 395 | if config.stack.enabled: |
389 | 396 | configured_features.append("stack_v2") |
390 | 397 | if config.lock.enabled: |
|
0 commit comments