Skip to content

Commit 0171e9f

Browse files
ckoehnbasepi
andauthored
Fix max span handling in gRPC client interceptor (#1861)
Co-authored-by: Colton Myers <[email protected]>
1 parent 01d71bb commit 0171e9f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

CHANGELOG.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ endif::[]
3737
==== Features
3838
* Add `server_ca_cert_file` option to provide custom CA certificate {pull}1852[#1852]
3939
40-
// [float]
41-
// ===== Bug fixes
42-
40+
[float]
41+
===== Bug fixes
42+
* Fix a bug in the GRPC instrumentation when reaching the maximum amount of spans per transaction {pull}1861[#1861]
4343
4444
[[release-notes-6.x]]
4545
=== Python Agent version 6.x

elasticapm/contrib/grpc/client_interceptor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import elasticapm
3737
from elasticapm.conf import constants
38-
from elasticapm.traces import Span
38+
from elasticapm.traces import DroppedSpan, SpanType
3939
from elasticapm.utils import default_ports
4040

4141

@@ -193,8 +193,8 @@ def intercept_unary_unary(self, continuation, client_call_details, request):
193193
# Future interface, though it may not.
194194
# """
195195

196-
def attach_traceparent(self, client_call_details: _ClientCallDetails, span: Span):
197-
if not span.transaction:
196+
def attach_traceparent(self, client_call_details: _ClientCallDetails, span: SpanType) -> _ClientCallDetails:
197+
if isinstance(span, DroppedSpan) or not span.transaction:
198198
return client_call_details
199199
meta = list(client_call_details.metadata) if client_call_details.metadata else []
200200
if constants.TRACEPARENT_HEADER_NAME not in meta:

tests/contrib/grpc/grpc_client_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ def test_grpc_client_unsampled_transaction(instrument, sending_elasticapm_client
219219
assert len(payloads) == 1 # only the server_version request
220220

221221

222+
@pytest.mark.parametrize("sending_elasticapm_client", [{"transaction_max_spans": 1}], indirect=True)
223+
def test_grpc_client_max_spans(instrument, sending_elasticapm_client, grpc_client_and_server_url):
224+
grpc_client, _ = grpc_client_and_server_url
225+
transaction = sending_elasticapm_client.begin_transaction("request")
226+
_ = grpc_client.GetServerResponse(Message(message="foo"))
227+
_ = grpc_client.GetServerResponse(Message(message="bar"))
228+
sending_elasticapm_client.end_transaction("grpc-test")
229+
assert transaction.dropped_spans == 1
230+
231+
222232
def extract_events_from_payload(service_name, payloads):
223233
payloads = [
224234
payload for payload in payloads if payload and payload[0]["metadata"]["service"]["name"] == service_name

0 commit comments

Comments
 (0)