Skip to content

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

Open
@hipitihop

Description

@hipitihop

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions