opencensus-python icon indicating copy to clipboard operation
opencensus-python copied to clipboard

google_cloud_clientlib extension does not trace datastore

Open davidn opened this issue 4 years ago • 2 comments

Steps to reproduce.

from opencensus.trace import config_integration, execution_context, tracer, samplers, print_exporter
from google.cloud import datastore

exporter = print_exporter.PrintExporter()
sampler = samplers.AlwaysOnSampler()
trace = tracer.Tracer(exporter=exporter, sampler=sampler)

config_integration.trace_integrations(['google_cloud_clientlibs'], tracer=trace)

client = datastore.Client()
client.get(client.key('Thing', 123))
with trace.span(name='after'):
    pass

What is the expected behavior? A span for datastore and a span for "after"

What is the actual behavior?

[SpanData(name='/token', context=SpanContext(trace_id=8d484c0f5daba1be1384c4793f599557, span_id=None, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='14baf45ff9639235', parent_span_id=None, attributes=BoundedDict({'component': 'HTTP', 'http.host': 'oauth2.googleapis.com', 'http.method': 'POST', 'http.path': '/token', 'http.url': 'https://oauth2.googleapis.com/token', 'http.status_code': 200}, maxlen=32), start_time='2021-06-04T17:14:01.560051Z', end_time='2021-06-04T17:14:01.958095Z', child_span_count=0, stack_trace=None, annotations=BoundedList([], maxlen=32), message_events=BoundedList([], maxlen=128), links=BoundedList([], maxlen=32), status=<opencensus.trace.status.Status object at 0x7f4cee7121d0>, same_process_as_parent_span=None, span_kind=2)]
[SpanData(name='after', context=SpanContext(trace_id=8d484c0f5daba1be1384c4793f599557, span_id=None, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='c9c5cab63ef68d26', parent_span_id=None, attributes=BoundedDict({}, maxlen=32), start_time='2021-06-04T17:14:02.053765Z', end_time='2021-06-04T17:14:02.053785Z', child_span_count=0, stack_trace=None, annotations=BoundedList([], maxlen=32), message_events=BoundedList([], maxlen=128), links=BoundedList([], maxlen=32), status=<opencensus.trace.status.Status object at 0x7f4cee6f8e80>, same_process_as_parent_span=None, span_kind=0)]

davidn avatar Jun 04 '21 17:06 davidn

Was this with gRPC or HTTP? What version of the datastore package?

aabmass avatar Jun 18 '21 16:06 aabmass

Was this with gRPC or HTTP?

I believe this issue only occurs with gRPC. If I run the code snippit above with GOOGLE_CLOUD_DISABLE_GRPC=true in the environment I get the expected behavior:

[SpanData(name='/token', context=SpanContext(trace_id=a8ace3b354a381183b216b1241d0384a, span_id=None, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='d9751cfc83f0f1c6', parent_span_id=None, attributes=BoundedDict({'component': 'HTTP', 'http.host': 'oauth2.googleapis.com', 'http.method': 'POST', 'http.path': '/token', 'http.url': 'https://oauth2.googleapis.com/token', 'http.status_code': 200}, maxlen=32), start_time='2021-06-20T18:26:08.379560Z', end_time='2021-06-20T18:26:08.523049Z', child_span_count=0, stack_trace=None, annotations=BoundedList([], maxlen=32), message_events=BoundedList([], maxlen=128), links=BoundedList([], maxlen=32), status=<opencensus.trace.status.Status object at 0x7f38ca6034a8>, same_process_as_parent_span=None, span_kind=2)]
[SpanData(name='/v1/projects/filter-feed:lookup', context=SpanContext(trace_id=a8ace3b354a381183b216b1241d0384a, span_id=None, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='4d89209f66d3c595', parent_span_id=None, attributes=BoundedDict({'component': 'HTTP', 'http.host': 'datastore.googleapis.com', 'http.method': 'POST', 'http.path': '/v1/projects/filter-feed:lookup', 'http.url': 'https://datastore.googleapis.com/v1/projects/filter-feed:lookup', 'http.status_code': 200}, maxlen=32), start_time='2021-06-20T18:26:08.523585Z', end_time='2021-06-20T18:26:08.726157Z', child_span_count=0, stack_trace=None, annotations=BoundedList([], maxlen=32), message_events=BoundedList([], maxlen=128), links=BoundedList([], maxlen=32), status=<opencensus.trace.status.Status object at 0x7f38ca603518>, same_process_as_parent_span=None, span_kind=2)]
[SpanData(name='after', context=SpanContext(trace_id=a8ace3b354a381183b216b1241d0384a, span_id=None, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='9deff40e1c44fc8f', parent_span_id=None, attributes=BoundedDict({}, maxlen=32), start_time='2021-06-20T18:26:08.726591Z', end_time='2021-06-20T18:26:08.726608Z', child_span_count=0, stack_trace=None, annotations=BoundedList([], maxlen=32), message_events=BoundedList([], maxlen=128), links=BoundedList([], maxlen=32), status=<opencensus.trace.status.Status object at 0x7f38ca603390>, same_process_as_parent_span=None, span_kind=0)]

What version of the datastore package?

here is selected output from pip freeze (this probably includes libs that are installed because of other dev I've been doing):

absl-py==0.12.0
backcall==0.2.0
cachetools==4.2.2
certifi==2021.5.30
chardet==4.0.0
google-api-core==1.29.0
google-api-python-client==2.7.0
google-auth==1.30.1
google-auth-httplib2==0.1.0
google-cloud-core==1.6.0
google-cloud-datastore==1.15.3
google-cloud-error-reporting==1.1.2
google-cloud-logging==2.3.1
google-cloud-monitoring==0.36.0
google-cloud-ndb==1.8.0
google-cloud-trace==0.24.0
google-python-cloud-debugger==2.17
googleapis-common-protos==1.53.0
grpcio==1.38.0
httplib2==0.19.1
idna==2.10
importlab==0.6.1
importlib-metadata==4.5.0
opencensus==0.7.13
opencensus-context==0.1.2
opencensus-ext-flask==0.7.5
opencensus-ext-google-cloud-clientlibs==0.1.2
opencensus-ext-grpc==0.7.2
opencensus-ext-logging==0.1.0
opencensus-ext-requests==0.7.5
opencensus-ext-stackdriver==0.7.4
proto-plus==1.18.1
protobuf==3.17.2
ptyprocess==0.7.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
requests==2.25.1
requests-mock==1.9.3
urllib3==1.26.5

davidn avatar Jun 20 '21 18:06 davidn