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

sdk/trace: ParentBased is a decorator #4565

Closed
pellared opened this issue Sep 27, 2023 · 4 comments · Fixed by #4604
Closed

sdk/trace: ParentBased is a decorator #4565

pellared opened this issue Sep 27, 2023 · 4 comments · Fixed by #4604
Labels
area:trace Part of OpenTelemetry tracing documentation Provides helpful information pkg:SDK Related to an SDK package
Milestone

Comments

@pellared
Copy link
Member

From open-telemetry/opentelemetry.io@5847bd3#r128534150

Update the docs and describe ParentBased sampler as a decorator (not composite).

@pellared pellared added documentation Provides helpful information pkg:SDK Related to an SDK package area:trace Part of OpenTelemetry tracing labels Sep 27, 2023
@pellared
Copy link
Member Author

@pellared pellared added the blocked:specification Waiting on clarification of the OpenTelemetry specification before progress can be made label Sep 27, 2023
@pellared
Copy link
Member Author

@MrAlias
Copy link
Contributor

MrAlias commented Sep 27, 2023

Huh? It is literally a decision hierarchy tree that determines what sampler to use.

func (pb parentBased) ShouldSample(p SamplingParameters) SamplingResult {
psc := trace.SpanContextFromContext(p.ParentContext)
if psc.IsValid() {
if psc.IsRemote() {
if psc.IsSampled() {
return pb.config.remoteParentSampled.ShouldSample(p)
}
return pb.config.remoteParentNotSampled.ShouldSample(p)
}
if psc.IsSampled() {
return pb.config.localParentSampled.ShouldSample(p)
}
return pb.config.localParentNotSampled.ShouldSample(p)
}
return pb.root.ShouldSample(p)
}

Also Go is not an object-oriented language, I do not support including object-oriented terms in our descriptions.

@pellared
Copy link
Member Author

I do not support including object-oriented terms in our descriptions

Even though GoF design patterns are coming from object-oriented languages (C++ and Smalltalk), Go is quite close to these languages (at least a lot closer than to functional languages). Even though there are key differences they are not related to the GoF design patterns which can be applied.

PS. I would prefer using a more Go idiomatic term instead but I am not aware if such exist.
PS2. https://go.dev/doc/faq#Is_Go_an_object-oriented_language

yurishkuro pushed a commit to open-telemetry/opentelemetry-specification that referenced this issue Sep 28, 2023
ParentBased sampler is decorator (and not a composite).

> The intent of a composite is to "compose" objects into tree structures
to represent part-whole hierarchies.

> What problems can the Composite design pattern solve? 
> [...]
> A part-whole hierarchy should be represented as tree structure

`ParentBased` does not produce a tree. Composite aims to solve a
different (but kind of similar) problem.



> decorator pattern [...] that allows behavior to be added to an
individual
[object](https://en.wikipedia.org/wiki/Object_(computer_science)),
dynamically, without affecting the behavior of other objects from the
same [class](https://en.wikipedia.org/wiki/Class_(computer_science)).

> What problems can it solve?
> Responsibilities should be added to (and removed from) an object
dynamically at run-time.[5]
>>A flexible alternative to subclassing for extending functionality
should be provided.

The key feature of the `ParentBased` is how it changes the "behavior" of
the wrapped sampler. We decorate the existing sampler so that it handles
the sampling based on the parent's span.

References:
- https://en.wikipedia.org/wiki/Decorator_pattern
- https://en.wikipedia.org/wiki/Composite_pattern
- https://sourcemaking.com/design_patterns/composite
- https://sourcemaking.com/design_patterns/decorator
-
https://stackoverflow.com/questions/2233952/difference-between-the-composite-pattern-and-decorator-pattern

Related issue
open-telemetry/opentelemetry-go#4565
@pellared pellared removed the blocked:specification Waiting on clarification of the OpenTelemetry specification before progress can be made label Oct 11, 2023
@MrAlias MrAlias added this to the v1.20.0 milestone Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:trace Part of OpenTelemetry tracing documentation Provides helpful information pkg:SDK Related to an SDK package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants