Skip to content

NH-53473 benchmark always sample #248

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tammy-baylis-swi
Copy link
Contributor

Do NOT merge.

Comment on lines +174 to +195
# def test_scenario_4_not_sampled(self):
# """
# Scenario #4, NOT sampled:
# 1. Decision to NOT sample is continued at service entry span (mocked). This is
# not the root span because it continues an existing OTel context.
# 2. traceparent and tracestate headers in the request to the test app are
# injected into the outgoing request (done by OTel TraceContextTextMapPropagator).
# 3. No spans are exported.
# """
# trace_id = "11112222333344445555666677778888"
# span_id = "1000100010001000"
# trace_flags = "00"
# traceparent = "00-{}-{}-{}".format(trace_id, span_id, trace_flags)
# tracestate_span = "e000baa4e000baa4"
# tracestate = "sw={}-{}".format(tracestate_span, trace_flags)

# Use in-process test app client and mock to propagate context
# and create in-memory trace
resp = None
# liboboe mocked to guarantee return of "do_sample" (2nd arg)
mock_decision = mock.Mock(
return_value=(1, 0, 3, 4, 5.0, 6.0, 1, 0, "ok", "ok", 0)
)
with mock.patch(
target="solarwinds_apm.extension.oboe.Context.getDecisions",
new=mock_decision,
):
# Request to instrumented app with headers
resp = self.client.get(
"/test_trace/",
headers={
"traceparent": traceparent,
"tracestate": tracestate,
"some-header": "some-value"
}
)
resp_json = json.loads(resp.data)
# # Use in-process test app client and mock to propagate context
# # and create in-memory trace
# resp = None
# # liboboe mocked to guarantee return of "do_sample" (2nd arg)
# mock_decision = mock.Mock(
# return_value=(1, 0, 3, 4, 5.0, 6.0, 1, 0, "ok", "ok", 0)

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
Comment on lines +213 to +221
# try:
# assert resp_json["incoming-headers"]["some-header"] == "some-value"
# except KeyError as e:
# self.fail("KeyError was raised at incoming-headers check: {}".format(e))

# Verify trace context injected into test app's outgoing postman-echo call
# (added to Flask app's response data) includes:
# - traceparent with a trace_id, trace_flags from original request
# - tracestate from original request
assert "traceparent" in resp_json
_TRACEPARENT_HEADER_FORMAT = (
"^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$"
)
_TRACEPARENT_HEADER_FORMAT_RE = re.compile(_TRACEPARENT_HEADER_FORMAT)
traceparent_re_result = re.search(
_TRACEPARENT_HEADER_FORMAT_RE,
resp_json["traceparent"],
)
new_trace_id = traceparent_re_result.group(2)
assert new_trace_id is not None
assert new_trace_id == trace_id
new_span_id = traceparent_re_result.group(3)
assert new_span_id is not None
new_trace_flags = traceparent_re_result.group(4)
assert new_trace_flags == trace_flags
# # Verify trace context injected into test app's outgoing postman-echo call
# # (added to Flask app's response data) includes:
# # - traceparent with a trace_id, trace_flags from original request
# # - tracestate from original request

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
Comment on lines +246 to +261
# try:
# assert resp_json["incoming-headers"]["traceparent"] == traceparent
# assert new_trace_id in resp_json["incoming-headers"]["traceparent"]
# assert new_span_id not in resp_json["incoming-headers"]["traceparent"]
# assert new_trace_flags in resp_json["incoming-headers"]["traceparent"]

assert resp_json["incoming-headers"]["tracestate"] == tracestate
assert "sw=" in resp_json["incoming-headers"]["tracestate"]
assert new_span_id not in resp_json["incoming-headers"]["tracestate"]
assert new_trace_flags in resp_json["incoming-headers"]["tracestate"]
except KeyError as e:
self.fail("KeyError was raised at continue trace check: {}".format(e))
# assert resp_json["incoming-headers"]["tracestate"] == tracestate
# assert "sw=" in resp_json["incoming-headers"]["tracestate"]
# assert new_span_id not in resp_json["incoming-headers"]["tracestate"]
# assert new_trace_flags in resp_json["incoming-headers"]["tracestate"]
# except KeyError as e:
# self.fail("KeyError was raised at continue trace check: {}".format(e))

# Verify x-trace response header has same trace_id
# though it will have different span ID because of Flask
# app's outgoing request
assert "x-trace" in resp.headers
assert new_trace_id in resp.headers["x-trace"]
# # Verify x-trace response header has same trace_id
# # though it will have different span ID because of Flask
# # app's outgoing request

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
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.

1 participant