Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove show_summary and fast_shutdown from logfire.configure() #431

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions logfire/_internal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class ConsoleOptions:
min_log_level: LevelName = 'info'
"""The minimum log level to show in the console."""

show_project_link: bool = True
"""Whether to print the URL of the Logfire project after initialization."""


@dataclass
class PydanticPlugin:
Expand Down Expand Up @@ -157,7 +160,6 @@ def configure( # noqa: D417
service_name: str | None = None,
service_version: str | None = None,
console: ConsoleOptions | Literal[False] | None = None,
show_summary: bool | None = None,
config_dir: Path | str | None = None,
data_dir: Path | str | None = None,
base_url: str | None = None,
Expand All @@ -166,7 +168,6 @@ def configure( # noqa: D417
additional_span_processors: Sequence[SpanProcessor] | None = None,
additional_metric_readers: Sequence[MetricReader] | None = None,
pydantic_plugin: PydanticPlugin | None = None,
fast_shutdown: bool = False,
scrubbing: ScrubbingOptions | Literal[False] | None = None,
inspect_arguments: bool | None = None,
sampling: SamplingOptions | None = None,
Expand All @@ -185,8 +186,6 @@ def configure( # noqa: D417
console: Whether to control terminal output. If `None` uses the `LOGFIRE_CONSOLE_*` environment variables,
otherwise defaults to `ConsoleOption(colors='auto', indent_spans=True, include_timestamps=True, verbose=False)`.
If `False` disables console output. It can also be disabled by setting `LOGFIRE_CONSOLE` environment variable to `false`.
show_summary: When to print a summary of the Logfire setup including a link to the dashboard. If `None` uses the `LOGFIRE_SHOW_SUMMARY` environment variable, otherwise
defaults to `True`.
config_dir: Directory that contains the `pyproject.toml` file for this project. If `None` uses the
`LOGFIRE_CONFIG_DIR` environment variable, otherwise defaults to the current working directory.
data_dir: Directory to store credentials, and logs. If `None` uses the `LOGFIRE_CREDENTIALS_DIR` environment variable, otherwise defaults to `'.logfire'`.
Expand All @@ -199,7 +198,6 @@ def configure( # noqa: D417
which exports metrics to Logfire's API.
pydantic_plugin: Configuration for the Pydantic plugin. If `None` uses the `LOGFIRE_PYDANTIC_PLUGIN_*` environment
variables, otherwise defaults to `PydanticPlugin(record='off')`.
fast_shutdown: Whether to shut down exporters and providers quickly, mostly used for tests. Defaults to `False`.
scrubbing: Options for scrubbing sensitive data. Set to `False` to disable.
inspect_arguments: Whether to enable
[f-string magic](https://logfire.pydantic.dev/docs/guides/onboarding_checklist/add_manual_tracing/#f-strings).
Expand Down Expand Up @@ -270,6 +268,14 @@ def configure( # noqa: D417
'Use `sampling=logfire.SamplingOptions(head=...)` instead.',
)

show_summary = deprecated_kwargs.pop('show_summary', None) # type: ignore
if show_summary is not None: # pragma: no cover
warnings.warn(
'The `show_summary` argument is deprecated. '
'Use `console=False` or `console=logfire.ConsoleOptions(show_project_link=False)` instead.',
DeprecationWarning,
)

if deprecated_kwargs:
raise TypeError(f'configure() got unexpected keyword arguments: {", ".join(deprecated_kwargs)}')

Expand All @@ -280,15 +286,13 @@ def configure( # noqa: D417
service_name=service_name,
service_version=service_version,
console=console,
show_summary=show_summary,
config_dir=Path(config_dir) if config_dir else None,
data_dir=Path(data_dir) if data_dir else None,
id_generator=id_generator,
ns_timestamp_generator=ns_timestamp_generator,
additional_span_processors=additional_span_processors,
additional_metric_readers=additional_metric_readers,
pydantic_plugin=pydantic_plugin,
fast_shutdown=fast_shutdown,
scrubbing=scrubbing,
inspect_arguments=inspect_arguments,
sampling=sampling,
Expand Down Expand Up @@ -332,9 +336,6 @@ class _LogfireConfigData:
console: ConsoleOptions | Literal[False] | None
"""Options for controlling console output"""

show_summary: bool
"""Whether to show the summary when starting a new project"""

data_dir: Path
"""The directory to store Logfire data in"""

Expand All @@ -350,9 +351,6 @@ class _LogfireConfigData:
pydantic_plugin: PydanticPlugin
"""Options for the Pydantic plugin"""

fast_shutdown: bool
"""Whether to shut down exporters and providers quickly, mostly used for tests"""

scrubbing: ScrubbingOptions | Literal[False]
"""Options for redacting sensitive data, or False to disable."""

Expand All @@ -373,15 +371,13 @@ def _load_configuration(
service_name: str | None,
service_version: str | None,
console: ConsoleOptions | Literal[False] | None,
show_summary: bool | None,
config_dir: Path | None,
data_dir: Path | None,
id_generator: IdGenerator | None,
ns_timestamp_generator: Callable[[], int] | None,
additional_span_processors: Sequence[SpanProcessor] | None,
additional_metric_readers: Sequence[MetricReader] | None,
pydantic_plugin: PydanticPlugin | None,
fast_shutdown: bool,
scrubbing: ScrubbingOptions | Literal[False] | None,
inspect_arguments: bool | None,
sampling: SamplingOptions | None,
Expand All @@ -394,7 +390,6 @@ def _load_configuration(
self.token = param_manager.load_param('token', token)
self.service_name = param_manager.load_param('service_name', service_name)
self.service_version = param_manager.load_param('service_version', service_version)
self.show_summary = param_manager.load_param('show_summary', show_summary)
self.data_dir = param_manager.load_param('data_dir', data_dir)
self.inspect_arguments = param_manager.load_param('inspect_arguments', inspect_arguments)
self.ignore_no_config = param_manager.load_param('ignore_no_config')
Expand Down Expand Up @@ -428,6 +423,7 @@ def _load_configuration(
include_timestamps=param_manager.load_param('console_include_timestamp'),
verbose=param_manager.load_param('console_verbose'),
min_log_level=param_manager.load_param('console_min_log_level'),
show_project_link=param_manager.load_param('console_show_project_link'),
)

if isinstance(pydantic_plugin, dict):
Expand All @@ -449,8 +445,6 @@ def _load_configuration(
)
self.sampling = sampling

self.fast_shutdown = fast_shutdown

self.id_generator = id_generator or RandomIdGenerator()
self.ns_timestamp_generator = ns_timestamp_generator or time.time_ns
self.additional_span_processors = additional_span_processors
Expand All @@ -473,15 +467,13 @@ def __init__(
service_name: str | None = None,
service_version: str | None = None,
console: ConsoleOptions | Literal[False] | None = None,
show_summary: bool | None = None,
config_dir: Path | None = None,
data_dir: Path | None = None,
id_generator: IdGenerator | None = None,
ns_timestamp_generator: Callable[[], int] | None = None,
additional_span_processors: Sequence[SpanProcessor] | None = None,
additional_metric_readers: Sequence[MetricReader] | None = None,
pydantic_plugin: PydanticPlugin | None = None,
fast_shutdown: bool = False,
scrubbing: ScrubbingOptions | Literal[False] | None = None,
inspect_arguments: bool | None = None,
sampling: SamplingOptions | None = None,
Expand All @@ -501,15 +493,13 @@ def __init__(
service_name=service_name,
service_version=service_version,
console=console,
show_summary=show_summary,
config_dir=config_dir,
data_dir=data_dir,
id_generator=id_generator,
ns_timestamp_generator=ns_timestamp_generator,
additional_span_processors=additional_span_processors,
additional_metric_readers=additional_metric_readers,
pydantic_plugin=pydantic_plugin,
fast_shutdown=fast_shutdown,
scrubbing=scrubbing,
inspect_arguments=inspect_arguments,
sampling=sampling,
Expand All @@ -533,15 +523,13 @@ def configure(
service_name: str | None,
service_version: str | None,
console: ConsoleOptions | Literal[False] | None,
show_summary: bool | None,
config_dir: Path | None,
data_dir: Path | None,
id_generator: IdGenerator | None,
ns_timestamp_generator: Callable[[], int] | None,
additional_span_processors: Sequence[SpanProcessor] | None,
additional_metric_readers: Sequence[MetricReader] | None,
pydantic_plugin: PydanticPlugin | None,
fast_shutdown: bool,
scrubbing: ScrubbingOptions | Literal[False] | None,
inspect_arguments: bool | None,
sampling: SamplingOptions | None,
Expand All @@ -555,15 +543,13 @@ def configure(
service_name,
service_version,
console,
show_summary,
config_dir,
data_dir,
id_generator,
ns_timestamp_generator,
additional_span_processors,
additional_metric_readers,
pydantic_plugin,
fast_shutdown,
scrubbing,
inspect_arguments,
sampling,
Expand Down Expand Up @@ -667,6 +653,8 @@ def add_span_processor(span_processor: SpanProcessor) -> None:
metric_readers = list(self.additional_metric_readers or [])

if (self.send_to_logfire == 'if-token-present' and self.token is not None) or self.send_to_logfire is True:
show_project_link = self.console and self.console.show_project_link

if self.token is None:
if (credentials := LogfireCredentials.load_creds_file(self.data_dir)) is None: # pragma: no branch
credentials = LogfireCredentials.initialize_project(
Expand All @@ -676,14 +664,14 @@ def add_span_processor(span_processor: SpanProcessor) -> None:
credentials.write_creds_file(self.data_dir)
self.token = credentials.token
self.base_url = self.base_url or credentials.logfire_api_url
if self.show_summary: # pragma: no branch
if show_project_link: # pragma: no branch
credentials.print_token_summary()
else:

def check_token():
assert self.token is not None
creds = self._initialize_credentials_from_token(self.token)
if self.show_summary and creds is not None: # pragma: no branch
if show_project_link and creds is not None: # pragma: no branch
creds.print_token_summary()

thread = Thread(target=check_token, name='check_logfire_token')
Expand Down
6 changes: 3 additions & 3 deletions logfire/_internal/config_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class _DefaultCallback:
"""Name of the service emitting spans. For further details, please refer to the [Service section](https://opentelemetry.io/docs/specs/semconv/resource/#service)."""
SERVICE_VERSION = ConfigParam(env_vars=['LOGFIRE_SERVICE_VERSION', 'OTEL_SERVICE_VERSION'], allow_file_config=True)
"""Version number of the service emitting spans. For further details, please refer to the [Service section](https://opentelemetry.io/docs/specs/semconv/resource/#service)."""
SHOW_SUMMARY = ConfigParam(env_vars=['LOGFIRE_SHOW_SUMMARY'], allow_file_config=True, default=True, tp=bool)
"""Whether to show the summary when a new project is created."""
CREDENTIALS_DIR = ConfigParam(env_vars=['LOGFIRE_CREDENTIALS_DIR'], allow_file_config=True, default='.logfire', tp=Path)
"""The directory where to store the configuration file."""
CONSOLE = ConfigParam(env_vars=['LOGFIRE_CONSOLE'], allow_file_config=True, default=True, tp=bool)
Expand All @@ -84,6 +82,8 @@ class _DefaultCallback:
"""Whether to log in verbose mode in the console."""
CONSOLE_MIN_LOG_LEVEL = ConfigParam(env_vars=['LOGFIRE_CONSOLE_MIN_LOG_LEVEL'], allow_file_config=True, default='info', tp=LevelName)
"""Minimum log level to show in the console."""
CONSOLE_SHOW_PROJECT_LINK = ConfigParam(env_vars=['LOGFIRE_CONSOLE_SHOW_PROJECT_LINK', 'LOGFIRE_SHOW_SUMMARY'], allow_file_config=True, default=True, tp=bool)
"""Whether to enable/disable the console exporter."""
PYDANTIC_PLUGIN_RECORD = ConfigParam(env_vars=['LOGFIRE_PYDANTIC_PLUGIN_RECORD'], allow_file_config=True, default='off', tp=PydanticPluginRecordValues)
"""Whether instrument Pydantic validation.."""
PYDANTIC_PLUGIN_INCLUDE = ConfigParam(env_vars=['LOGFIRE_PYDANTIC_PLUGIN_INCLUDE'], allow_file_config=True, default=set(), tp=Set[str])
Expand All @@ -105,14 +105,14 @@ class _DefaultCallback:
'service_name': SERVICE_NAME,
'service_version': SERVICE_VERSION,
'trace_sample_rate': TRACE_SAMPLE_RATE,
'show_summary': SHOW_SUMMARY,
'data_dir': CREDENTIALS_DIR,
'console': CONSOLE,
'console_colors': CONSOLE_COLORS,
'console_span_style': CONSOLE_SPAN_STYLE,
'console_include_timestamp': CONSOLE_INCLUDE_TIMESTAMP,
'console_verbose': CONSOLE_VERBOSE,
'console_min_log_level': CONSOLE_MIN_LOG_LEVEL,
'console_show_project_link': CONSOLE_SHOW_PROJECT_LINK,
'pydantic_plugin_record': PYDANTIC_PLUGIN_RECORD,
'pydantic_plugin_include': PYDANTIC_PLUGIN_INCLUDE,
'pydantic_plugin_exclude': PYDANTIC_PLUGIN_EXCLUDE,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ def configure_tracking_exporter():
send_to_logfire=True,
token='abc1',
console=False,
fast_shutdown=True,
)
wait_for_check_token_thread()

Expand Down Expand Up @@ -1294,7 +1293,7 @@ def test_send_to_logfire_if_token_present_not_empty(capsys: pytest.CaptureFixtur
'https://logfire-api.pydantic.dev/v1/info',
json={'project_name': 'myproject', 'project_url': 'fake_project_url'},
)
configure(send_to_logfire='if-token-present', console=False)
configure(send_to_logfire='if-token-present')
wait_for_check_token_thread()
assert len(request_mocker.request_history) == 1
assert capsys.readouterr().err == 'Logfire project URL: fake_project_url\n'
Expand Down