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

Ignore Links with invalid span context #735

Closed
fbogsany opened this issue Apr 30, 2021 · 0 comments · Fixed by #888
Closed

Ignore Links with invalid span context #735

fbogsany opened this issue Apr 30, 2021 · 0 comments · Fixed by #888
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed spec-compliance Required for OpenTelemetry spec compliance
Milestone

Comments

@fbogsany
Copy link
Contributor

See open-telemetry/opentelemetry-specification#1492.

In the following code we should check that the links each have a valid span context, and remove any with an invalid span context.

def trim_links(links, max_links_count, max_attributes_per_link) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# Fast path (likely) common cases.
return nil if links.nil?
if links.size <= max_links_count &&
links.all? { |link| link.attributes.size <= max_attributes_per_link && Internal.valid_attributes?(link.attributes) }
return links.frozen? ? links : links.clone.freeze
end
# Slow path: trim attributes for each Link.
links.last(max_links_count).map! do |link|
attrs = Hash[link.attributes] # link.attributes is frozen, so we need an unfrozen copy to adjust.
attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
excess = attrs.size - max_attributes_per_link
excess.times { attrs.shift } if excess.positive?
OpenTelemetry::Trace::Link.new(link.span_context, attrs)
end.freeze
end

@fbogsany fbogsany added this to the Tracing v1.0 milestone May 4, 2021
@mwear mwear added good first issue Good for newcomers help wanted Extra attention is needed labels Jun 8, 2021
@mwear mwear added the spec-compliance Required for OpenTelemetry spec compliance label Jul 13, 2021
@robertlaurin robertlaurin self-assigned this Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed spec-compliance Required for OpenTelemetry spec compliance
Projects
None yet
3 participants