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

Trace SDK: support span limits #481

Closed
iRevive opened this issue Feb 6, 2024 · 2 comments · Fixed by #719
Closed

Trace SDK: support span limits #481

iRevive opened this issue Feb 6, 2024 · 2 comments · Fixed by #719
Assignees
Labels
help wanted Extra attention is needed sdk module Features and improvements to the sdk module tracing Improvements to tracing module

Comments

@iRevive
Copy link
Contributor

iRevive commented Feb 6, 2024

Reference Link
Spec https://opentelemetry.io/docs/specs/otel/trace/sdk/#span-limits
Java implementation SpanLimits.java

The purpose is to keep the number of a) Attributes, b) Links, and c) Events under the configured limit.
Aside from dropping the overflowing ones, we should also track how many have been dropped.

1) Design SpanLimits and SpanLimits.Builder

There is a draft implementation which can be helpful.

Tests should include the discipline's HashTest. The example - RetryPolicySuite.

2) Design a generic collection container with fixed bounds

OpenTelemetry Java, for example, keeps track of dropped attributes right into the span's (or event's or link's) state.
The example, and the simplified version:

class SpanLink {
  def attributes: Attributes
  def totalAttributesCount: Int // how many attributes were submitted to be recorded
  def droppedAttribuesCount: Int = totalAttributesCount - attributes.size
}

To keep track of dropped attributes, links, or events, we can use the generic container:

sealed trait Bounded[A, C <: immutable.Iterable[x]] {
  def limit: Int // the max size
  def dropped: Int // how many elements have been dropped
  def elements: C
  def append(a: A): Bounded[A, C]
}

object Bounded {
  def attributes(limit: Int): Bounded[Attribute[_], Attributes]
  def links(limit: Int): Bounded[LinkData, Vector[LinkData]]
  def events(limit: Int): Bounded[EventData, Vector[EventData]]
}

We may bikeshed the name 🙂 e.g: Bounded, Fixed, Limited, etc.

3) Use Bounded container in the SDK implementation:

For example - https://github.com/typelevel/otel4s/pull/325/files#diff-b00a1cedc0fb0cc94255f20aea84be95187a261e07f8ad033de3375f70d43f8cR151-R160.

4) Add the number of dropped elements to the proto encoders

The SpansProtoEncoder. The proto models already have the properties and we need to populate them.

The change would be similar to:

SpanProto.Link(
  traceId = ByteString.copyFrom(data.spanContext.traceId.toArray),
  spanId = ByteString.copyFrom(data.spanContext.spanId.toArray),
  traceState = traceState,
- attributes = ProtoEncoder.encode(data.attributes),
+ attributes = ProtoEncoder.encode(data.attributes.elements),
+ droppedAttributesCount = data.attributes.dropped
)

5) Implement SpanLimitsAutoConfigure

We need this to autoconfigure the SpanLimits using configuration properties.

The example - TelemetryResourceAutoConfigure.

The configuration options - https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#span-limits.

@iRevive iRevive added help wanted Extra attention is needed sdk module Features and improvements to the sdk module labels Feb 6, 2024
@iRevive iRevive added the tracing Improvements to tracing module label Apr 20, 2024
@bio-aeon
Copy link
Contributor

Hi. Can I try to implement this or is it already being done by someone?

@iRevive
Copy link
Contributor Author

iRevive commented Jul 24, 2024

Hey @bio-aeon, you can work on it. Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed sdk module Features and improvements to the sdk module tracing Improvements to tracing module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants