def setUp(self): super().setUp() self.app = fastapi.FastAPI() @self.app.get("/foobar") async def _(): return {"message": "hello world"} otel_fastapi.FastAPIInstrumentor().instrument_app(self.app) self.client = TestClient(self.app) self.tracer = self.tracer_provider.get_tracer(__name__)
def setUp(self): super().setUp() self.env_patch = patch.dict( "os.environ", { OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Custom-Test-Header-1,Custom-Test-Header-2,Custom-Test-Header-3", OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "Custom-Test-Header-1,Custom-Test-Header-2,Custom-Test-Header-3", }, ) self.env_patch.start() self.app = self._create_app() otel_fastapi.FastAPIInstrumentor().instrument_app(self.app) self.client = TestClient(self.app)
def setUp(self): super().setUp() self.env_patch = patch.dict( "os.environ", {"OTEL_PYTHON_FASTAPI_EXCLUDED_URLS": "/exclude/123,healthzz"}, ) self.env_patch.start() self.exclude_patch = patch( "opentelemetry.instrumentation.fastapi._excluded_urls", get_excluded_urls("FASTAPI"), ) self.exclude_patch.start() self._instrumentor = otel_fastapi.FastAPIInstrumentor() self._app = self._create_app() self._client = TestClient(self._app)
def test_instrumentation(self): """Verify that instrumentation methods are instrumenting and removing as expected. """ instrumentor = otel_fastapi.FastAPIInstrumentor() original = fastapi.FastAPI instrumentor.instrument() try: instrumented = fastapi.FastAPI self.assertIsNot(original, instrumented) finally: instrumentor.uninstrument() should_be_original = fastapi.FastAPI self.assertIs(original, should_be_original)
def setUp(self): super().setUp() self.env_patch = patch.dict( "os.environ", { OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Custom-Test-Header-1,Custom-Test-Header-2,Custom-Test-Header-3", }, ) self.env_patch.start() self.app = fastapi.FastAPI() @self.app.get("/foobar") async def _(): return {"message": "hello world"} reset_trace_globals() tracer_provider = trace.NoOpTracerProvider() trace.set_tracer_provider(tracer_provider=tracer_provider) self._instrumentor = otel_fastapi.FastAPIInstrumentor() self._instrumentor.instrument_app(self.app) self.client = TestClient(self.app)
def tearDown(self) -> None: super().tearDown() self.env_patch.stop() with self.disable_logging(): otel_fastapi.FastAPIInstrumentor().uninstrument_app(self.app)
def setUp(self): super().setUp() self._instrumentor = otel_fastapi.FastAPIInstrumentor() self._app = self._create_app() self._client = TestClient(self._app)