def test_export_timeout(self, mock_post):
     mock_post.return_value = MockResponse(200)
     spans = []
     exporter = ZipkinExporter(timeout=2)
     status = exporter.export(spans)
     self.assertEqual(SpanExportResult.SUCCESS, status)
     mock_post.assert_called_with(url="http://localhost:9411/api/v2/spans",
                                  data=b"",
                                  timeout=2)
 def test_export_span_service_name(self, mock_post):
     mock_post.return_value = MockResponse(200)
     resource = Resource.create({SERVICE_NAME: "test"})
     context = trace.SpanContext(
         trace_id=0x000000000000000000000000DEADBEEF,
         span_id=0x00000000DEADBEF0,
         is_remote=False,
     )
     span = _Span("test_span", context=context, resource=resource)
     span.start()
     span.end()
     exporter = ZipkinExporter()
     exporter.export([span])
     self.assertEqual(exporter.local_node.service_name, "test")
    def test_constructor_all_params_and_env_vars(self):
        """Test the scenario where all params are provided and all OS env
        vars are set. Explicit params should take precedence.
        """
        os_endpoint = "https://os.env.param:9911/path"
        os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] = os_endpoint
        os.environ[OTEL_EXPORTER_ZIPKIN_TIMEOUT] = "15"

        constructor_param_endpoint = "https://constructor.param:9911/path"
        local_node_ipv4 = "192.168.0.1"
        local_node_ipv6 = "2001:db8::1000"
        local_node_port = 30301
        max_tag_value_length = 56
        timeout_param = 20

        exporter = ZipkinExporter(
            constructor_param_endpoint,
            local_node_ipv4,
            local_node_ipv6,
            local_node_port,
            max_tag_value_length,
            timeout_param,
        )

        self.assertIsInstance(exporter.encoder, ProtobufEncoder)
        self.assertEqual(exporter.endpoint, constructor_param_endpoint)
        self.assertEqual(exporter.local_node.service_name, TEST_SERVICE_NAME)
        self.assertEqual(exporter.local_node.ipv4,
                         ipaddress.IPv4Address(local_node_ipv4))
        self.assertEqual(exporter.local_node.ipv6,
                         ipaddress.IPv6Address(local_node_ipv6))
        self.assertEqual(exporter.local_node.port, local_node_port)
        # Assert timeout passed in constructor is prioritized over env
        # when both are set.
        self.assertEqual(exporter.timeout, 20)
Exemplo n.º 4
0
    def _init_exporter(self, trace_reporter_type):
        exporter_type = ''
        exporter = None
        try:
            if trace_reporter_type == config_pb2.TraceReporterType.ZIPKIN:
                exporter_type = 'zipkin'
                exporter = ZipkinExporter(
                    endpoint=self._config.agent_config.reporting.endpoint)
            elif trace_reporter_type == config_pb2.TraceReporterType.OTLP:
                exporter_type = 'otlp'
                exporter = OTLPGrpcSpanExporter(
                    endpoint=self._config.agent_config.reporting.endpoint,
                    insecure=not self._config.agent_config.reporting.secure)
            elif trace_reporter_type == config_pb2.TraceReporterType.OTLP_HTTP:
                exporter_type = 'otlp_http'
                exporter = OTLPHttpSpanExporter(
                    endpoint=self._config.agent_config.reporting.endpoint)

            if exporter:
                logger.info('Initialized %s exporter reporting to `%s`',
                            exporter_type,
                            self._config.agent_config.reporting.endpoint)
            else:
                logger.error("Unknown exporter type `%s`", trace_reporter_type)

            return exporter
        except Exception as err:  # pylint: disable=W0703
            logger.error(
                'Failed to initialize %s exporter: exception=%s, stacktrace=%s',
                exporter_type, err, traceback.format_exc())
            return None
 def test_constructor_default(self):
     exporter = ZipkinExporter()
     self.assertIsInstance(exporter.encoder, ProtobufEncoder)
     self.assertEqual(exporter.endpoint, DEFAULT_ENDPOINT)
     self.assertEqual(exporter.local_node.service_name, TEST_SERVICE_NAME)
     self.assertEqual(exporter.local_node.ipv4, None)
     self.assertEqual(exporter.local_node.ipv6, None)
     self.assertEqual(exporter.local_node.port, None)
    def test_constructor_env_vars(self):
        os_endpoint = "https://foo:9911/path"
        os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] = os_endpoint

        exporter = ZipkinExporter()

        self.assertEqual(exporter.endpoint, os_endpoint)
        self.assertEqual(exporter.local_node.service_name, TEST_SERVICE_NAME)
        self.assertEqual(exporter.local_node.ipv4, None)
        self.assertEqual(exporter.local_node.ipv6, None)
        self.assertEqual(exporter.local_node.port, None)
    def test_constructor_protocol_endpoint(self):
        """Test the constructor for the common usage of providing the
        protocol and endpoint arguments."""
        endpoint = "https://opentelemetry.io:15875/myapi/traces?format=zipkin"

        exporter = ZipkinExporter(endpoint)

        self.assertIsInstance(exporter.encoder, ProtobufEncoder)
        self.assertEqual(exporter.endpoint, endpoint)
        self.assertEqual(exporter.local_node.service_name, TEST_SERVICE_NAME)
        self.assertEqual(exporter.local_node.ipv4, None)
        self.assertEqual(exporter.local_node.ipv6, None)
        self.assertEqual(exporter.local_node.port, None)
    def test_export_shutdown(self, mock_post):
        mock_post.return_value = MockResponse(200)
        spans = []
        exporter = ZipkinExporter()
        status = exporter.export(spans)
        self.assertEqual(SpanExportResult.SUCCESS, status)

        exporter.shutdown()
        # Any call to .export() post shutdown should return failure
        status = exporter.export(spans)
        self.assertEqual(SpanExportResult.FAILURE, status)
 def test_export_invalid_response(self, mock_post):
     mock_post.return_value = MockResponse(404)
     spans = []
     exporter = ZipkinExporter()
     status = exporter.export(spans)
     self.assertEqual(SpanExportResult.FAILURE, status)
 def test_export_success(self, mock_post):
     mock_post.return_value = MockResponse(200)
     spans = []
     exporter = ZipkinExporter()
     status = exporter.export(spans)
     self.assertEqual(SpanExportResult.SUCCESS, status)