Skip to content

feat(bigquery): add HTTP response attribute tracing#12109

Merged
ldetmer merged 7 commits intomainfrom
http-response-attributes
Mar 19, 2026
Merged

feat(bigquery): add HTTP response attribute tracing#12109
ldetmer merged 7 commits intomainfrom
http-response-attributes

Conversation

@ldetmer
Copy link
Contributor

@ldetmer ldetmer commented Mar 18, 2026

This adds generic HTTP response attribute capture via open telemetry to BigQuery. Error attributes are not included in this PR.

example success POST
example failed GET

@ldetmer ldetmer marked this pull request as ready for review March 18, 2026 18:16
@ldetmer ldetmer requested review from a team as code owners March 18, 2026 18:16
@ldetmer ldetmer changed the title feat: add HTTP response attribute tracing feat(bigquery): add HTTP response attribute tracing Mar 18, 2026

static void addRequestBodySizeToSpan(HttpRequest request, Span span) {
try {
span.setAttribute(HTTP_REQUEST_BODY_SIZE, request.getContent().getLength());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think some NullPointerExceptions may be expected, as some request.getContent() is expected to be null (i.e. requests without a body). Would it be better to add an explicit null check, so that only real exceptions are caught?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

AttributeKey.longKey("http.response.status_code");
public static final AttributeKey<Long> HTTP_REQUEST_RESEND_COUNT =
AttributeKey.longKey("http.request.resend_count");
public static final AttributeKey<Long> HTTP_REQUEST_BODY_SIZE =
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed HTTP_REQUEST_BODY_SIZE is not populated in this PR. Is that WAI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is populated see, but note:

  1. we only add it from the response as its empty until execution
  2. it will only show up in POST requests

HttpResponseInterceptor originalInterceptor = request.getResponseInterceptor();
request.setResponseInterceptor(
response -> {
addCommonResponseAttributesToSpan(request, response, span);
Copy link
Contributor

Choose a reason for hiding this comment

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

A general questions regarding the interceptors. Do we know if they runs on the same thread or a different thread? If it is a different thread, there might be a chance that the Span is already ended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It runs on the same thread. The client uses a syncronous execute call from apiary. So it will always get intercepted, and processed before it returns to the client.


static void addRequestBodySizeToSpan(HttpRequest request, Span span) {
try {
if (request.getContent() != null) {
Copy link
Member

@lqiu96 lqiu96 Mar 19, 2026

Choose a reason for hiding this comment

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

qq, if there is no content, I assume that would be when we are not sending a request body? For those case, would it be preferred to not record anything or set the body size to 0?

I'm guessing BigQuery probably doesn't really have any of those APIs where there is no body (wondering as I'm assuming this logic will probably be migrated to Gax)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for checking. I confirmed that we should omit in the case of a GET request (where content is null), encoded content (where we can't get accurate information on the actual size sent as that happens in the the transport layer) and in case of an error.

I was missing the use case for encoded content, so added that check!

Copy link
Member

@lqiu96 lqiu96 left a comment

Choose a reason for hiding this comment

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

LGTM, but I'm not the most familiar with tracing so I'll defer approval to the others. logic to record the body and status code looks fine

@ldetmer ldetmer requested review from blakeli0 and jinseopkim0 March 19, 2026 16:19
span.getAttributes().get(BigQueryTelemetryTracer.RPC_SYSTEM_NAME));
assertEquals(
responseCode,
span.getAttributes().get(HttpTracingRequestInitializer.HTTP_RESPONSE_STATUS_CODE));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is existing behavior, we can do it as a separate PR. But we should consider test one behavior (attribute) at a time. See Test One Thing At A Time and Keep Tests Focused.

@ldetmer ldetmer enabled auto-merge (squash) March 19, 2026 19:52
@ldetmer ldetmer merged commit f8a13e5 into main Mar 19, 2026
55 of 56 checks passed
@ldetmer ldetmer deleted the http-response-attributes branch March 19, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants