sf-veritas 0.11.10__cp314-cp314-manylinux_2_28_x86_64.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.
Files changed (141) hide show
  1. sf_veritas/__init__.py +46 -0
  2. sf_veritas/_auto_preload.py +73 -0
  3. sf_veritas/_sfconfig.c +162 -0
  4. sf_veritas/_sfconfig.cpython-314-x86_64-linux-gnu.so +0 -0
  5. sf_veritas/_sfcrashhandler.c +267 -0
  6. sf_veritas/_sfcrashhandler.cpython-314-x86_64-linux-gnu.so +0 -0
  7. sf_veritas/_sffastlog.c +953 -0
  8. sf_veritas/_sffastlog.cpython-314-x86_64-linux-gnu.so +0 -0
  9. sf_veritas/_sffastnet.c +994 -0
  10. sf_veritas/_sffastnet.cpython-314-x86_64-linux-gnu.so +0 -0
  11. sf_veritas/_sffastnetworkrequest.c +727 -0
  12. sf_veritas/_sffastnetworkrequest.cpython-314-x86_64-linux-gnu.so +0 -0
  13. sf_veritas/_sffuncspan.c +2791 -0
  14. sf_veritas/_sffuncspan.cpython-314-x86_64-linux-gnu.so +0 -0
  15. sf_veritas/_sffuncspan_config.c +730 -0
  16. sf_veritas/_sffuncspan_config.cpython-314-x86_64-linux-gnu.so +0 -0
  17. sf_veritas/_sfheadercheck.c +341 -0
  18. sf_veritas/_sfheadercheck.cpython-314-x86_64-linux-gnu.so +0 -0
  19. sf_veritas/_sfnetworkhop.c +1454 -0
  20. sf_veritas/_sfnetworkhop.cpython-314-x86_64-linux-gnu.so +0 -0
  21. sf_veritas/_sfservice.c +1223 -0
  22. sf_veritas/_sfservice.cpython-314-x86_64-linux-gnu.so +0 -0
  23. sf_veritas/_sfteepreload.c +6227 -0
  24. sf_veritas/app_config.py +57 -0
  25. sf_veritas/cli.py +336 -0
  26. sf_veritas/constants.py +10 -0
  27. sf_veritas/custom_excepthook.py +304 -0
  28. sf_veritas/custom_log_handler.py +146 -0
  29. sf_veritas/custom_output_wrapper.py +153 -0
  30. sf_veritas/custom_print.py +153 -0
  31. sf_veritas/django_app.py +5 -0
  32. sf_veritas/env_vars.py +186 -0
  33. sf_veritas/exception_handling_middleware.py +18 -0
  34. sf_veritas/exception_metaclass.py +69 -0
  35. sf_veritas/fast_frame_info.py +116 -0
  36. sf_veritas/fast_network_hop.py +293 -0
  37. sf_veritas/frame_tools.py +112 -0
  38. sf_veritas/funcspan_config_loader.py +693 -0
  39. sf_veritas/function_span_profiler.py +1313 -0
  40. sf_veritas/get_preload_path.py +34 -0
  41. sf_veritas/import_hook.py +62 -0
  42. sf_veritas/infra_details/__init__.py +3 -0
  43. sf_veritas/infra_details/get_infra_details.py +24 -0
  44. sf_veritas/infra_details/kubernetes/__init__.py +3 -0
  45. sf_veritas/infra_details/kubernetes/get_cluster_name.py +147 -0
  46. sf_veritas/infra_details/kubernetes/get_details.py +7 -0
  47. sf_veritas/infra_details/running_on/__init__.py +17 -0
  48. sf_veritas/infra_details/running_on/kubernetes.py +11 -0
  49. sf_veritas/interceptors.py +543 -0
  50. sf_veritas/libsfnettee.so +0 -0
  51. sf_veritas/local_env_detect.py +118 -0
  52. sf_veritas/package_metadata.py +6 -0
  53. sf_veritas/patches/__init__.py +0 -0
  54. sf_veritas/patches/_patch_tracker.py +74 -0
  55. sf_veritas/patches/concurrent_futures.py +19 -0
  56. sf_veritas/patches/constants.py +1 -0
  57. sf_veritas/patches/exceptions.py +82 -0
  58. sf_veritas/patches/multiprocessing.py +32 -0
  59. sf_veritas/patches/network_libraries/__init__.py +99 -0
  60. sf_veritas/patches/network_libraries/aiohttp.py +294 -0
  61. sf_veritas/patches/network_libraries/curl_cffi.py +363 -0
  62. sf_veritas/patches/network_libraries/http_client.py +670 -0
  63. sf_veritas/patches/network_libraries/httpcore.py +580 -0
  64. sf_veritas/patches/network_libraries/httplib2.py +315 -0
  65. sf_veritas/patches/network_libraries/httpx.py +557 -0
  66. sf_veritas/patches/network_libraries/niquests.py +218 -0
  67. sf_veritas/patches/network_libraries/pycurl.py +399 -0
  68. sf_veritas/patches/network_libraries/requests.py +595 -0
  69. sf_veritas/patches/network_libraries/ssl_socket.py +822 -0
  70. sf_veritas/patches/network_libraries/tornado.py +360 -0
  71. sf_veritas/patches/network_libraries/treq.py +270 -0
  72. sf_veritas/patches/network_libraries/urllib_request.py +483 -0
  73. sf_veritas/patches/network_libraries/utils.py +598 -0
  74. sf_veritas/patches/os.py +17 -0
  75. sf_veritas/patches/threading.py +231 -0
  76. sf_veritas/patches/web_frameworks/__init__.py +54 -0
  77. sf_veritas/patches/web_frameworks/aiohttp.py +798 -0
  78. sf_veritas/patches/web_frameworks/async_websocket_consumer.py +337 -0
  79. sf_veritas/patches/web_frameworks/blacksheep.py +532 -0
  80. sf_veritas/patches/web_frameworks/bottle.py +513 -0
  81. sf_veritas/patches/web_frameworks/cherrypy.py +683 -0
  82. sf_veritas/patches/web_frameworks/cors_utils.py +122 -0
  83. sf_veritas/patches/web_frameworks/django.py +963 -0
  84. sf_veritas/patches/web_frameworks/eve.py +401 -0
  85. sf_veritas/patches/web_frameworks/falcon.py +931 -0
  86. sf_veritas/patches/web_frameworks/fastapi.py +738 -0
  87. sf_veritas/patches/web_frameworks/flask.py +526 -0
  88. sf_veritas/patches/web_frameworks/klein.py +501 -0
  89. sf_veritas/patches/web_frameworks/litestar.py +616 -0
  90. sf_veritas/patches/web_frameworks/pyramid.py +440 -0
  91. sf_veritas/patches/web_frameworks/quart.py +841 -0
  92. sf_veritas/patches/web_frameworks/robyn.py +708 -0
  93. sf_veritas/patches/web_frameworks/sanic.py +874 -0
  94. sf_veritas/patches/web_frameworks/starlette.py +742 -0
  95. sf_veritas/patches/web_frameworks/strawberry.py +1446 -0
  96. sf_veritas/patches/web_frameworks/tornado.py +485 -0
  97. sf_veritas/patches/web_frameworks/utils.py +170 -0
  98. sf_veritas/print_override.py +13 -0
  99. sf_veritas/regular_data_transmitter.py +444 -0
  100. sf_veritas/request_interceptor.py +401 -0
  101. sf_veritas/request_utils.py +550 -0
  102. sf_veritas/segfault_handler.py +116 -0
  103. sf_veritas/server_status.py +1 -0
  104. sf_veritas/shutdown_flag.py +11 -0
  105. sf_veritas/subprocess_startup.py +3 -0
  106. sf_veritas/test_cli.py +145 -0
  107. sf_veritas/thread_local.py +1319 -0
  108. sf_veritas/timeutil.py +114 -0
  109. sf_veritas/transmit_exception_to_sailfish.py +28 -0
  110. sf_veritas/transmitter.py +132 -0
  111. sf_veritas/types.py +47 -0
  112. sf_veritas/unified_interceptor.py +1678 -0
  113. sf_veritas/utils.py +39 -0
  114. sf_veritas-0.11.10.dist-info/METADATA +97 -0
  115. sf_veritas-0.11.10.dist-info/RECORD +141 -0
  116. sf_veritas-0.11.10.dist-info/WHEEL +5 -0
  117. sf_veritas-0.11.10.dist-info/entry_points.txt +2 -0
  118. sf_veritas-0.11.10.dist-info/top_level.txt +1 -0
  119. sf_veritas.libs/libbrotlicommon-6ce2a53c.so.1.0.6 +0 -0
  120. sf_veritas.libs/libbrotlidec-811d1be3.so.1.0.6 +0 -0
  121. sf_veritas.libs/libcom_err-730ca923.so.2.1 +0 -0
  122. sf_veritas.libs/libcrypt-52aca757.so.1.1.0 +0 -0
  123. sf_veritas.libs/libcrypto-bdaed0ea.so.1.1.1k +0 -0
  124. sf_veritas.libs/libcurl-eaa3cf66.so.4.5.0 +0 -0
  125. sf_veritas.libs/libgssapi_krb5-323bbd21.so.2.2 +0 -0
  126. sf_veritas.libs/libidn2-2f4a5893.so.0.3.6 +0 -0
  127. sf_veritas.libs/libk5crypto-9a74ff38.so.3.1 +0 -0
  128. sf_veritas.libs/libkeyutils-2777d33d.so.1.6 +0 -0
  129. sf_veritas.libs/libkrb5-a55300e8.so.3.3 +0 -0
  130. sf_veritas.libs/libkrb5support-e6594cfc.so.0.1 +0 -0
  131. sf_veritas.libs/liblber-2-d20824ef.4.so.2.10.9 +0 -0
  132. sf_veritas.libs/libldap-2-cea2a960.4.so.2.10.9 +0 -0
  133. sf_veritas.libs/libnghttp2-39367a22.so.14.17.0 +0 -0
  134. sf_veritas.libs/libpcre2-8-516f4c9d.so.0.7.1 +0 -0
  135. sf_veritas.libs/libpsl-99becdd3.so.5.3.1 +0 -0
  136. sf_veritas.libs/libsasl2-7de4d792.so.3.0.0 +0 -0
  137. sf_veritas.libs/libselinux-d0805dcb.so.1 +0 -0
  138. sf_veritas.libs/libssh-c11d285b.so.4.8.7 +0 -0
  139. sf_veritas.libs/libssl-60250281.so.1.1.1k +0 -0
  140. sf_veritas.libs/libunistring-05abdd40.so.2.1.0 +0 -0
  141. sf_veritas.libs/libuuid-95b83d40.so.1.3.0 +0 -0
