11import io
22import json
3- import os
43import re
54from unittest import mock
65
7- import pytest
86from opentelemetry .sdk .resources import Resource
97from opentelemetry .sdk .trace import TracerProvider
108from opentelemetry .sdk .trace .export import ConsoleSpanExporter , SimpleSpanProcessor
119from opentelemetry .trace import set_tracer_provider
1210from yarl import URL
1311
12+ from crawlee import ConcurrencySettings
1413from crawlee .crawlers import ParselCrawler
1514from crawlee .otel .crawler_instrumentor import CrawlerInstrumentor
1615from crawlee .storages import Dataset
1716
1817
19- @pytest .mark .skipif (
20- os .name == 'nt' ,
21- reason = 'This test is flaky on Windows, see https://github.com/apify/crawlee-python/issues/1469.' ,
22- )
2318async def test_crawler_instrumentor_capability (server_url : URL ) -> None :
2419 """Test OpenTelemetry instrumentation capability of the crawler.
2520
@@ -40,15 +35,20 @@ async def test_crawler_instrumentor_capability(server_url: URL) -> None:
4035 provider .add_span_processor (SimpleSpanProcessor (exporter ))
4136 set_tracer_provider (provider )
4237 # Instrument the crawler with OpenTelemetry
43- CrawlerInstrumentor (instrument_classes = [Dataset ]).instrument ()
38+ instrumentor = CrawlerInstrumentor (instrument_classes = [Dataset ])
39+ instrumentor .instrument ()
4440
4541 # Generate first telemetry data from `Dataset` public methods.
4642 # `Dataset` is in `instrument_classes` argument, and thus it's public methods are instrumented.
4743 dataset = await Dataset .open (name = 'test-dataset' )
4844 await dataset .drop ()
4945
5046 # Other traces will be from crawler run.
51- crawler = ParselCrawler (max_requests_per_crawl = 1 , request_handler = mock .AsyncMock ())
47+ crawler = ParselCrawler (
48+ max_requests_per_crawl = 1 ,
49+ request_handler = mock .AsyncMock (),
50+ concurrency_settings = ConcurrencySettings (desired_concurrency = 1 , max_concurrency = 1 ),
51+ )
5252
5353 # Run crawler and generate more telemetry data.
5454 await crawler .run ([str (server_url )])
0 commit comments