|
8 | 8 | import platform
|
9 | 9 | import sys
|
10 | 10 | import warnings
|
11 |
| -import webbrowser |
12 | 11 | from collections.abc import Sequence
|
13 | 12 | from operator import itemgetter
|
14 | 13 | from pathlib import Path
|
15 | 14 | from typing import Any
|
16 |
| -from urllib.parse import urlparse |
17 | 15 |
|
18 | 16 | import requests
|
19 | 17 | from opentelemetry import trace
|
20 | 18 | from rich.console import Console
|
21 | 19 |
|
22 |
| -from logfire._internal.cli.prompt import parse_prompt |
23 | 20 | from logfire.exceptions import LogfireConfigError
|
24 | 21 | from logfire.propagate import ContextCarrier, get_context
|
25 | 22 |
|
26 | 23 | from ...version import VERSION
|
27 |
| -from ..auth import DEFAULT_FILE, HOME_LOGFIRE, UserTokenCollection, poll_for_token, request_device_code |
| 24 | +from ..auth import HOME_LOGFIRE |
28 | 25 | from ..client import LogfireClient
|
29 | 26 | from ..config import REGIONS, LogfireCredentials, get_base_url_from_token
|
30 | 27 | from ..config_params import ParamManager
|
31 | 28 | from ..tracer import SDKTracerProvider
|
| 29 | +from .auth import parse_auth |
| 30 | +from .prompt import parse_prompt |
32 | 31 | from .run import collect_instrumentation_context, parse_run, print_otel_summary
|
33 | 32 |
|
34 | 33 | BASE_OTEL_INTEGRATION_URL = 'https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/'
|
@@ -117,68 +116,6 @@ def parse_inspect(args: argparse.Namespace) -> None:
|
117 | 116 | console.print('No recommended packages found. You are all set!', style='green') # pragma: no cover
|
118 | 117 |
|
119 | 118 |
|
120 |
| -def parse_auth(args: argparse.Namespace) -> None: |
121 |
| - """Authenticate with Logfire. |
122 |
| -
|
123 |
| - This will authenticate your machine with Logfire and store the credentials. |
124 |
| - """ |
125 |
| - logfire_url: str | None = args.logfire_url |
126 |
| - |
127 |
| - tokens_collection = UserTokenCollection() |
128 |
| - logged_in = tokens_collection.is_logged_in(logfire_url) |
129 |
| - |
130 |
| - if logged_in: |
131 |
| - sys.stderr.writelines( |
132 |
| - ( |
133 |
| - f'You are already logged in. (Your credentials are stored in {DEFAULT_FILE})\n', |
134 |
| - 'If you would like to log in using a different account, use the --region argument:\n', |
135 |
| - 'logfire --region <region> auth\n', |
136 |
| - ) |
137 |
| - ) |
138 |
| - return |
139 |
| - |
140 |
| - sys.stderr.writelines( |
141 |
| - ( |
142 |
| - '\n', |
143 |
| - 'Welcome to Logfire! 🔥\n', |
144 |
| - 'Before you can send data to Logfire, we need to authenticate you.\n', |
145 |
| - '\n', |
146 |
| - ) |
147 |
| - ) |
148 |
| - if not logfire_url: |
149 |
| - selected_region = -1 |
150 |
| - while not (1 <= selected_region <= len(REGIONS)): |
151 |
| - sys.stderr.write('Logfire is available in multiple data regions. Please select one:\n') |
152 |
| - for i, (region_id, region_data) in enumerate(REGIONS.items(), start=1): |
153 |
| - sys.stderr.write(f'{i}. {region_id.upper()} (GCP region: {region_data["gcp_region"]})\n') |
154 |
| - |
155 |
| - try: |
156 |
| - selected_region = int( |
157 |
| - input(f'Selected region [{"/".join(str(i) for i in range(1, len(REGIONS) + 1))}]: ') |
158 |
| - ) |
159 |
| - except ValueError: |
160 |
| - selected_region = -1 |
161 |
| - logfire_url = list(REGIONS.values())[selected_region - 1]['base_url'] |
162 |
| - |
163 |
| - device_code, frontend_auth_url = request_device_code(args._session, logfire_url) |
164 |
| - frontend_host = urlparse(frontend_auth_url).netloc |
165 |
| - input(f'Press Enter to open {frontend_host} in your browser...') |
166 |
| - try: |
167 |
| - webbrowser.open(frontend_auth_url, new=2) |
168 |
| - except webbrowser.Error: |
169 |
| - pass |
170 |
| - sys.stderr.writelines( |
171 |
| - ( |
172 |
| - f"Please open {frontend_auth_url} in your browser to authenticate if it hasn't already.\n", |
173 |
| - 'Waiting for you to authenticate with Logfire...\n', |
174 |
| - ) |
175 |
| - ) |
176 |
| - |
177 |
| - tokens_collection.add_token(logfire_url, poll_for_token(args._session, device_code, logfire_url)) |
178 |
| - sys.stderr.write('Successfully authenticated!\n') |
179 |
| - sys.stderr.write(f'\nYour Logfire credentials are stored in {DEFAULT_FILE}\n') |
180 |
| - |
181 |
| - |
182 | 119 | def parse_list_projects(args: argparse.Namespace) -> None:
|
183 | 120 | """List user projects."""
|
184 | 121 | client = LogfireClient.from_url(args.logfire_url)
|
|
0 commit comments