Open adriangb opened 1 week ago
MRE:
import anyio import fastapi import httpx import uvicorn from opentelemetry import trace from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter resource = Resource(attributes={SERVICE_NAME: '🐛'}) traceProvider = TracerProvider(resource=resource) processor = BatchSpanProcessor(ConsoleSpanExporter()) traceProvider.add_span_processor(processor) trace.set_tracer_provider(traceProvider) app = fastapi.FastAPI() @app.get('/ok') async def ok() -> int: return 123 @app.get('/error') async def error() -> int: raise Exception('An error occurred!') FastAPIInstrumentor.instrument_app(app) async def main() -> None: config = uvicorn.Config(app=app, port=9999, log_config=None) server = uvicorn.Server(config) async with anyio.create_task_group() as tg: tg.start_soon(server.serve) await anyio.sleep(1) # Wait for the server to start async with httpx.AsyncClient(base_url='http://localhost:9999') as client: response = await client.get('/ok') assert response.status_code == 200, f'{response.status_code}: {response.text}' response = await client.get('/error') assert response.status_code == 500, f'{response.status_code}: {response.text}' tg.cancel_scope.cancel() if __name__ == '__main__': anyio.run(main)
With this change it shows up properly
Run this and you'll see that there is no "http.status_code": 500 in the logs.
"http.status_code": 500
@adriangb Please take a look at the failing tests
fixes https://github.com/open-telemetry/opentelemetry-python-contrib/issues/795
MRE:
With this change it shows up properly
Run this and you'll see that there is no
"http.status_code": 500
in the logs.