Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ConsoleSpanExporter): export span links #2917

Merged
merged 5 commits into from
Apr 26, 2022

Conversation

trentm
Copy link
Contributor

@trentm trentm commented Apr 21, 2022

Which problem is this PR solving?

Currently the ConsoleSpanExporter does not include Span links, if the span happens to have any.

Short description of the changes

This PR adds span.links to the exported info.

As well, this changes the exporter to use console.dir(...) instead of console.log(...) so that the object depth can be set to 3, instead of the default 2. It is the difference between this (with console.log):

{
  traceId: '6f8d4df4cf914faaeaf99e958d788950',
  parentId: undefined,
  name: 'sLinksWithAttrs',
  id: 'e0b9b5d27579168d',
  kind: 0,
  timestamp: 1650492644954686,
  duration: 7,
  attributes: {},
  links: [ { context: [Object], attributes: [Object] } ],
  status: { code: 0 },
  events: []
}

and this (console.dir with depth 3):

{
  traceId: '48472434d1b96f48482761a3521b0d97',
  parentId: undefined,
  name: 'sLinksWithAttrs',
  id: '6fd6da8c3d98b995',
  kind: 0,
  timestamp: 1650492651408875,
  duration: 7,
  attributes: {},
  links: [
    {
      context: {
        traceId: '27d5c6b33e4bb5be49582ca14644e262',
        spanId: 'b88e2cb9c6a434bd',
        traceFlags: 1,
        traceState: undefined
      },
      attributes: { 'a.string': 'hi', 'a.number': 42 }
    }
  ],
  status: { code: 0 },
  events: []
}

This does mean an additional links: [] in the output of each span for the common case where there are no links. However, given ConsoleSpanExporter is for dev/debugging, that slight additional noise doesn't seem bad.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Besides running this manually:

// consolelinks.js
const api = require('@opentelemetry/api')
const { NodeTracerProvider } = require('./packages/opentelemetry-sdk-trace-node') // '@opentelemetry/sdk-trace-node'
const { SimpleSpanProcessor, ConsoleSpanExporter } = require('./packages/opentelemetry-sdk-trace-base') // '@opentelemetry/sdk-trace-base'
const provider = new NodeTracerProvider()
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()))
provider.register()
const tracer = api.trace.getTracer('consolelinks')

const s1 = tracer.startSpan('sLinksNone')
s1.end()
const s2 = tracer.startSpan('sLinksWithAttrs', {
  links: [{ context: s1.spanContext(), attributes: { 'a.string': 'hi', 'a.number': 42 } }]
})
s2.end()

I also updated ConsoleSpanExporter.test.ts to expect a "links" key in the output.

Checklist:

  • Followed the style guidelines of this project (at least I believe so)
  • Unit tests have been added
  • Documentation has been updated

@trentm trentm requested a review from a team April 21, 2022 16:29
@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #2917 (405580b) into main (28a177f) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #2917   +/-   ##
=======================================
  Coverage   92.81%   92.81%           
=======================================
  Files         184      184           
  Lines        6066     6066           
  Branches     1296     1296           
=======================================
  Hits         5630     5630           
  Misses        436      436           
Impacted Files Coverage Δ
...y-sdk-trace-base/src/export/ConsoleSpanExporter.ts 78.57% <100.00%> (ø)

@legendecas legendecas merged commit 6710cdd into open-telemetry:main Apr 26, 2022
@trentm
Copy link
Contributor Author

trentm commented Apr 27, 2022

Thanks!

@trentm trentm deleted the links-in-consolespanexporter branch April 27, 2022 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants