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] Add BaggageSpanProcessor to allow multi-span attributes #66

Closed
JamieDanielson opened this issue Feb 12, 2024 · 0 comments · Fixed by #74
Closed

[feat] Add BaggageSpanProcessor to allow multi-span attributes #66

JamieDanielson opened this issue Feb 12, 2024 · 0 comments · Fixed by #74
Assignees
Labels
type: enhancement New feature or request
Milestone

Comments

@JamieDanielson
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Add a BaggageSpanProcessor to use in the web SDK, similar to what exists today in the Node Distro, to easily add attributes to downstream spans in a trace using baggage.

Describe the solution you'd like

#13 specifically references using a shared package extracted out from the Node Distro and packaged separately to use in both places. For now we're going to essentially copy the functionality into here, and separate the shared dependency later.

@JamieDanielson JamieDanielson added the type: enhancement New feature or request label Feb 12, 2024
@JamieDanielson JamieDanielson added this to the Beta milestone Feb 12, 2024
@JamieDanielson JamieDanielson self-assigned this Feb 14, 2024
JamieDanielson added a commit that referenced this issue Feb 15, 2024
## Which problem is this PR solving?

- Closes #66 

## Short description of the changes

- Add BaggageSpanProcessor, and configure it in the span processor
builder
- Add and update tests to confirm baggage gets added as span attributes
- Add debug log for entries in baggage

## How to verify that this has the expected result

In the example app, add something to baggage and see it show up as an
attribute on a span created from parent context:

```js
  const tracer = trace.getTracer('example-tracer');
  // new context based on current, with key/values added to baggage
  const ctx = propagation.setBaggage(
    context.active(),
    propagation.createBaggage({
      for_the_spans: { value: 'important value' },
    }),
  );
  // starting a new span on the tracer using the saved context
  context.with(ctx, () => {
    tracer.startActiveSpan('heygirl', (span) => {
      // do work here
      span.end();
    })
  })
```

![baggage is span
attribute](https://github.com/honeycombio/honeycomb-opentelemetry-web/assets/29520003/8a29d739-710a-439c-8394-b8cffa68c39b)

or nest even further to get on downstream spans as well

```js
  const tracer = trace.getTracer('example-tracer');
  // new context based on current, with key/values added to baggage
  const ctx = propagation.setBaggage(
    context.active(),
    propagation.createBaggage({
      for_the_spans: { value: 'important value' },
    }),
  );
  // starting a new span on the tracer using the saved context
  context.with(ctx, () => {
    tracer.startActiveSpan('heygirl', (span) => {
      // do work here
      context.with(trace.setSpan(context.active(), span), () => {
        tracer.startActiveSpan('heygirl2', (childspan) => {
          // do work here
          childspan.end();
        });
        span.end();
      })
    })
  });
```


![image](https://github.com/honeycombio/honeycomb-opentelemetry-web/assets/29520003/9ff3e930-3b26-40c5-865d-88888b9142dc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant