JSPM

tracer-component

0.1.0-20230213204243.commit-a69f42d
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 1
    • Score
      100M100P100Q18100F
    • License ISC

    Trace execution spans all across your application.

    Package Exports

    • tracer-component
    • tracer-component/dist/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tracer-component) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Tracer component

    This component creates trace spans over an execution, providing context to the code being executed so it can be traced.

    Usage

    The tracer component is pretty straightforward to use, just import the component, initialize it and wrap your traceable code into a trace span:

    import { createTracerComponent } from '@well-known-components/tracer-component'
    
    const tracer = createTracerComponent()
    tracer.span('my span', () => {
      // Do some work here
    })

    While being into the span, the traced code is able to access the trace context, this is specially useful if we want to add traced logs to our code:

    const tracer = createTracerComponent()
    tracer.span('my span', () => {
      console.log(`[${tracer.getTraceString()}] Starting some work`)
      // Do some work here
      console.log(`[${tracer.getTraceString()}] Finishing some work`)
    })

    In the example given above, the logs will output a trace alongside the log message using the traceparent format.

      [00-7970d1a8361cc811ee59dc3ee1c8134e-0000000000000000-00] Starting some work
      [00-7970d1a8361cc811ee59dc3ee1c8134e-0000000000000000-00] Finishing some work

    As seen in the example, the format is built as: version-traceId-parentId-flags. The trace id makes it easy to track which execution of the span we're logging and will be unique through the span execution. The parent id identifies the span id where the current span was created from, making it possible to track which span originated the current span. All of this values, including version and flags values can be seen in the traceparent format document.