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

NH-52516: return false if span is not sampled or invalid #59

Merged
merged 5 commits into from
Aug 17, 2023

Conversation

xuan-cao-swi
Copy link
Contributor

  1. Change noop string to 99-00000000000000000000000000000000-0000000000000000-00 to separate from start span 00-00000000000000000000000000000000-0000000000000000-00
  2. use baggage stored span to determine valid and sampled (not sure if this is correct behavior)

@xuan-cao-swi xuan-cao-swi marked this pull request as ready for review August 11, 2023 16:59
@xuan-cao-swi xuan-cao-swi requested a review from a team August 11, 2023 16:59
@swi-jared
Copy link
Contributor

I don't think this is right. We should still allow a custom transaction name if not sampled (i.e. record only), so that it populates metrics.

test/api/set_transaction_name_test.rb Fixed Show fixed Hide fixed
test/api/set_transaction_name_test.rb Fixed Show fixed Hide fixed
test/api/set_transaction_name_test.rb Fixed Show fixed Hide fixed
test/api/set_transaction_name_test.rb Fixed Show fixed Hide fixed
test/api/set_transaction_name_test.rb Fixed Show fixed Hide fixed
test/api/set_transaction_name_test.rb Fixed Show fixed Hide fixed
@@ -65,9 +65,9 @@ def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:
new_trace_state = calculate_trace_state(liboboe_decision,parent_span_context,xtraceoptions)
SolarWindsAPM.logger.debug {"[#{self.class}/#{__method__}] new_trace_state: #{new_trace_state.inspect}"}

new_attributes = calculate_attributes(attributes,liboboe_decision,new_trace_state,parent_span_context,xtraceoptions)
new_attributes = otel_sampled?(otel_decision)? calculate_attributes(attributes,liboboe_decision,new_trace_state,parent_span_context,xtraceoptions) : nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

related to sampler refactor. instead of checking is otel-type sampled in calculate_attributes; just check in function should_sample?

@@ -330,6 +325,10 @@ def sw_from_span_and_decision(parent_span_context, decision)
trace_flag = Transformer.trace_flags_from_boolean(decision["do_sample"])
Transformer.sw_from_span_and_decision(parent_span_context.hex_span_id, trace_flag)
end

def otel_sampled?(otel_decision)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

related to sampler refactor.

it 'test_calculate_attributes should return nil' do
attributes = @sampler.send(:calculate_attributes, "tmp_span", @attributes_dict, @decision, @tracestate, @parent_context)
assert_nil(attributes)
it 'test_calculate_attributes' do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

related to sampler refactor.

@xuan-cao-swi
Copy link
Contributor Author

I don't think this is right. We should still allow a custom transaction name if not sampled (i.e. record only), so that it populates metrics.

Thanks, I rewrote the part that will still set transaction name while it's not sampled, but the function will return false.

SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Solarwinds processor is missing. Set transaction name failed."}
status = false
else
entry_trace_id = ::OpenTelemetry::Baggage.value(::SolarWindsAPM::Constants::INTL_SWO_CURRENT_TRACE_ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

A future improvement could be using a single Baggage key to hold the trace info

entry_trace_id = ::OpenTelemetry::Baggage.value(::SolarWindsAPM::Constants::INTL_SWO_CURRENT_TRACE_ID)
entry_span_id = ::OpenTelemetry::Baggage.value(::SolarWindsAPM::Constants::INTL_SWO_CURRENT_SPAN_ID)
status = false if entry_trace_id.nil? || entry_span_id.nil? || trace_flags.nil?
status = false if entry_trace_id == '0'*32 || entry_span_id == '0'*16 || trace_flags == '00' # not sampled
Copy link
Contributor

Choose a reason for hiding this comment

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

If you used a single baggage key, this check could also be simplified

@xuan-cao-swi xuan-cao-swi merged commit 996a8b0 into main Aug 17, 2023
12 checks passed
@xuan-cao-swi xuan-cao-swi deleted the NH-52516 branch August 17, 2023 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants