Skip to content

feat(bottlecap): Add Composite Trace Propagator#413

Merged
duncanista merged 10 commits intojordan.gonzalez/bottlecap/universal-instrumentationfrom
jordan.gonzalez/bottlecap/add-composite-propagator
Oct 21, 2024
Merged

feat(bottlecap): Add Composite Trace Propagator#413
duncanista merged 10 commits intojordan.gonzalez/bottlecap/universal-instrumentationfrom
jordan.gonzalez/bottlecap/add-composite-propagator

Conversation

@duncanista
Copy link
Copy Markdown
Contributor

@duncanista duncanista commented Oct 15, 2024

What?

Creates a composite propagator to extract trace context.

This is because we have specific logic on how we handle/resolve trace context in the tracers.

How?

  • New struct DatadogCompositePropagator using DatadogHeaderPropagator and TraceContextPropagator.
  • Added configuration options so the propagator can decide how to act.

Motivation

SVLS-5769 and...

  • Maintain feature parity with the tracers.

Notes

  • Unit tests were copied from Python tracer, seen as the source of "true".

also updated unit tests, as we have custom behavior, we should check only the fields we care about in the tests
also known as our internal http propagator, but in reality, http doesnt make any sense to me, its just a composite propagator which we used based on our configuration
@duncanista duncanista changed the base branch from main to jordan.gonzalez/bottlecap/universal-instrumentation October 15, 2024 21:52
@duncanista duncanista marked this pull request as ready for review October 17, 2024 17:33
@duncanista duncanista requested a review from a team as a code owner October 17, 2024 17:33
Copy link
Copy Markdown
Contributor

@alexgallotta alexgallotta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job overall!
I would argue that in a lot of places struct/traits could be avoided and make the code easier, more readable, easier to test and shorter though

Comment thread bottlecap/src/config/mod.rs
(contexts, styles)
}

fn resolve_contexts(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this method be outside of the struct implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the only place being used, I'd rather keep it here, there's no other place where this is being used. What would be the benefit of keeping it outside of the struct?

primary_context
}

fn attach_baggage(context: &mut SpanContext, carrier: &dyn Extractor) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this method be outside of the struct implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as the other comment


impl DatadogCompositePropagator {
#[must_use]
pub fn new(config: Arc<config::Config>) -> Self {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If also this method is removed, there is no need of the impl altogether.
It's a bit heavy for a constructor to have all this logic, it could be a builder/function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you modify this? I decided to follow this because of the behavior changes on the configuration, and to save the state of the available propagators, at the end of the day, it will be very cheap in computation

Copy link
Copy Markdown
Contributor

@alexgallotta alexgallotta Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took some time to modify it and give it an idea of what I thought
#418

I think it's already a great job and there is a lot of business logic I am not familiar with!

My take, from what I've read, is to use abstractions and traits/struct very sparingly and when they are really worth it.
Usually better start with basic function and modules most of the time. It helps to also see things differently when the struct impl is not around, and when refactoring or changing something you don't need to change 10 fields all around the code/function initialization!

That PR is not necessarily to merge or continue working on, just to show how it could look like with a different approach

@duncanista duncanista merged commit b5a049a into jordan.gonzalez/bottlecap/universal-instrumentation Oct 21, 2024
@duncanista duncanista deleted the jordan.gonzalez/bottlecap/add-composite-propagator branch October 21, 2024 17:58
alexgallotta pushed a commit that referenced this pull request Nov 4, 2024
* add `trace_propagation_style.rs`

* add Trace Propagation to `config.rs`

also updated unit tests, as we have custom behavior, we should check only the fields we care about in the tests

* add `links` to `SpanContext`

* add composite propagator

also known as our internal http propagator, but in reality, http doesnt make any sense to me, its just a composite propagator which we used based on our configuration

* update `TextMapPropagator`s to comply with interface

also updated the naming

* fmt

* add unit testing for `config.rs`

* add `PartialEq` to `SpanContext`

* correct logic from `text_map_propagator.rs`

logic was wrong in some parts, this was discovered through unit tests

* add unit tests for `DatadogCompositePropagator`

also corrected some logic
duncanista added a commit that referenced this pull request Nov 15, 2024
* add `trace_propagation_style.rs`

* add Trace Propagation to `config.rs`

also updated unit tests, as we have custom behavior, we should check only the fields we care about in the tests

* add `links` to `SpanContext`

* add composite propagator

also known as our internal http propagator, but in reality, http doesnt make any sense to me, its just a composite propagator which we used based on our configuration

* update `TextMapPropagator`s to comply with interface

also updated the naming

* fmt

* add unit testing for `config.rs`

* add `PartialEq` to `SpanContext`

* correct logic from `text_map_propagator.rs`

logic was wrong in some parts, this was discovered through unit tests

* add unit tests for `DatadogCompositePropagator`

also corrected some logic
duncanista added a commit that referenced this pull request Nov 19, 2024
* add `trace_propagation_style.rs`

* add Trace Propagation to `config.rs`

also updated unit tests, as we have custom behavior, we should check only the fields we care about in the tests

* add `links` to `SpanContext`

* add composite propagator

also known as our internal http propagator, but in reality, http doesnt make any sense to me, its just a composite propagator which we used based on our configuration

* update `TextMapPropagator`s to comply with interface

also updated the naming

* fmt

* add unit testing for `config.rs`

* add `PartialEq` to `SpanContext`

* correct logic from `text_map_propagator.rs`

logic was wrong in some parts, this was discovered through unit tests

* add unit tests for `DatadogCompositePropagator`

also corrected some logic
duncanpharvey pushed a commit that referenced this pull request Mar 10, 2026
* add `trace_propagation_style.rs`

* add Trace Propagation to `config.rs`

also updated unit tests, as we have custom behavior, we should check only the fields we care about in the tests

* add `links` to `SpanContext`

* add composite propagator

also known as our internal http propagator, but in reality, http doesnt make any sense to me, its just a composite propagator which we used based on our configuration

* update `TextMapPropagator`s to comply with interface

also updated the naming

* fmt

* add unit testing for `config.rs`

* add `PartialEq` to `SpanContext`

* correct logic from `text_map_propagator.rs`

logic was wrong in some parts, this was discovered through unit tests

* add unit tests for `DatadogCompositePropagator`

also corrected some logic
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.

2 participants