Skip to content

fix: End BIDI gRPC transactions on response send instead of stream close#2758

Open
nlakhera wants to merge 1 commit intonewrelic:mainfrom
nlakhera:fix/bidi-grpc-transaction-duration
Open

fix: End BIDI gRPC transactions on response send instead of stream close#2758
nlakhera wants to merge 1 commit intonewrelic:mainfrom
nlakhera:fix/bidi-grpc-transaction-duration

Conversation

@nlakhera
Copy link

@nlakhera nlakhera commented Feb 19, 2026

Overview

For bidirectional streaming gRPC calls, transactions now end when the first response is sent rather than when the stream closes. This provides accurate transaction durations (typically 2-10ms) instead of measuring the entire stream lifecycle (30-180 seconds).

Changes:

  • ServerImpl_Instrumentation: Detect BIDI streaming and mark streams
  • ServerStream_Instrumentation: Instrument writeMessage() to expire token after first response is sent
  • Only affects BIDI_STREAMING, other gRPC types unchanged

Fixes issue where transaction duration included stream idle time and upstream service latency, making performance monitoring ineffective.

Related: Internal discussion on gRPC transaction instrumentation

Before contributing, please read our contributing guidelines and code of conduct.

Related Github Issue

Include a link to the related GitHub issue, if applicable

Testing

The agent includes a suite of tests which should be used to
verify your changes don't break existing functionality. These tests will run with
Github Actions when a pull request is made. More details on running the tests locally can be found
here,

Checks

  • Your contributions are backwards compatible with relevant frameworks and APIs.
  • Your code does not contain any breaking changes. Otherwise please describe.
  • Your code does not introduce any new dependencies. Otherwise please describe.

For bidirectional streaming gRPC calls, transactions now end when the
first response is sent rather than when the stream closes. This provides
accurate transaction durations (typically 2-10ms) instead of measuring
the entire stream lifecycle (30-180 seconds).

Changes:
- ServerImpl_Instrumentation: Detect BIDI streaming and mark streams
- ServerStream_Instrumentation: Instrument writeMessage() to expire
  token after first response is sent
- Only affects BIDI_STREAMING, other gRPC types unchanged

Fixes issue where transaction duration included stream idle time and
upstream service latency, making performance monitoring ineffective.

Related: Internal discussion on gRPC transaction instrumentation
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants