Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Update gRPC client interceptor to use tracer from execution context#157

Merged
liyanhui1228 merged 2 commits intocensus-instrumentation:masterfrom
wkiser:grpc_client
Apr 19, 2018
Merged

Update gRPC client interceptor to use tracer from execution context#157
liyanhui1228 merged 2 commits intocensus-instrumentation:masterfrom
wkiser:grpc_client

Conversation

@wkiser
Copy link
Copy Markdown
Contributor

@wkiser wkiser commented Apr 18, 2018

Ran into this when calling a gRPC client from within a flask endpoint handler. The tracer was set once when the interceptor was created and never updated afterwards.

grpc.StreamUnaryClientInterceptor,
grpc.StreamStreamClientInterceptor):

def __init__(self, tracer=None, host_port=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please keep the tracer parameter here since we also need to handle the case that sharing the tracer between threads. See #133, which was addressing issue #134 caused by tracer not shared between threads when instrumenting google cloud client library calls.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do!

Would the current integration in google_cloud_clientlibs be facing this same issue if it is passing in the tracer at initialization time? For instance, if a Flask endpoint calls a gcloud service, would the gcloud span be nested under the flask one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix! Yes I have opened a new issue #161, I'll look into and work on it later this week.

tracer.add_attribute_to_current_span(
attribute_key=attributes_helper.GRPC_ATTRIBUTES.get(GRPC_METHOD),
attribute_value=str(client_call_details.method))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably add code below to here to update the tracer in execution context:

execution_context.set_opencensus_tracer(self._tracer)
execution_context.set_current_span(span)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants