Skip to content

Commit 124f9dc

Browse files
beniwohlireakaleekbasepi
authored
handle case when no span is created in GRPC client interceptor (#1740)
* handle case when no span is created in GRPC client interceptor closes #1739 * Migrate Jenkinsfile 2 GH Actions Workflow (#1731) * Migrate Jenkinsfile to GH Actions * Generic naming * Upload junit test and coverage reports on success or on failure * Better naming * Remove cron from packages workflow * Rename all occurences of WEBFRAMEWORK to FRAMEWORK * Add a warning about BaseHTTPMiddleware to Starlette docs (#1735) * Add a warning about BaseHTTPMiddleware to Starlette docs Also switch to using get_client() and make the docs simpler for environment variable configuration. * CHANGELOG * Change `server_url` default to avoid ipv6 ambiguity (#1744) * Change `server_url` default to avoid ipv6 ambiguity * Fix failing test and another minor doc fix * Add service.agent.activation_method to metadata (#1743) * Add activation_method to metadata * Add test * Move activation_method default above start_threads * CHANGELOG * Fix nightly scheduled test (#1747) * Split matrix items into chunks to bypass the 256 limit of matrix items in github actions * cleanup * Add comments * Add update-specs updatcli workflow (#1745) * Add update-specs updatcli workflow * Fix paths * Required Status Check (#1749) * Create single status check that can be set as required * Let windows test runs exit with the correct exit code * Set the exit code * Formatting * fix * More readable jq query * Set status check to success in case it's an only-docs PR (#1753) * Set status check to success in case it's a only-docs PR * Set permissions * fix path patterns * Add comments * Update badge (#1752) * Add dynamic config tag to more supported options (#1750) * Fix sha source (#1754) * update changelog --------- Co-authored-by: Jan Calanog <[email protected]> Co-authored-by: Colton Myers <[email protected]> Co-authored-by: Jan Calanog <[email protected]>
1 parent f933ac0 commit 124f9dc

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ endif::[]
4343
4444
* Small fix to underlying Starlette logic to prevent duplicate Client objects {pull}1735[#1735]
4545
* Change `server_url` default to `http://127.0.0.1:8200` to avoid ipv6 ambiguity {pull}1744[#1744]
46-
46+
* Fix an issue in GRPC instrumentation with unsampled transactions {pull}1740[#1740]
4747
4848
4949
[[release-notes-6.x]]

elasticapm/contrib/grpc/client_interceptor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def intercept_unary_unary(self, continuation, client_call_details, request):
9494
with elasticapm.capture_span(
9595
client_call_details.method, span_type="external", span_subtype="grpc", extra=self._context.copy(), leaf=True
9696
) as span:
97+
if not span:
98+
return continuation(client_call_details, request)
9799
client_call_details = self.attach_traceparent(client_call_details, span)
98100
try:
99101
response = continuation(client_call_details, request)

tests/contrib/grpc/grpc_client_tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ def test_grpc_client_server_exception(instrument, sending_elasticapm_client, grp
178178
assert error["transaction_id"] == server_transactions[0]["id"]
179179

180180

181+
def test_grpc_client_unsampled_transaction(instrument, sending_elasticapm_client, grpc_client_and_server_url):
182+
grpc_client, grpc_server_url = grpc_client_and_server_url
183+
grpc_server_host, grpc_server_port = grpc_server_url.split(":")
184+
transaction = sending_elasticapm_client.begin_transaction("request")
185+
transaction.is_sampled = False
186+
parsed_url = urllib.parse.urlparse(sending_elasticapm_client.httpserver.url)
187+
response = grpc_client.GetServerResponse(Message(message="foo"))
188+
transaction.is_sampled = True
189+
sending_elasticapm_client.end_transaction("grpc-test")
190+
payloads = sending_elasticapm_client.httpserver.payloads
191+
for i in range(1000):
192+
if len(sending_elasticapm_client.httpserver.payloads) > 1:
193+
break
194+
time.sleep(0.01)
195+
transaction_data = payloads[1][1]["transaction"]
196+
assert transaction_data["span_count"]["started"] == 0
197+
198+
181199
def extract_events_from_payload(service_name, payloads):
182200
payloads = [
183201
payload for payload in payloads if payload and payload[0]["metadata"]["service"]["name"] == service_name

0 commit comments

Comments
 (0)