Description
While trying to initialize a HTTP exporter, I mistakenly passed a GRPC one which led to the silent truncation of the endpoint value. This caused confusion and resulted in hours of debugging. The source of the confusion was this import line:
Instead of
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
I copy pasted from the commonly available examples, which use:
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
This issue might be a common occurrence for newcomers, as almost all the examples use the GRPC exporter. To prevent this from happening in the future, I propose adding a warning message in the OTLP GRPC Exporter when there is a mismatch between the configured endpoint and the provided endpoint. This would provide clear, actionable feedback to the user and improve the overall user experience.
Here’s the proposed change:
if parsed_url.netloc:
self._endpoint = parsed_url.netloc
if parsed_url.path:
logger.warning(f"Endpoint set to {self._endpoint}, which differs from the provided endpoint {endpoint}. If you're trying to configure a HTTP endpoint, please ensure you're using the correct exporter.")
This change replaces the existing code:
if parsed_url.netloc:
self._endpoint = parsed_url.netloc