Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support kind keyword in Opencensus #19548

Merged
merged 9 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/core/azure-core-tracing-opencensus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Release History

## 1.0.0b8 (Unreleased)

- Fix for supporting `kind` keyword while instantiating the span.

## 1.0.0b7 (2021-04-08)

- `Link` and `SpanKind` can now be added while creating the span instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import Dict, Optional, Union, Callable, Sequence
from typing import Dict, Optional, Union, Callable, Sequence, Any

from azure.core.pipeline.transport import HttpRequest, HttpResponse
AttributeValue = Union[
Expand Down Expand Up @@ -61,7 +61,21 @@ def __init__(self, span=None, name="span", **kwargs):
:paramtype links: list[~azure.core.tracing.Link]
"""
tracer = self.get_current_tracer()
value = kwargs.pop('kind', None)
kind = (
OpenCensusSpanKind.CLIENT if value == SpanKind.CLIENT else
OpenCensusSpanKind.CLIENT if value == SpanKind.PRODUCER else # No producer in opencensus
OpenCensusSpanKind.SERVER if value == SpanKind.SERVER else
OpenCensusSpanKind.CLIENT if value == SpanKind.CONSUMER else # No consumer in opencensus
OpenCensusSpanKind.UNSPECIFIED if value == SpanKind.INTERNAL else # No internal in opencensus
OpenCensusSpanKind.UNSPECIFIED if value == SpanKind.UNSPECIFIED else
None
) # type: SpanKind
if value and kind is None:
raise ValueError("Kind {} is not supported in OpenCensus".format(value))
self._span_instance = span or tracer.start_span(name=name, **kwargs)
if kind is not None:
self._span_instance.span_kind = kind
Copy link
Member

Choose a reason for hiding this comment

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

No handler for links?

Copy link
Member

Choose a reason for hiding this comment

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

Or it is handled in tracer.start_span?


@property
def span_instance(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def test_add_attribute(self):
assert wrapped_class.span_instance.attributes["test"] == "test2"
assert parent.attributes["test"] == "test2"

def test_passing_kind_in_ctor(self):
with ContextHelper() as ctx:
trace = tracer_module.Tracer(sampler=AlwaysOnSampler())
parent = trace.start_span()
wrapped_class = OpenCensusSpan(kind=SpanKind.CLIENT)
assert wrapped_class.kind == SpanKind.CLIENT

def test_set_http_attributes(self):
with ContextHelper():
trace = tracer_module.Tracer(sampler=AlwaysOnSampler())
Expand Down