From 987dddeb00f51b86c80dae91987f46c720b60528 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Fri, 21 Jun 2024 14:20:59 +0200 Subject: [PATCH 1/2] Remove logfire_api_session parameter from logfire.configure --- logfire/_internal/config.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/logfire/_internal/config.py b/logfire/_internal/config.py index 2a0252f50..6fd0e5a1b 100644 --- a/logfire/_internal/config.py +++ b/logfire/_internal/config.py @@ -153,7 +153,6 @@ def configure( default_span_processor: Callable[[SpanExporter], SpanProcessor] | None = None, metric_readers: None = None, additional_metric_readers: Sequence[MetricReader] | None = None, - logfire_api_session: requests.Session | None = None, pydantic_plugin: PydanticPlugin | None = None, fast_shutdown: bool = False, scrubbing_patterns: Sequence[str] | None = None, @@ -201,7 +200,6 @@ def configure( which exports metrics to Logfire's API. Ensure that `preferred_temporality=logfire.METRICS_PREFERRED_TEMPORALITY` is passed to the constructor of metric readers/exporters that accept the `preferred_temporality` argument. - logfire_api_session: HTTP client session used to communicate with the Logfire 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`. @@ -247,7 +245,6 @@ def configure( additional_span_processors=additional_span_processors, default_span_processor=default_span_processor, additional_metric_readers=additional_metric_readers, - logfire_api_session=logfire_api_session, pydantic_plugin=pydantic_plugin, fast_shutdown=fast_shutdown, scrubbing_patterns=scrubbing_patterns, @@ -308,9 +305,6 @@ class _LogfireConfigData: id_generator: IdGenerator """The ID generator to use""" - logfire_api_session: requests.Session - """The session to use when checking the Logfire backend""" - ns_timestamp_generator: Callable[[], int] """The nanosecond timestamp generator to use""" @@ -354,7 +348,6 @@ def _load_configuration( additional_span_processors: Sequence[SpanProcessor] | None, default_span_processor: Callable[[SpanExporter], SpanProcessor] | None, additional_metric_readers: Sequence[MetricReader] | None, - logfire_api_session: requests.Session | None, pydantic_plugin: PydanticPlugin | None, fast_shutdown: bool, scrubbing_patterns: Sequence[str] | None, @@ -421,7 +414,6 @@ def _load_configuration( self.additional_span_processors = additional_span_processors self.default_span_processor = default_span_processor or _get_default_span_processor self.additional_metric_readers = additional_metric_readers - self.logfire_api_session = logfire_api_session or requests.Session() if self.service_version is None: try: self.service_version = get_git_revision_hash() @@ -451,7 +443,6 @@ def __init__( additional_span_processors: Sequence[SpanProcessor] | None = None, default_span_processor: Callable[[SpanExporter], SpanProcessor] | None = None, additional_metric_readers: Sequence[MetricReader] | None = None, - logfire_api_session: requests.Session | None = None, pydantic_plugin: PydanticPlugin | None = None, fast_shutdown: bool = False, scrubbing_patterns: Sequence[str] | None = None, @@ -484,7 +475,6 @@ def __init__( additional_span_processors=additional_span_processors, default_span_processor=default_span_processor, additional_metric_readers=additional_metric_readers, - logfire_api_session=logfire_api_session, pydantic_plugin=pydantic_plugin, fast_shutdown=fast_shutdown, scrubbing_patterns=scrubbing_patterns, @@ -521,7 +511,6 @@ def configure( additional_span_processors: Sequence[SpanProcessor] | None, default_span_processor: Callable[[SpanExporter], SpanProcessor] | None, additional_metric_readers: Sequence[MetricReader] | None, - logfire_api_session: requests.Session | None, pydantic_plugin: PydanticPlugin | None, fast_shutdown: bool, scrubbing_patterns: Sequence[str] | None, @@ -548,7 +537,6 @@ def configure( additional_span_processors, default_span_processor, additional_metric_readers, - logfire_api_session, pydantic_plugin, fast_shutdown, scrubbing_patterns, @@ -637,13 +625,12 @@ 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: - credentials: LogfireCredentials | None = None if self.token is None: if (credentials := LogfireCredentials.load_creds_file(self.data_dir)) is None: # pragma: no branch credentials = LogfireCredentials.initialize_project( logfire_api_url=self.base_url, project_name=self.project_name, - session=self.logfire_api_session, + session=requests.Session(), ) credentials.write_creds_file(self.data_dir) self.token = credentials.token @@ -658,8 +645,6 @@ def add_span_processor(span_processor: SpanProcessor) -> None: credentials.print_token_summary() headers = {'User-Agent': f'logfire/{VERSION}', 'Authorization': self.token} - self.logfire_api_session.headers.update(headers) - session = OTLPExporterHttpSession(max_body_size=OTLP_MAX_BODY_SIZE) session.headers.update(headers) otel_traces_exporter_env = os.getenv(OTEL_TRACES_EXPORTER) @@ -763,7 +748,7 @@ def meter(self) -> metrics.Meter: return self.get_meter_provider().get_meter('logfire', VERSION) def _initialize_credentials_from_token(self, token: str) -> LogfireCredentials | None: - return LogfireCredentials.from_token(token, self.logfire_api_session, self.base_url) + return LogfireCredentials.from_token(token, requests.Session(), self.base_url) def _get_default_span_processor(exporter: SpanExporter) -> SpanProcessor: From 29296adb582a0482d36d2ffee1f5fdec3ce83763 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Fri, 21 Jun 2024 14:21:51 +0200 Subject: [PATCH 2/2] Remove logfire_api_session parameter from logfire.configure --- tests/test_configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_configure.py b/tests/test_configure.py index 7a8257b7b..36b1cb230 100644 --- a/tests/test_configure.py +++ b/tests/test_configure.py @@ -785,7 +785,7 @@ def normalize(s: dict[str, Any]) -> dict[str, Any]: for value in s.values(): assert not dataclasses.is_dataclass(value) # These values get deepcopied by dataclasses.asdict, so we can't compare them directly - return {k: v for k, v in s.items() if k not in ['logfire_api_session', 'id_generator']} + return {k: v for k, v in s.items() if k not in ['id_generator']} assert normalize(serialized) == normalize(serialized2)