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="[]", timeout=2
     )
示例#2
0
 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")
示例#3
0
    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

        constructor_param_version = Protocol.V2
        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

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

        self.assertIsInstance(exporter.encoder, JsonV2Encoder)
        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)
示例#4
0
 def test_constructor_default(self):
     exporter = ZipkinExporter()
     self.assertIsInstance(exporter.encoder, JsonV2Encoder)
     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)
示例#5
0
    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)
示例#6
0
    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=endpoint)

        self.assertIsInstance(exporter.encoder, JsonV2Encoder)
        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)
示例#8
0
    def tracer_provider(
        tracer_type: str = Provide[config.tracing.type],
        sample_rate: t.Optional[float] = Provide[config.tracing.sample_rate],
        zipkin_server_url: t.Optional[str] = Provide[
            config.tracing.zipkin.url],
        jaeger_server_address: t.Optional[str] = Provide[
            config.tracing.jaeger.address],
        jaeger_server_port: t.Optional[int] = Provide[
            config.tracing.jaeger.port],
    ):
        from opentelemetry.sdk.trace import TracerProvider
        from opentelemetry.sdk.trace.export import BatchSpanProcessor

        from ..utils.telemetry import ParentBasedTraceIdRatio

        if sample_rate is None:
            sample_rate = 0.0

        provider = TracerProvider(
            sampler=ParentBasedTraceIdRatio(sample_rate),
            # resource: Resource = Resource.create({}),
            # shutdown_on_exit: bool = True,
            # active_span_processor: Union[
            # SynchronousMultiSpanProcessor, ConcurrentMultiSpanProcessor
            # ] = None,
            # id_generator: IdGenerator = None,
        )

        if tracer_type == "zipkin" and zipkin_server_url is not None:
            from opentelemetry.exporter.zipkin.json import ZipkinExporter

            exporter = ZipkinExporter(endpoint=zipkin_server_url, )
            provider.add_span_processor(BatchSpanProcessor(exporter))
            return provider
        elif (tracer_type == "jaeger" and jaeger_server_address is not None
              and jaeger_server_port is not None):
            from opentelemetry.exporter.jaeger.thrift import JaegerExporter

            exporter = JaegerExporter(
                agent_host_name=jaeger_server_address,
                agent_port=jaeger_server_port,
            )
            provider.add_span_processor(BatchSpanProcessor(exporter))
            return provider
        else:
            return provider
示例#9
0
 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)
示例#10
0
 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)