From 05001f260e03c67092e24d54d9591af8f18271b4 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 3 May 2021 21:10:33 -0700 Subject: [PATCH 1/9] Increase dependency --- sdk/core/azure-core-tracing-opencensus/setup.py | 2 +- sdk/core/azure-core-tracing-opentelemetry/setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/core/azure-core-tracing-opencensus/setup.py b/sdk/core/azure-core-tracing-opencensus/setup.py index 7ab9fb4027cb..09380d0dc9f5 100644 --- a/sdk/core/azure-core-tracing-opencensus/setup.py +++ b/sdk/core/azure-core-tracing-opencensus/setup.py @@ -61,7 +61,7 @@ 'opencensus>=0.6.0', 'opencensus-ext-azure>=0.3.1', 'opencensus-ext-threading', - 'azure-core<2.0.0,>=1.0.0', + 'azure-core<2.0.0,>=1.14.0', ], extras_require={ ":python_version<'3.5'": ['typing'], diff --git a/sdk/core/azure-core-tracing-opentelemetry/setup.py b/sdk/core/azure-core-tracing-opentelemetry/setup.py index 65a2fc8216e8..2cf850cf7567 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/setup.py +++ b/sdk/core/azure-core-tracing-opentelemetry/setup.py @@ -57,7 +57,7 @@ python_requires=">=3.6.0", install_requires=[ 'opentelemetry-api<2.0.0,>=1.0.0', - 'azure-core<2.0.0,>=1.13.0', + 'azure-core<2.0.0,>=1.14.0', ], extras_require={ ":python_version<'3.5'": ['typing'], From cdfd3c7b37e8e61a562760e66f2c340f5a59bec7 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 3 May 2021 21:26:34 -0700 Subject: [PATCH 2/9] shared --- shared_requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared_requirements.txt b/shared_requirements.txt index 4a7fb37fdfc4..cffd80132adc 100644 --- a/shared_requirements.txt +++ b/shared_requirements.txt @@ -127,8 +127,8 @@ pyjwt>=1.7.1 #override azure azure-keyvault~=1.0 #override azure-mgmt-core azure-core<2.0.0,>=1.13.0 #override azure-containerregistry azure-core>=1.4.0,<2.0.0 -#override azure-core-tracing-opencensus azure-core<2.0.0,>=1.0.0 -#override azure-core-tracing-opentelemetry azure-core<2.0.0,>=1.13.0 +#override azure-core-tracing-opencensus azure-core<2.0.0,>=1.14.0 +#override azure-core-tracing-opentelemetry azure-core<2.0.0,>=1.14.0 #override azure-cosmos azure-core<2.0.0,>=1.0.0 #override azure-data-tables azure-core<2.0.0,>=1.13.0 #override azure-eventhub azure-core<2.0.0,>=1.13.0 From 85982608347a6134ef7c2b62c59801f37a46bfea Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 3 May 2021 22:25:57 -0700 Subject: [PATCH 3/9] update tests --- .../tests/test_tracing_implementations.py | 3 ++- .../tests/test_tracing_implementations.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py b/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py index ffdbb8b58a3b..7d77c5521e3b 100644 --- a/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py +++ b/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py @@ -132,7 +132,7 @@ def test_add_attribute(self): def test_set_http_attributes(self): with ContextHelper(): trace = tracer_module.Tracer(sampler=AlwaysOnSampler()) - parent = trace.start_span() + parent = trace.start_span(span_kind=OpenCensusSpanKind.CLIENT) wrapped_class = OpenCensusSpan(span=parent) request = mock.Mock() setattr(request, "method", "GET") @@ -141,6 +141,7 @@ def test_set_http_attributes(self): setattr(request, "headers", {}) setattr(response, "status_code", 200) wrapped_class.set_http_attributes(request) + assert wrapped_class.span_instance.kind == OpenCensusSpanKind.CLIENT assert wrapped_class.span_instance.attributes.get("http.method") == request.method assert wrapped_class.span_instance.attributes.get("component") == "http" assert wrapped_class.span_instance.attributes.get("http.url") == request.url diff --git a/sdk/core/azure-core-tracing-opentelemetry/tests/test_tracing_implementations.py b/sdk/core/azure-core-tracing-opentelemetry/tests/test_tracing_implementations.py index 15d4e11569dc..a3be80465e09 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/tests/test_tracing_implementations.py +++ b/sdk/core/azure-core-tracing-opentelemetry/tests/test_tracing_implementations.py @@ -139,7 +139,7 @@ def test_add_attribute(self, tracer): assert parent.attributes["test"] == "test2" def test_set_http_attributes(self, tracer): - with tracer.start_as_current_span("Root") as parent: + with tracer.start_as_current_span("Root", kind=OpenTelemetrySpanKind.CLIENT) as parent: wrapped_class = OpenTelemetrySpan(span=parent) request = mock.Mock() setattr(request, "method", "GET") @@ -148,6 +148,7 @@ def test_set_http_attributes(self, tracer): setattr(request, "headers", {}) setattr(response, "status_code", 200) wrapped_class.set_http_attributes(request) + assert wrapped_class.span_instance.kind == OpenTelemetrySpanKind.CLIENT assert wrapped_class.span_instance.attributes.get("http.method") == request.method assert wrapped_class.span_instance.attributes.get("component") == "http" assert wrapped_class.span_instance.attributes.get("http.url") == request.url From f4312e7af076db48f55e0d4ea2da132372502775 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 3 May 2021 22:56:02 -0700 Subject: [PATCH 4/9] test update --- .../tests/test_tracing_implementations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py b/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py index 7d77c5521e3b..706242a803e1 100644 --- a/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py +++ b/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py @@ -141,7 +141,7 @@ def test_set_http_attributes(self): setattr(request, "headers", {}) setattr(response, "status_code", 200) wrapped_class.set_http_attributes(request) - assert wrapped_class.span_instance.kind == OpenCensusSpanKind.CLIENT + assert wrapped_class.span_instance.span_kind == OpenCensusSpanKind.CLIENT assert wrapped_class.span_instance.attributes.get("http.method") == request.method assert wrapped_class.span_instance.attributes.get("component") == "http" assert wrapped_class.span_instance.attributes.get("http.url") == request.url From 55f9efe07c96964fb721a26c892e425af1262344 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 4 May 2021 00:53:24 -0700 Subject: [PATCH 5/9] regression --- .../tests/test_tracing_implementations.py | 2 +- .../ext/opentelemetry_span/__init__.py | 26 +++++++++++++++++++ .../azure/core/tracing/_abstract_span.py | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py b/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py index 706242a803e1..ecaf8ac96ee4 100644 --- a/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py +++ b/sdk/core/azure-core-tracing-opencensus/tests/test_tracing_implementations.py @@ -132,7 +132,7 @@ def test_add_attribute(self): def test_set_http_attributes(self): with ContextHelper(): trace = tracer_module.Tracer(sampler=AlwaysOnSampler()) - parent = trace.start_span(span_kind=OpenCensusSpanKind.CLIENT) + parent = trace.start_span() wrapped_class = OpenCensusSpan(span=parent) request = mock.Mock() setattr(request, "method", "GET") diff --git a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py index f3a1bfe6c350..ff14f5dd279b 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py +++ b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py @@ -125,6 +125,11 @@ def kind(self): def kind(self, value): # type: (SpanKind) -> None """Set the span kind of this span.""" + warnings.warn( + """Kind must be set while creating the span for Opentelemetry. It might be possible + that one of the packages you are using doesn't follow the latest Opentelemtry Spec. + Try updating the azure packages to the latest versions.""" + ) kind = ( OpenTelemetrySpanKind.CLIENT if value == SpanKind.CLIENT else OpenTelemetrySpanKind.PRODUCER if value == SpanKind.PRODUCER else @@ -299,3 +304,24 @@ def call_with_current_context(*args, **kwargs): detach(token) return call_with_current_context + + def set_http_attributes(self, request, response=None): + # type: (HttpRequest, Optional[HttpResponseType]) -> None + """ + Add correct attributes for a http client span. + + :param request: The request made + :type request: HttpRequest + :param response: The response received by the server. Is None if no response received. + :type response: ~azure.core.pipeline.transport.HttpResponse or ~azure.core.pipeline.transport.AsyncHttpResponse + """ + self.add_attribute(self._SPAN_COMPONENT, "http") + self.add_attribute(self._HTTP_METHOD, request.method) + self.add_attribute(self._HTTP_URL, request.url) + user_agent = request.headers.get("User-Agent") + if user_agent: + self.add_attribute(self._HTTP_USER_AGENT, user_agent) + if response and response.status_code: + self.add_attribute(self._HTTP_STATUS_CODE, response.status_code) + else: + self.add_attribute(self._HTTP_STATUS_CODE, 504) diff --git a/sdk/core/azure-core/azure/core/tracing/_abstract_span.py b/sdk/core/azure-core/azure/core/tracing/_abstract_span.py index de9e408b3025..e2cea5547126 100644 --- a/sdk/core/azure-core/azure/core/tracing/_abstract_span.py +++ b/sdk/core/azure-core/azure/core/tracing/_abstract_span.py @@ -221,6 +221,7 @@ def set_http_attributes(self, request, response=None): :param response: The response received by the server. Is None if no response received. :type response: ~azure.core.pipeline.transport.HttpResponse or ~azure.core.pipeline.transport.AsyncHttpResponse """ + self.kind = SpanKind.CLIENT self.add_attribute(self._SPAN_COMPONENT, "http") self.add_attribute(self._HTTP_METHOD, request.method) self.add_attribute(self._HTTP_URL, request.url) From 1128256b07bdd0d0b597210b07ab542559e060bf Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 4 May 2021 09:00:22 -0700 Subject: [PATCH 6/9] version --- sdk/core/azure-core-tracing-opencensus/setup.py | 2 +- sdk/core/azure-core-tracing-opentelemetry/setup.py | 2 +- shared_requirements.txt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/core/azure-core-tracing-opencensus/setup.py b/sdk/core/azure-core-tracing-opencensus/setup.py index 09380d0dc9f5..c70433333ca1 100644 --- a/sdk/core/azure-core-tracing-opencensus/setup.py +++ b/sdk/core/azure-core-tracing-opencensus/setup.py @@ -61,7 +61,7 @@ 'opencensus>=0.6.0', 'opencensus-ext-azure>=0.3.1', 'opencensus-ext-threading', - 'azure-core<2.0.0,>=1.14.0', + 'azure-core<2.0.0,>=1.13.0', ], extras_require={ ":python_version<'3.5'": ['typing'], diff --git a/sdk/core/azure-core-tracing-opentelemetry/setup.py b/sdk/core/azure-core-tracing-opentelemetry/setup.py index 2cf850cf7567..65a2fc8216e8 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/setup.py +++ b/sdk/core/azure-core-tracing-opentelemetry/setup.py @@ -57,7 +57,7 @@ python_requires=">=3.6.0", install_requires=[ 'opentelemetry-api<2.0.0,>=1.0.0', - 'azure-core<2.0.0,>=1.14.0', + 'azure-core<2.0.0,>=1.13.0', ], extras_require={ ":python_version<'3.5'": ['typing'], diff --git a/shared_requirements.txt b/shared_requirements.txt index cffd80132adc..44e361d627e3 100644 --- a/shared_requirements.txt +++ b/shared_requirements.txt @@ -127,8 +127,8 @@ pyjwt>=1.7.1 #override azure azure-keyvault~=1.0 #override azure-mgmt-core azure-core<2.0.0,>=1.13.0 #override azure-containerregistry azure-core>=1.4.0,<2.0.0 -#override azure-core-tracing-opencensus azure-core<2.0.0,>=1.14.0 -#override azure-core-tracing-opentelemetry azure-core<2.0.0,>=1.14.0 +#override azure-core-tracing-opencensus azure-core<2.0.0,>=1.13.0 +#override azure-core-tracing-opentelemetry azure-core<2.0.0,>=1.13.0 #override azure-cosmos azure-core<2.0.0,>=1.0.0 #override azure-data-tables azure-core<2.0.0,>=1.13.0 #override azure-eventhub azure-core<2.0.0,>=1.13.0 From 9e43c7a1eb25fcd29d09592edbee3854b90fae4a Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 4 May 2021 09:10:12 -0700 Subject: [PATCH 7/9] Update sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py --- .../azure/core/tracing/ext/opentelemetry_span/__init__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py index ff14f5dd279b..57fbea7f6f35 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py +++ b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py @@ -125,11 +125,6 @@ def kind(self): def kind(self, value): # type: (SpanKind) -> None """Set the span kind of this span.""" - warnings.warn( - """Kind must be set while creating the span for Opentelemetry. It might be possible - that one of the packages you are using doesn't follow the latest Opentelemtry Spec. - Try updating the azure packages to the latest versions.""" - ) kind = ( OpenTelemetrySpanKind.CLIENT if value == SpanKind.CLIENT else OpenTelemetrySpanKind.PRODUCER if value == SpanKind.PRODUCER else From 0f60b8d5cde1b7279d2edbe25c900b0b34aed3e2 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 4 May 2021 10:34:33 -0700 Subject: [PATCH 8/9] Update sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py --- .../ext/opentelemetry_span/__init__.py | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py index 57fbea7f6f35..f3a1bfe6c350 100644 --- a/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py +++ b/sdk/core/azure-core-tracing-opentelemetry/azure/core/tracing/ext/opentelemetry_span/__init__.py @@ -299,24 +299,3 @@ def call_with_current_context(*args, **kwargs): detach(token) return call_with_current_context - - def set_http_attributes(self, request, response=None): - # type: (HttpRequest, Optional[HttpResponseType]) -> None - """ - Add correct attributes for a http client span. - - :param request: The request made - :type request: HttpRequest - :param response: The response received by the server. Is None if no response received. - :type response: ~azure.core.pipeline.transport.HttpResponse or ~azure.core.pipeline.transport.AsyncHttpResponse - """ - self.add_attribute(self._SPAN_COMPONENT, "http") - self.add_attribute(self._HTTP_METHOD, request.method) - self.add_attribute(self._HTTP_URL, request.url) - user_agent = request.headers.get("User-Agent") - if user_agent: - self.add_attribute(self._HTTP_USER_AGENT, user_agent) - if response and response.status_code: - self.add_attribute(self._HTTP_STATUS_CODE, response.status_code) - else: - self.add_attribute(self._HTTP_STATUS_CODE, 504) From 27229733935e7bb38b45f0bfeca70f7d4e23aa34 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 4 May 2021 13:20:44 -0700 Subject: [PATCH 9/9] Apply suggestions from code review --- sdk/core/azure-core-tracing-opencensus/setup.py | 2 +- shared_requirements.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/core/azure-core-tracing-opencensus/setup.py b/sdk/core/azure-core-tracing-opencensus/setup.py index c70433333ca1..7ab9fb4027cb 100644 --- a/sdk/core/azure-core-tracing-opencensus/setup.py +++ b/sdk/core/azure-core-tracing-opencensus/setup.py @@ -61,7 +61,7 @@ 'opencensus>=0.6.0', 'opencensus-ext-azure>=0.3.1', 'opencensus-ext-threading', - 'azure-core<2.0.0,>=1.13.0', + 'azure-core<2.0.0,>=1.0.0', ], extras_require={ ":python_version<'3.5'": ['typing'], diff --git a/shared_requirements.txt b/shared_requirements.txt index 44e361d627e3..baf963ca9127 100644 --- a/shared_requirements.txt +++ b/shared_requirements.txt @@ -127,7 +127,7 @@ pyjwt>=1.7.1 #override azure azure-keyvault~=1.0 #override azure-mgmt-core azure-core<2.0.0,>=1.13.0 #override azure-containerregistry azure-core>=1.4.0,<2.0.0 -#override azure-core-tracing-opencensus azure-core<2.0.0,>=1.13.0 +#override azure-core-tracing-opencensus azure-core<2.0.0,>=1.0.0 #override azure-core-tracing-opentelemetry azure-core<2.0.0,>=1.13.0 #override azure-cosmos azure-core<2.0.0,>=1.0.0 #override azure-data-tables azure-core<2.0.0,>=1.13.0 @@ -266,4 +266,4 @@ opentelemetry-sdk<2.0.0,>=1.0.0 #override azure-mgmt-rdbms msrest>=0.6.21 #override azure-mgmt-peering msrest>=0.6.21 #override azure-mgmt-confidentialledger msrest>=0.6.21 -#override azure-mgmt-mixedreality msrest>=0.6.21 \ No newline at end of file +#override azure-mgmt-mixedreality msrest>=0.6.21