DataDog / dd-trace-js

JavaScript APM Tracer
https://docs.datadoghq.com/tracing/
Other
654 stars 307 forks source link

Add support for TRPC clients #4458

Open alyahmedaly opened 4 months ago

alyahmedaly commented 4 months ago

I'm trying TRPC in one of our apps, but I don't see the trpc counted as separate resource in the apm dashboard, maybe it's our setup as we use express.js and I want to be able to incrementally move to trpc.

alyahmedaly commented 4 months ago

found a solution Thanks datadog team for having plugin system, sharing here maybe someone else will need this

 tracer.use('express', {
      hooks: {
        request(span, req) {
          if (!span || !req || !('baseUrl' in req)) return;
          const expressReq = req as express.Request;
          if (!expressReq.baseUrl?.endsWith('/api/rpc') && expressReq.path) {
            return;
          }
          span.setTag('http.route', `${expressReq.baseUrl}${expressReq.path}`);
        },
      },
    });

but will be great if we get native support so I will keep the issue open and if you copied/used this react with heart it will make my day that I helped another Person ❤️