@@ -0,0 +1,57 @@
1
+ import os
2
+ import uuid
3
+ from typing import Dict, List, Optional, Union
4
+
5
+ from .constants import SAILFISH_DEFAULT_GRAPHQL_ENDPOINT
6
+ from .infra_details import get_infra_details
7
+
8
+ # CRITICAL: Read from environment first to ensure C library and Python use the same UUID
9
+ # The C library (_sfteepreload.so) generates a UUID during sender thread init if not set
10
+ # It also exports it to SFT_SERVICE_UUID so Python can read it
11
+ # If C library isn't active (no LD_PRELOAD), Python generates its own UUID
12
+ _service_uuid = os.getenv('SFT_SERVICE_UUID')
13
+ if not _service_uuid:
14
+ _service_uuid = str(uuid.uuid4())
15
+ os.environ['SFT_SERVICE_UUID'] = _service_uuid # Set for consistency
16
+ _service_identifier = None
17
+ _service_version = None
18
+ _service_display_name = None
19
+ _git_sha = None
20
+ _service_identification_received = False
21
+ _service_additional_metadata: Optional[Dict[str, Union[str, int, float, None]]] = None
22
+
23
+ _setup_interceptors_call_filename = None
24
+ _setup_interceptors_call_lineno = None
25
+
26
+ _interceptors_initialized = False
27
+
28
+ _profiling_mode_enabled: bool = False
29
+ _profiling_max_depth: int = 5
30
+
31
+ _site_and_dist_packages_to_collect_local_variables_on: Optional[List[str]] = []
32
+
33
+ _sailfish_api_key = None
34
+ _sailfish_graphql_endpoint: str = os.getenv(
35
+ "SAILFISH_GRAPHQL_ENDPOINT", SAILFISH_DEFAULT_GRAPHQL_ENDPOINT
36
+ )
37
+
38
+ _infra_details = get_infra_details()
39
+
40
+
41
+ def _set_site_and_dist_packages_to_collect_local_variables_on(
42
+ site_and_dist_packages_to_collect_local_variables_on: Optional[List[str]] = None,
43
+ ):
44
+ if site_and_dist_packages_to_collect_local_variables_on is None:
45
+ _site_and_dist_packages_to_collect_local_variables_on = []
46
+ site_and_dist_packages_to_collect_local_variables_on_final: List[str] = (
47
+ site_and_dist_packages_to_collect_local_variables_on.copy()
48
+ )
49
+ for package in site_and_dist_packages_to_collect_local_variables_on:
50
+ if "-" not in package:
51
+ continue
52
+ site_and_dist_packages_to_collect_local_variables_on_final.append(
53
+ package.replace("-", "_")
54
+ )
55
+ _site_and_dist_packages_to_collect_local_variables_on = (
56
+ site_and_dist_packages_to_collect_local_variables_on_final
57
+ )
sf_veritas/cli.py ADDED
@@ -0,0 +1,336 @@
1
+ import os
2
+ import subprocess
3
+ import sys
4
+ import tempfile
5
+ from typing import Dict, List, Optional, Union
6
+
7
+ from fire import Fire
8
+
9
+ from .env_vars import SF_DEBUG
10
+ from .unified_interceptor import setup_interceptors
11
+
12
+ METHOD = "os.execvp"
13
+
14
+
15
+ def inject_code(file_path, **kwargs):
16
+ """
17
+ Injects the given code snippet at the top of the target Python file.
18
+ """
19
+ code_to_inject = f"""
20
+ from sf_veritas import setup_interceptors
21
+
22
+ setup_interceptors(
23
+ api_key={kwargs.get('api_key')!r},
24
+ service_identifier={kwargs.get('service_identifier', None)!r},
25
+ service_version={kwargs.get('service_version', None)!r},
26
+ service_additional_metadata={kwargs.get('service_additional_metadata', None)!r},
27
+ profiling_mode_enabled={kwargs.get('profiling_mode_enabled', False)},
28
+ profiling_max_depth={kwargs.get('profiling_max_depth', 5)},
29
+ domains_to_not_propagate_headers_to={kwargs.get('domains_to_not_propagate_headers_to', None)!r},
30
+ site_and_dist_packages_to_collect_local_variables_on={kwargs.get('site_and_dist_packages_to_collect_local_variables_on', None)!r}
31
+ )
32
+ """
33
+
34
+ # Read the original file content
35
+ with open(file_path, "r") as f:
36
+ original_content = f.read()
37
+
38
+ # Combine the injected code with the original content
39
+ new_content = code_to_inject + "\n" + original_content
40
+
41
+ # Create a temporary file in the same directory as the original script
42
+ temp_dir = os.path.dirname(file_path)
43
+ temp_file = tempfile.NamedTemporaryFile(
44
+ delete=False, dir=temp_dir, prefix="temp-", suffix=".py"
45
+ )
46
+
47
+ # Write the new content to the temporary file
48
+ with open(temp_file.name, "w") as f:
49
+ f.write(new_content)
50
+
51
+ return temp_file.name
52
+
53
+
54
+ def get_sf_veritas_index(argv=sys.argv):
55
+ for i, arg in enumerate(argv):
56
+ if "sf-veritas" in arg:
57
+ return i
58
+ return None
59
+
60
+
61
+ def get_python_index(argv=sys.argv):
62
+ if "python" in argv:
63
+ return argv.index("python")
64
+ if "python3" in argv:
65
+ return argv.index("python3")
66
+ return None
67
+
68
+
69
+ def get_command_index(command_name, argv=sys.argv):
70
+ """
71
+ Returns the index of a given command in sys.argv or None if not found.
72
+ """
73
+ if command_name in argv:
74
+ return argv.index(command_name)
75
+ return None
76
+
77
+
78
+ def handle_framework_command(
79
+ command_index,
80
+ module_delimiter=":",
81
+ argv=sys.argv,
82
+ app_path_offset: int = 1,
83
+ **kwargs,
84
+ ):
85
+ """
86
+ Handles framework commands like uvicorn, gunicorn, sanic, waitress-serve, daphne, etc.
87
+ """
88
+ app_path = argv[command_index + app_path_offset]
89
+ module_path = app_path.split(module_delimiter)[0].replace(".", "/") + ".py"
90
+
91
+ # Inject code into the module
92
+ modified_module_path = inject_code(module_path, **kwargs)
93
+
94
+ # Turn the modified file path into a dotted module path
95
+ modified_module_relpath = os.path.relpath(modified_module_path, start=os.getcwd())
96
+ new_module_path = os.path.splitext(modified_module_relpath)[0].replace("/", ".")
97
+
98
+ # Strip off any leading dots that appear because of ../ or ./ references
99
+ new_module_path = new_module_path.lstrip(".")
100
+
101
+ # If there's still nothing, you could do a sanity check here:
102
+ # if not new_module_path:
103
+ # raise ValueError("Unable to determine a valid module name from path")
104
+
105
+ # Reconstruct the final "module:app" string
106
+ if module_delimiter in app_path:
107
+ # e.g., "backend.temp-abcdef:application"
108
+ modified_app_path = (
109
+ new_module_path + module_delimiter + app_path.split(module_delimiter)[1]
110
+ )
111
+ else:
112
+ modified_app_path = new_module_path
113
+
114
+ # Build the run_command
115
+ run_command = [argv[command_index], *argv[command_index + 1 :]]
116
+ run_command[app_path_offset] = modified_app_path
117
+
118
+ return run_command
119
+
120
+
121
+ def find_application_arg(command_index, argv=sys.argv):
122
+ """
123
+ Finds the application argument for daphne and granian commands, ignoring any flags.
124
+ """
125
+ if SF_DEBUG:
126
+ print(
127
+ f"Checking arguments after index {command_index}: {argv[command_index + 1:]}",
128
+ log=False,
129
+ )
130
+ should_skip = False
131
+ for i in range(command_index + 1, len(argv)):
132
+ if should_skip:
133
+ should_skip = False
134
+ continue
135
+ if argv[i].startswith("-"):
136
+ should_skip = True
137
+ continue
138
+ return argv[i]
139
+ return None
140
+
141
+
142
+ def main(
143
+ api_key: str,
144
+ service_identifier: str = None,
145
+ service_version: Union[str, int] = None, # Allow both string and int
146
+ service_additional_metadata: Dict[str, Union[str, int, float, None]] = None,
147
+ profiling_mode_enabled: bool = False,
148
+ profiling_max_depth: int = 5,
149
+ domains_to_not_propagate_headers_to: Optional[List[str]] = None,
150
+ site_and_dist_packages_to_collect_local_variables_on: Optional[List[str]] = None,
151
+ *args,
152
+ ):
153
+ """
154
+ Main function to handle CLI and set up interceptors.
155
+
156
+ Args:
157
+ api_key: (Required) API key for authentication. This must be provided as a CLI argument.
158
+ service_identifier: Identifier for the service.
159
+ service_version: Version of the service.
160
+ service_additional_metadata: Additional metadata to associate with the service.
161
+ profiling_mode_enabled: Whether profiling mode is enabled.
162
+ profiling_max_depth: Maximum depth for profiling.
163
+ domains_to_not_propagate_headers_to: Domains to which headers should not be propagated.
164
+ site_and_dist_packages_to_collect_local_variables_on: If set to None, defaults to [], excluding all installed packages.
165
+ *args: Additional command-line arguments to be passed through.
166
+ """
167
+
168
+ # Convert service_version to string if it's numeric
169
+ if service_version is not None:
170
+ service_version = str(service_version)
171
+
172
+ # Collect setup parameters
173
+ setup_params = {
174
+ "api_key": api_key,
175
+ "service_identifier": service_identifier,
176
+ "service_version": service_version,
177
+ "service_additional_metadata": service_additional_metadata,
178
+ "profiling_mode_enabled": profiling_mode_enabled,
179
+ "profiling_max_depth": profiling_max_depth,
180
+ "domains_to_not_propagate_headers_to": domains_to_not_propagate_headers_to,
181
+ "site_and_dist_packages_to_collect_local_variables_on": site_and_dist_packages_to_collect_local_variables_on,
182
+ }
183
+
184
+ # Remaining arguments are captured in *args
185
+ remaining_args = sys.argv[1:]
186
+ try:
187
+ separator_index = sys.argv.index("--")
188
+ remaining_args = sys.argv[separator_index + 1 :]
189
+ except ValueError:
190
+ pass
191
+
192
+ if SF_DEBUG:
193
+ print("[[ DEBUG ]] sys.argv [[ /DEBUG ]]", sys.argv)
194
+ print("[[ DEBUG ]] setup_params [[ /DEBUG ]]", setup_params)
195
+ print("[[ DEBUG ]] remaining_args [[ /DEBUG ]]", remaining_args)
196
+
197
+ setup_interceptors(**setup_params)
198
+
199
+ if not remaining_args:
200
+ print("Usage: sf-veritas [options] <command> [args]")
201
+ sys.exit(1)
202
+
203
+ # Detect CLI command and adjust injection based on the framework
204
+ python_index = get_python_index(remaining_args)
205
+ uvicorn_index = get_command_index("uvicorn", remaining_args)
206
+ gunicorn_index = get_command_index("gunicorn", remaining_args)
207
+ flask_index = get_command_index("flask", remaining_args)
208
+ django_admin_index = get_command_index("django-admin", remaining_args)
209
+ sanic_index = get_command_index("sanic", remaining_args)
210
+ pserve_index = get_command_index("pserve", remaining_args)
211
+ waitress_index = get_command_index("waitress-serve", remaining_args)
212
+ daphne_index = get_command_index("daphne", remaining_args)
213
+ granian_index = get_command_index("granian", remaining_args)
214
+
215
+ if python_index is not None and python_index >= 0:
216
+ if "-m" in remaining_args:
217
+ module_index = remaining_args.index("-m", python_index)
218
+
219
+ # Ensure there's a module specified after `-m`
220
+ if module_index + 1 < len(remaining_args):
221
+ module_dot_path = remaining_args[module_index + 1]
222
+ module_path = module_dot_path.replace(".", "/") + ".py"
223
+
224
+ # Inject code into the module, passing setup_params
225
+ modified_module_path = inject_code(module_path, **setup_params)
226
+
227
+ # Calculate the relative path for the new temporary file's dot-path
228
+ new_module_dot_path = os.path.splitext(
229
+ os.path.relpath(modified_module_path, start=os.getcwd())
230
+ )[0].replace("/", ".")
231
+
232
+ # Rebuild the command with the modified module dot-path
233
+ code_after_module_index = module_index + 2
234
+ run_command = [
235
+ sys.executable,
236
+ "-m",
237
+ new_module_dot_path,
238
+ ] + remaining_args[code_after_module_index:]
239
+ else:
240
+ print("Error: No module specified after '-m'.")
241
+ sys.exit(1)
242
+ else:
243
+ script_path = remaining_args[python_index + 1]
244
+
245
+ # Inject code into the script file directly, passing setup_params
246
+ modified_script_path = inject_code(script_path, **setup_params)
247
+
248
+ # Rebuild the command to use the path to the modified script file
249
+ run_command = [sys.executable, modified_script_path] + remaining_args[
250
+ python_index + 2 :
251
+ ]
252
+ elif uvicorn_index is not None:
253
+ run_command = handle_framework_command(
254
+ uvicorn_index, module_delimiter=".", argv=remaining_args, **setup_params
255
+ )
256
+ elif gunicorn_index is not None:
257
+ run_command = handle_framework_command(
258
+ gunicorn_index, argv=remaining_args, **setup_params
259
+ )
260
+ elif sanic_index is not None:
261
+ run_command = handle_framework_command(
262
+ sanic_index, module_delimiter=".", argv=remaining_args, **setup_params
263
+ )
264
+ elif waitress_index is not None:
265
+ run_command = handle_framework_command(
266
+ waitress_index, module_delimiter=":", argv=remaining_args, **setup_params
267
+ )
268
+ elif flask_index is not None:
269
+ # Flask expects the FLASK_APP environment variable
270
+ app_path = os.environ.get("FLASK_APP", None)
271
+ if app_path:
272
+ module_path = app_path.replace(".", "/") + ".py"
273
+
274
+ # Inject code into the module, passing setup_params
275
+ modified_module_path = inject_code(module_path, **setup_params)
276
+
277
+ # Set the modified path back to FLASK_APP
278
+ os.environ["FLASK_APP"] = modified_module_path.replace("/", ".").replace(
279
+ ".py", ""
280
+ )
281
+
282
+ run_command = remaining_args
283
+ elif django_admin_index is not None:
284
+ # Handle django-admin commands
285
+ script_path = remaining_args[django_admin_index]
286
+
287
+ # Inject code into the script file directly, passing setup_params
288
+ modified_script_path = inject_code(script_path, **setup_params)
289
+
290
+ # Rebuild the command to use the path to the modified script file
291
+ run_command = (
292
+ remaining_args[:django_admin_index]
293
+ + [modified_script_path]
294
+ + remaining_args[django_admin_index + 1 :]
295
+ )
296
+ elif daphne_index is not None or granian_index is not None:
297
+ command_index = daphne_index if daphne_index is not None else granian_index
298
+ app_arg = find_application_arg(command_index, argv=remaining_args)
299
+ app_path_offset = remaining_args.index(app_arg)
300
+
301
+ if not app_arg:
302
+ print("Error: No application module specified for daphne or granian.")
303
+ sys.exit(1)
304
+
305
+ run_command = handle_framework_command(
306
+ command_index,
307
+ module_delimiter=":",
308
+ argv=remaining_args,
309
+ app_path_offset=app_path_offset,
310
+ **setup_params,
311
+ )
312
+ elif pserve_index is not None:
313
+ # Rebuild the command to use pserve
314
+ run_command = remaining_args
315
+ else:
316
+ # For all other cases, pass the command as-is
317
+ run_command = remaining_args
318
+
319
+ if SF_DEBUG:
320
+ print("Run command is now:", run_command, log=False)
321
+
322
+ env = os.environ.copy()
323
+
324
+ if METHOD == "subprocess.run":
325
+ result = subprocess.run(run_command, env=env)
326
+ sys.exit(result.returncode)
327
+ else:
328
+ os.execvpe(run_command[0], run_command, env)
329
+
330
+
331
+ def fire_main():
332
+ return Fire(main)
333
+
334
+
335
+ if __name__ == "__main__":
336
+ fire_main()
@@ -0,0 +1,10 @@
1
+ NONSESSION_APPLOGS = "nonsession-applogs"
2
+ SAILFISH_DEFAULT_GRAPHQL_ENDPOINT = "https://api-service.sailfishqa.com/graphql/"
3
+ SAILFISH_TRACING_HEADER = "X-Sf3-Rid"
4
+ FUNCSPAN_OVERRIDE_HEADER = "X-Sf3-FunctionSpanCaptureOverride"
5
+ PARENT_SESSION_ID_HEADER = "X-Sf4-Prid" # Parent Recording ID (propagates to external services)
6
+
7
+ # Byte-string constants for fast header matching (avoid decode/dict overhead)
8
+ SAILFISH_TRACING_HEADER_BYTES = SAILFISH_TRACING_HEADER.encode("ascii").lower() # b"x-sf3-rid"
9
+ FUNCSPAN_OVERRIDE_HEADER_BYTES = FUNCSPAN_OVERRIDE_HEADER.encode("ascii").lower() # b"x-sf3-functionspancaptureoverride"
10
+ PARENT_SESSION_ID_HEADER_BYTES = PARENT_SESSION_ID_HEADER.encode("ascii").lower() # b"x-sf4-prid"