DataDog / dd-trace-java

Datadog APM client for Java
https://docs.datadoghq.com/tracing/languages/java
Apache License 2.0
587 stars 290 forks source link

Twilio Instrumentation for Paged request #2606

Open vuquocbao opened 3 years ago

vuquocbao commented 3 years ago

Hello,

I was wondering if you can add support for getting paged results from the twilio sdk?

So in the TwilioReader class there are multiple methods like firstPage, nextPage, lastPage, etc. I was wondering if these can be added.

So we use dd-trace-java in our project and when we call most of the twilio apis the spans shows up except when we read the from a resource using one of these page methods.

https://github.com/DataDog/dd-trace-java/blob/0a24e307f0b4e6abbfd3cdbce5231095f6d9a632/dd-java-agent/instrumentation/twilio/src/main/java/datadog/trace/instrumentation/twilio/TwilioSyncInstrumentation.java#L78

lpriima commented 3 years ago

@vuquocbao ,

Did you try to list these extra twilio methods in system property dd.trace.methods ( https://docs.datadoghq.com/tracing/setup_overview/setup/java/?tab=containers#configuration ) ? Does it show the paginated spans the way you expect or you want something different ?

vuquocbao commented 3 years ago

@lpriima I added the methods into the system properties in my yaml config.

    - name: DD_TRACE_METHODS
      value: "com.twilio.rest.taskrouter.v1.workspace.TaskReader[*]"

So we have a span for the HTTP call but it is not split out into a different service like the methods defined in the TwilioSyncInstrumentation.

Any methods defined there get a new span and the span is treated as a different service in the APM. See the attached image. The turquoise spans are the ones created with TwilioSyncInstrumentation on the Twilio JavaSDK. The span that my mouse is highlighted over the HTTP span created when calling the paged methods. It does not show up in the twilio-sdk apm unlike create, delete, read, fetch, or update methods from the sdk.

I assume it would be pretty straightforward to add those methods to the file I noted above. I could make an MR but I'm very familiar with this code base and how bytebuddy works

image