designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

Feature request: RUM SDK should provide a way to start/stop spans

Open hipitihop opened this issue 2 years ago • 3 comments

Request Our SPA app would like to be able to start and stop root spans and child spans https://help.datadoghq.com/hc/en-us/requests/822482 so that multiple operations can be grouped and visualized on the timeline. Each span can then show total duration across the operations within it's group.

Background Currently our application uses RUM addAction and startView API and also uses the logs API. Often, multiple operations are considered part of a logical coordinated group. Some operations may be web-socket based calls to our GrapghQL back-end (currently RUM does not wrap websockets), others operations may be XHR requests and the like. Such logical grouping can be considered to be further composable from other child sub groups of operations.

An example flow:

-> DD_RUM/addAction("bootstrap-start") (root span)

   -> DD_RUM/addAction("fetch-jwt")
      -> HTTP/XHR request to server endpoint (traced by RUM)

   -> DD_RUM/addAction("fetch-configuration")
      -> HTTP/XHR request to server endpoint (traced by RUM)
      -> DD_LOGS.logger.info(JSON payload)

   -> DD_RUM/addAction("db-connect") (child span 1)
      -> Establish Websocket connect to GraphQL
      -> Setup initial GraphQL subscriptions over websocket.
      (end child span 1)

   ->  DD_RUM/addAction("fetch-static-assets") (child span 2)
      -> HTTP/XHR request 1
      -> HTTP/XHR request 2
      -> HTTP/XHR request 3
      (end child span 2)

-> DD_RUM/addAction("success-bootstrap") (end root span)

Notes/Suggestions:

  • typically an action could be considered the start of child span, however, an action may not represent the end of the previous span.

  • perhaps the addAction API could be extended, to optionally include start and/or stop span names, either or both in the options. e.g.

    {"startSpan": "child-span-2",
     "stopSpan": "child-span-1"}
    
  • for additional decoupling so that actions are not the only way to stop and start spans, have a separate API. e.g.

    DD_RUM/startSpan("bootstrap")
    
    DD_RUM/stopSpan("bootstrap")
    

    Example with optional stopSpan argument. This starts child span 2 and stops child span 1

    DD_RUM/startSpan("child-span-2", "child-span-1")
    
  • span names should probably follow the hierarchical tag name conventions e.g. "bootstrap" for the root span, then "bootstrap.child1" and "bootstrap.child1.subchild1" Then ending a span higher up the tag hierarchy is considered to stop all sub-spans. e.g. DD_RUM/stopSpan("bootstrap") will stop all child spans.

Raising this as a continuation of https://help.datadoghq.com/hc/en-us/requests/822482

hipitihop avatar Jul 13 '22 02:07 hipitihop

Hello, Thank you for bringing this up! This is something we definitly want to explore. It's not quite yet on our roadmap though. We'll keep you posted on this issue.

BenoitZugmeyer avatar Aug 02 '22 09:08 BenoitZugmeyer

Hello, Thank you for bringing this up! This is something we definitly want to explore. It's not quite yet on our roadmap though. We'll keep you posted on this issue.

Do you suggest any workaround in the meantime ? e.g. by using a normal HTTP POST ingest endpoint ?

hipitihop avatar Aug 02 '22 23:08 hipitihop

We don't have anything better than what you are using right now (addAction("something-start") ... addAction("something-end"))

Using the intake endpoint directly would not be straightforward. Even if you would succeeded to send correctly assembled RUM events, the UI might not expect such spans and would fail to display them accurately.

BenoitZugmeyer avatar Aug 03 '22 16:08 BenoitZugmeyer