Hey team, I just tried out the Datadog Adapter and...
# hamilton-help
r
Hey team, I just tried out the Datadog Adapter and could use some help understanding the trace results. I'm using the AsyncDriver and passed in the ddog adapter to `.with_adapters`:
Copy code
datadog_hook = h_ddog.DDOGTracer(root_name="hamilton_dag_trace")

builder = (
    AsyncBuilder()
    .with_config(config)
    .with_modules(*self.included_modules)
    .allow_module_overrides()
    .with_adapters(self.result_builder, datadog_hook)
)
driver = await builder.build()
I see the traces ok in DataDog but trying to figure out what's happening during long idle times in the graph. I have 5 Hamilton functions that fetch from Postgres, each of which uses
extract_columns
to extract total of ~300 nodes. The odd thing is I see all the nodes execute really fast at the beginning of the graph, and then the postgres queries fire after, with no node execution after that. Is this something in the way the AsyncDriver works by creating a bunch of asyncio tasks at once and awaiting asyncio.gather for them to complete, and the datadog spans are only running over task creation, not the function body running?
Here's a screenshot example graph. There's a few large gaps with nothing recorded so trying to figure out what might have been happening there
e
Yes, this is likely the async driver. We have updated this for the Hamilton UI, can probably apply the same approach to ddog. Basically it measures the execution of the function which just creates a coroutine/promise, computing it runs later. AFK but can take a look at the code later!
r
Ok thanks! Makes sense
Something else I'm noticing is my FastAPI trace is not connected as the parent to Hamilton's, i.e. I get 2 separate traces for the same request. Is there a way to pass or get the current parent trace and set that as the parent to Hamilton's execution?
s
Just to understand how to reproduce that, what is creating the outer trace context?
r
I'm using
ddtrace-run uvicorn ...
to auto patch modules like FastAPI. I believe they auto wire in middleware that creates a span around the request
Yeah looks like they patch FastAPI and wrap with this middleware https://github.com/DataDog/dd-trace-py/blob/main/ddtrace/contrib/internal/asgi/middleware.py#L94
e
I’m not at my keyboard but should be able to take a look, it should be able to work with this
Also the OTel adapter might be able to do this in a cleaner way
r
Cool, definitely open to the opentelemetry plugin too if it makes it easier
s
(it’s on the roadmap to have the Hamilton UI also ingest OTel… )
👍 1
r
Know you guys are busy — I put this in an issue for tracking: https://github.com/DAGWorks-Inc/hamilton/issues/1236
🙌 1
e
Thanks! Will take a look soon and scope out — agreed that this is high value (and we should be able to do this with OTel as well)
🙌 1
Heh, just took a look and it looks straightforward. TBD on our timing, but if you want to do it quickly/learn a bit about the internals, my guess is this could be a very simple change to make, and happy to help you/pair on it! See https://github.com/DAGWorks-Inc/hamilton/issues/1236. Obviously would need to test out this strategy, but at first glance it looks like it should work.
r
Awesome, thanks! I'll see if I get some time and can open a PR. I will test out the OTel version first and see if it works better as-is with async
e
Awesome!
Yes happy to hop on a call if you need help