Comments (4)
@sats268842 Do you have any middleware installed that are catching exceptions and not re-raising them? I was running into the same issue, and it was due to this middleware: https://gist.github.com/nymous/f138c7f06062b7c43c060bf03759c29e, which does something like:
response = Response(status_code=500)
try:
response = await call_next(request)
except Exception:
# do something
raise
finally:
# do something else
return response
The problem was specifically with the return response
inside of the finally
blockβthis swallows the exception, so ddtrace
's TracingMiddleware
never receives the exception and is therefore never able to add it to the trace.
I fixed it by moving the return response
to outside of the finally
block, and being OK with not returning my own Response(status_code=500)
from this middleware. I'm handling it in an exception handler instead:
@app.exception_handler(Exception)
async def handle_exceptions(exc: Exception):
return Response(status_code=500)
from dd-trace-py.
Thanks for the report @sats268842. We'll see if we can put together a demo app that reproduces this behavior. If you have one you can share, that would be helpful.
from dd-trace-py.
@emmettbutler Additionally, I've discovered that if you install both the auto instrumentation library injection and the ddtrace Python package, the tracing and metrics won't work. Also I will look into demo app, if time permits.
from dd-trace-py.
@emmettbutler Also got workaround for this issue using below code
from ddtrace.opentelemetry import TracerProvider
from opentelemetry.trace import set_tracer_provider
set_tracer_provider(TracerProvider())
@app.exception_handler(StarletteHTTPException)
async def http_exception_handler(request: Request, exc):
import traceback
current_span = trace.get_current_span()
if (current_span is not None) and (current_span.is_recording()):
print(exc.__class__.__name__)
exc_type, exc_value, exc_traceback = sys.exc_info()
filename, line_number, function_name, code = traceback.extract_tb(exc_traceback)[-1]
attributes = {
"error.message": str(exc.detail),
"error.kind": exc.__class__.__name__,
"error.type": exc.__class__.__name__,
"error.stack": traceback.format_exc(),
"error.file": filename,
"error.line": line_number,
"error.function": function_name,
"http.status_code": exc.status_code,
}
current_span.set_status(StatusCode.ERROR, str(exc.detail))
current_span.set_attributes(attributes)
return ORJSONResponse(({"detail": str(exc.detail)}), status_code=exc.status_code)
from dd-trace-py.
Related Issues (20)
- Upgrading from v2.4.0 to v2.8.1 changes tracking from `trace.django.request` to `trace.django.middleware` HOT 3
- ddtrace breaks Bedrock Cohere Command R models
- grpc integration causes exception with grpc.aio streaming HOT 1
- ModuleWatchdog is installed unconditionally when ddtrace is imported HOT 1
- Elastic Search Quantization not always effective and does not match Datadog agent's
- Segmentation Fault in dd-trace-py on Python 3.12 HOT 3
- OpenAI: TypeError: 'NoneType' object cannot be interpreted as an integer HOT 4
- The gRPC AIO server integration fails to set the gRPC status code for the span HOT 1
- Langchain patch assumes that you have langchain_community installed HOT 3
- Errors parsing DSNs when using both psycopg2 and psycopg
- Feature Request: [LLMObs] Support Automatic spans for `langchain_community`'s tools and retriever. HOT 3
- High CPU utilization causing kubernetes pod scaling with ddtrace > 2.3.0 HOT 2
- Cannot override the `service_name` for the `requests` integration HOT 1
- Boto3 Bedrock Client - Propogate Http x-datadog headers HOT 2
- Langchain v0.2+: ModuleNotFoundError: No module named 'langchain_community' HOT 2
- How to handle deprecation of `ddtrace.context.Context` when it is still present in public API? HOT 1
- Using ddtrace-run together with `gUnicorn` causes all `Spyne` SOAP endpoints to break. HOT 1
- Python 3.12 / ddtrace-run combined with psycopg3 AsyncConnectionPool leads to `TypeError: 'async for' requires an object with __aiter__ method, got Psycopg3TracedAsyncCursor` when consuming iterator HOT 1
- Add handled exceptions to error tracking
- TypeError: unhashable type: 'dict' thrown from cache
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dd-trace-py.