@@ -936,10 +936,14 @@ def check_token():
936936
937937 base_url = self .advanced .generate_base_url (self .token )
938938 headers ['authorization' ] = self .token
939- elif self .send_to_logfire is True and self .advanced .base_url is not None :
940- # We may not need a token if we are sending to a custom
941- # base URL
942- base_url = self .advanced .base_url
939+ elif (
940+ self .send_to_logfire is True
941+ and (provided_base_url := self .advanced .base_url ) is not None
942+ and provided_base_url .startswith ('grpc' )
943+ ):
944+ # We may not need a token if we are sending to a grpc
945+ # endpoint; it could be an otel collector acting as a proxy
946+ base_url = provided_base_url
943947
944948 if base_url is not None :
945949 if base_url .startswith ('grpc://' ):
@@ -961,9 +965,6 @@ def check_token():
961965 endpoint = base_url ,
962966 headers = headers ,
963967 compression = GrpcCompression .Gzip ,
964- # I'm pretty sure that this line here is redundant,
965- # and that passing it to the QuietMetricExporter is what matters
966- # because the PeriodicExportingMetricReader will read it from there.
967968 preferred_temporality = METRICS_PREFERRED_TEMPORALITY ,
968969 )
969970 log_exporter = GrpcOTLPLogExporter (
@@ -984,9 +985,6 @@ def check_token():
984985 headers = headers ,
985986 session = session ,
986987 compression = Compression .Gzip ,
987- # I'm pretty sure that this line here is redundant,
988- # and that passing it to the QuietMetricExporter is what matters
989- # because the PeriodicExportingMetricReader will read it from there.
990988 preferred_temporality = METRICS_PREFERRED_TEMPORALITY ,
991989 )
992990 log_exporter = OTLPLogExporter (
@@ -1020,6 +1018,11 @@ def check_token():
10201018 PeriodicExportingMetricReader (
10211019 QuietMetricExporter (
10221020 metric_exporter ,
1021+ # NB this could really be retrieved from `metric_exporter` by `QuietMetricExporter`,
1022+ # but it is currently a private attribute on `MetricExporter`, we preferred not to reach
1023+ # inside the otel SDK details.
1024+ #
1025+ # Just make sure it always matches.
10231026 preferred_temporality = METRICS_PREFERRED_TEMPORALITY ,
10241027 )
10251028 )
0 commit comments