|
23 | 23 | from .env_utils import is_env_enabled |
24 | 24 |
|
25 | 25 | if TYPE_CHECKING: |
26 | | - from ..agents.base_agent import BaseAgent |
| 26 | + from ..agents.base_agent import BaseAgent |
27 | 27 |
|
28 | 28 |
|
29 | 29 | def is_telemetry_enabled(agent: "BaseAgent") -> bool: |
30 | | - """Check if telemetry is enabled for the given agent. |
| 30 | + """Check if telemetry is enabled for the given agent. |
31 | 31 |
|
32 | | - By default telemetry is enabled for an agent unless any of the variables to disable telemetry are set to true. |
| 32 | + By default telemetry is enabled for an agent unless any of the variables to disable telemetry are set to true. |
33 | 33 |
|
34 | | - Args: |
35 | | - agent: The agent to check if telemetry is enabled for. |
| 34 | + Args: |
| 35 | + agent: The agent to check if telemetry is enabled for. |
36 | 36 |
|
37 | | - Returns: |
38 | | - False if any of the environment variables or attributes to disable telemetryare set to True, 'true' or 1, False otherwise. |
| 37 | + Returns: |
| 38 | + False if any of the environment variables or attributes to disable telemetryare set to True, 'true' or 1, False otherwise. |
39 | 39 |
|
40 | | - Examples: |
41 | | - >>> os.environ['OTEL_SDK_DISABLED'] = 'true' |
42 | | - >>> is_telemetry_disabled(my_agent) |
43 | | - False |
| 40 | + Examples: |
| 41 | + >>> os.environ['OTEL_SDK_DISABLED'] = 'true' |
| 42 | + >>> is_telemetry_enabled(my_agent) |
| 43 | + True |
44 | 44 |
|
45 | | - >>> os.environ['ADK_TELEMETRY_DISABLED'] = 1 |
46 | | - >>> is_telemetry_disabled(my_agent) |
47 | | - False |
| 45 | + >>> os.environ['ADK_TELEMETRY_DISABLED'] = 1 |
| 46 | + >>> is_telemetry_enabled(my_agent) |
| 47 | + True |
48 | 48 |
|
49 | | - >>> my_agent.disable_telemetry = True |
50 | | - >>> is_telemetry_disabled(my_agent) |
51 | | - False |
| 49 | + >>> my_agent.disable_telemetry = True |
| 50 | + >>> is_telemetry_enabled(my_agent) |
| 51 | + True |
52 | 52 |
|
53 | | - >>> os.environ['OTEL_SDK_DISABLED'] = 0 |
54 | | - >>> os.environ['ADK_TELEMETRY_DISABLED'] = 'false' |
55 | | - >>> my_agent.disable_telemetry = False |
56 | | - >>> is_telemetry_disabled(my_agent) |
57 | | - True |
58 | | - """ |
59 | | - telemetry_disabled = ( |
60 | | - is_env_enabled("OTEL_SDK_DISABLED") |
61 | | - or is_env_enabled("ADK_TELEMETRY_DISABLED") |
62 | | - or getattr(agent, "disable_telemetry", False) |
63 | | - ) |
64 | | - return not telemetry_disabled |
| 53 | + >>> os.environ['OTEL_SDK_DISABLED'] = 1 |
| 54 | + >>> os.environ['ADK_TELEMETRY_DISABLED'] = 'false' |
| 55 | + >>> my_agent.disable_telemetry = False |
| 56 | + >>> is_telemetry_enabled(my_agent) |
| 57 | + False |
| 58 | + """ |
| 59 | + telemetry_disabled = ( |
| 60 | + is_env_enabled("OTEL_SDK_DISABLED") |
| 61 | + or is_env_enabled("ADK_TELEMETRY_DISABLED") |
| 62 | + or getattr(agent, "disable_telemetry", False) |
| 63 | + ) |
| 64 | + return not telemetry_disabled |
0 commit comments