From a131d1a1ab1b8a24402957ed82524fac3d6b824a Mon Sep 17 00:00:00 2001 From: Andrew Xue Date: Fri, 29 May 2020 18:11:13 -0400 Subject: [PATCH] address comments --- docs/examples/cloud_trace_exporter/README.rst | 32 ++----------- .../cloud_trace_exporter/basic_trace.py | 2 +- docs/examples/cloud_trace_exporter/client.py | 34 -------------- docs/examples/cloud_trace_exporter/server.py | 46 ------------------- docs/ext/cloud_trace/cloud_trace.rst | 2 +- .../README.rst | 4 +- .../setup.cfg | 4 +- .../setup.py | 2 +- .../exporter}/cloud_trace/__init__.py | 12 ++--- .../exporter}/cloud_trace/version.py | 0 .../tests/__init__.py | 0 .../tests/test_cloud_trace_exporter.py | 9 ++-- .../src/opentelemetry/ext/datadog/exporter.py | 3 +- .../tests/test_datadog_exporter.py | 1 - opentelemetry-sdk/CHANGELOG.md | 2 - scripts/coverage.sh | 2 +- tox.ini | 2 +- 17 files changed, 23 insertions(+), 134 deletions(-) delete mode 100644 docs/examples/cloud_trace_exporter/client.py delete mode 100644 docs/examples/cloud_trace_exporter/server.py rename ext/{opentelemetry-ext-cloud-trace => opentelemetry-exporter-cloud-trace}/README.rst (87%) rename ext/{opentelemetry-ext-cloud-trace => opentelemetry-exporter-cloud-trace}/setup.cfg (95%) rename ext/{opentelemetry-ext-cloud-trace => opentelemetry-exporter-cloud-trace}/setup.py (91%) rename ext/{opentelemetry-ext-cloud-trace/src/opentelemetry/ext => opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter}/cloud_trace/__init__.py (95%) rename ext/{opentelemetry-ext-cloud-trace/src/opentelemetry/ext => opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter}/cloud_trace/version.py (100%) rename ext/{opentelemetry-ext-cloud-trace => opentelemetry-exporter-cloud-trace}/tests/__init__.py (100%) rename ext/{opentelemetry-ext-cloud-trace => opentelemetry-exporter-cloud-trace}/tests/test_cloud_trace_exporter.py (97%) diff --git a/docs/examples/cloud_trace_exporter/README.rst b/docs/examples/cloud_trace_exporter/README.rst index b7a0e20a344..871422356a7 100644 --- a/docs/examples/cloud_trace_exporter/README.rst +++ b/docs/examples/cloud_trace_exporter/README.rst @@ -18,7 +18,7 @@ To use this exporter you first need to: pip install opentelemetry-api pip install opentelemetry-sdk - pip install opentelemetry-ext-cloud-trace + pip install opentelemetry-exporter-cloud-trace * Run example @@ -26,33 +26,9 @@ To use this exporter you first need to: python basic_trace.py -Server-Client Example --------------------------- - -* Installation - -.. code-block:: sh - - pip install flask - pip install requests - pip install opentelemetry-api - pip install opentelemetry-sdk - pip install opentelemetry-ext-cloud-trace - pip install opentelemetry-ext-flask - -* Start server - -.. code-block:: sh - - python server.py - -* Run client - -.. code-block:: sh - - python client.py - Checking Output -------------------------- -After running any of these examples, you can go to `Cloud Trace overview `_ to see the results. \ No newline at end of file +After running any of these examples, you can go to `Cloud Trace overview `_ to see the results. + +* `More information about exporters in general `_ \ No newline at end of file diff --git a/docs/examples/cloud_trace_exporter/basic_trace.py b/docs/examples/cloud_trace_exporter/basic_trace.py index 6b61678f50b..76840a291ec 100644 --- a/docs/examples/cloud_trace_exporter/basic_trace.py +++ b/docs/examples/cloud_trace_exporter/basic_trace.py @@ -1,5 +1,5 @@ from opentelemetry import trace -from opentelemetry.ext.cloud_trace import CloudTraceSpanExporter +from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor diff --git a/docs/examples/cloud_trace_exporter/client.py b/docs/examples/cloud_trace_exporter/client.py deleted file mode 100644 index 1ed9d52e68f..00000000000 --- a/docs/examples/cloud_trace_exporter/client.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import requests - -from opentelemetry import trace -from opentelemetry.ext.cloud_trace import CloudTraceSpanExporter -from opentelemetry.ext.requests import RequestsInstrumentor -from opentelemetry.sdk.trace import TracerProvider -from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor - -trace.set_tracer_provider(TracerProvider()) - -cloud_trace_exporter = CloudTraceSpanExporter() -trace.get_tracer_provider().add_span_processor( - SimpleExportSpanProcessor(cloud_trace_exporter) -) -# Instrumenting requests should be done AFTER a tracer provider is configured -RequestsInstrumentor().instrument() -tracer = trace.get_tracer(__name__) - -with tracer.start_as_current_span("client"): - response = requests.get(url="http://localhost:7777/") diff --git a/docs/examples/cloud_trace_exporter/server.py b/docs/examples/cloud_trace_exporter/server.py deleted file mode 100644 index 6aec42eba63..00000000000 --- a/docs/examples/cloud_trace_exporter/server.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import requests -from flask import Flask - -from opentelemetry import trace -from opentelemetry.ext.cloud_trace import CloudTraceSpanExporter -from opentelemetry.ext.flask import FlaskInstrumentor -from opentelemetry.ext.requests import RequestsInstrumentor -from opentelemetry.sdk.trace import TracerProvider -from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor - -trace.set_tracer_provider(TracerProvider()) - -cloud_trace_exporter = CloudTraceSpanExporter() -trace.get_tracer_provider().add_span_processor( - SimpleExportSpanProcessor(cloud_trace_exporter) -) -# Instrumenting requests should be done AFTER a tracer provider is configured -RequestsInstrumentor().instrument() -app = Flask(__name__) -FlaskInstrumentor().instrument_app(app) - - -@app.route("/") -def hello(): - tracer = trace.get_tracer(__name__) - with tracer.start_as_current_span("parent"): - requests.get("https://www.wikipedia.org/wiki/Rabbit") - return "hello" - - -if __name__ == "__main__": - app.run(debug=True, port=7777) diff --git a/docs/ext/cloud_trace/cloud_trace.rst b/docs/ext/cloud_trace/cloud_trace.rst index 536242d50b1..5914b00d1a4 100644 --- a/docs/ext/cloud_trace/cloud_trace.rst +++ b/docs/ext/cloud_trace/cloud_trace.rst @@ -1,7 +1,7 @@ OpenTelemetry Cloud Trace Exporter ================================== -.. automodule:: opentelemetry.ext.cloud_trace +.. automodule:: opentelemetry.exporter.cloud_trace :members: :undoc-members: :show-inheritance: diff --git a/ext/opentelemetry-ext-cloud-trace/README.rst b/ext/opentelemetry-exporter-cloud-trace/README.rst similarity index 87% rename from ext/opentelemetry-ext-cloud-trace/README.rst rename to ext/opentelemetry-exporter-cloud-trace/README.rst index 4e9408abf0b..001f163007e 100644 --- a/ext/opentelemetry-ext-cloud-trace/README.rst +++ b/ext/opentelemetry-exporter-cloud-trace/README.rst @@ -8,7 +8,7 @@ Installation :: - pip install opentelemetry-ext-cloud-trace + pip install opentelemetry-exporter-cloud-trace Usage ----- @@ -16,7 +16,7 @@ Usage .. code:: python from opentelemetry import trace - from opentelemetry.ext.cloud_trace import CloudTraceSpanExporter + from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( SimpleExportSpanProcessor, diff --git a/ext/opentelemetry-ext-cloud-trace/setup.cfg b/ext/opentelemetry-exporter-cloud-trace/setup.cfg similarity index 95% rename from ext/opentelemetry-ext-cloud-trace/setup.cfg rename to ext/opentelemetry-exporter-cloud-trace/setup.cfg index a7123eed630..df6c2ce587b 100644 --- a/ext/opentelemetry-ext-cloud-trace/setup.cfg +++ b/ext/opentelemetry-exporter-cloud-trace/setup.cfg @@ -13,13 +13,13 @@ # limitations under the License. # [metadata] -name = opentelemetry-ext-cloud-trace +name = opentelemetry-exporter-cloud-trace description = Cloud Trace integration for OpenTelemetry long_description = file: README.rst long_description_content_type = text/x-rst author = OpenTelemetry Authors author_email = cncf-opentelemetry-contributors@lists.cncf.io -url = https://github.com/open-telemetry/opentelemetry-python/ext/opentelemetry-ext-cloud-trace +url = https://github.com/open-telemetry/opentelemetry-python/ext/opentelemetry-exporter-cloud-trace platforms = any license = Apache-2.0 classifiers = diff --git a/ext/opentelemetry-ext-cloud-trace/setup.py b/ext/opentelemetry-exporter-cloud-trace/setup.py similarity index 91% rename from ext/opentelemetry-ext-cloud-trace/setup.py rename to ext/opentelemetry-exporter-cloud-trace/setup.py index 253b0d50e4f..332cf41d01c 100644 --- a/ext/opentelemetry-ext-cloud-trace/setup.py +++ b/ext/opentelemetry-exporter-cloud-trace/setup.py @@ -17,7 +17,7 @@ BASE_DIR = os.path.dirname(__file__) VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "ext", "cloud_trace", "version.py" + BASE_DIR, "src", "opentelemetry", "exporter", "cloud_trace", "version.py" ) PACKAGE_INFO = {} with open(VERSION_FILENAME) as f: diff --git a/ext/opentelemetry-ext-cloud-trace/src/opentelemetry/ext/cloud_trace/__init__.py b/ext/opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter/cloud_trace/__init__.py similarity index 95% rename from ext/opentelemetry-ext-cloud-trace/src/opentelemetry/ext/cloud_trace/__init__.py rename to ext/opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter/cloud_trace/__init__.py index 53b47027c7e..12a0cc01304 100644 --- a/ext/opentelemetry-ext-cloud-trace/src/opentelemetry/ext/cloud_trace/__init__.py +++ b/ext/opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter/cloud_trace/__init__.py @@ -21,7 +21,7 @@ .. code-block:: python from opentelemetry import trace - from opentelemetry.ext.cloud_trace import CloudTraceSpanExporter + from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor @@ -88,12 +88,12 @@ def export(self, spans: Sequence[Span]) -> SpanExportResult: spans: Tuple of spans to export """ cloud_trace_spans = [] - for span in self.translate_to_cloud_trace(spans): + for span in self._translate_to_cloud_trace(spans): try: cloud_trace_spans.append(self.client.create_span(**span)) # pylint: disable=broad-except except Exception as ex: - logger.warning("Error %s when creating span %s", ex, span) + logger.error("Error when creating span %s", span, exc_info=ex) try: self.client.batch_write_spans( @@ -101,12 +101,12 @@ def export(self, spans: Sequence[Span]) -> SpanExportResult: ) # pylint: disable=broad-except except Exception as ex: - logger.warning("Error while writing to Cloud Trace: %s", ex) + logger.error("Error while writing to Cloud Trace", exc_info=ex) return SpanExportResult.FAILURE return SpanExportResult.SUCCESS - def translate_to_cloud_trace( + def _translate_to_cloud_trace( self, spans: Sequence[Span] ) -> List[Dict[str, Any]]: """Translate the spans to Cloud Trace format. @@ -286,7 +286,7 @@ def _format_attribute_value(value: types.AttributeValue) -> AttributeValue: value = _get_truncatable_str_object(value) elif isinstance(value, float): value_type = "string_value" - value = _get_truncatable_str_object(str(value)) + value = _get_truncatable_str_object("{:0.4f}".format(value)) else: logger.warning( "ignoring attribute value %s of type %s. Values type must be one " diff --git a/ext/opentelemetry-ext-cloud-trace/src/opentelemetry/ext/cloud_trace/version.py b/ext/opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter/cloud_trace/version.py similarity index 100% rename from ext/opentelemetry-ext-cloud-trace/src/opentelemetry/ext/cloud_trace/version.py rename to ext/opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter/cloud_trace/version.py diff --git a/ext/opentelemetry-ext-cloud-trace/tests/__init__.py b/ext/opentelemetry-exporter-cloud-trace/tests/__init__.py similarity index 100% rename from ext/opentelemetry-ext-cloud-trace/tests/__init__.py rename to ext/opentelemetry-exporter-cloud-trace/tests/__init__.py diff --git a/ext/opentelemetry-ext-cloud-trace/tests/test_cloud_trace_exporter.py b/ext/opentelemetry-exporter-cloud-trace/tests/test_cloud_trace_exporter.py similarity index 97% rename from ext/opentelemetry-ext-cloud-trace/tests/test_cloud_trace_exporter.py rename to ext/opentelemetry-exporter-cloud-trace/tests/test_cloud_trace_exporter.py index 2d0875df568..ce68c842e1e 100644 --- a/ext/opentelemetry-ext-cloud-trace/tests/test_cloud_trace_exporter.py +++ b/ext/opentelemetry-exporter-cloud-trace/tests/test_cloud_trace_exporter.py @@ -20,7 +20,7 @@ from google.cloud.trace_v2.proto.trace_pb2 import TruncatableString from google.rpc.status_pb2 import Status -from opentelemetry.ext.cloud_trace import ( +from opentelemetry.exporter.cloud_trace import ( CloudTraceSpanExporter, _extract_attributes, _extract_events, @@ -29,7 +29,7 @@ _truncate_str, ) from opentelemetry.sdk.trace import Event, Span -from opentelemetry.trace import Link, SpanContext, SpanKind +from opentelemetry.trace import DefaultSpan, Link, SpanContext, SpanKind from opentelemetry.trace.status import Status as SpanStatus from opentelemetry.trace.status import StatusCanonicalCode @@ -37,7 +37,7 @@ class TestCloudTraceSpanExporter(unittest.TestCase): def setUp(self): self.client_patcher = mock.patch( - "opentelemetry.ext.cloud_trace.TraceServiceClient" + "opentelemetry.exporter.cloud_trace.TraceServiceClient" ) self.client_patcher.start() self.project_id = "PROJECT" @@ -254,6 +254,3 @@ def test_extract_links(self): ] ), ) - - def test_truncate_string(self): - self.assertEqual("111", _truncate_str("1111", 3)[0]) diff --git a/ext/opentelemetry-ext-datadog/src/opentelemetry/ext/datadog/exporter.py b/ext/opentelemetry-ext-datadog/src/opentelemetry/ext/datadog/exporter.py index 01a01919962..1b3c713b5cb 100644 --- a/ext/opentelemetry-ext-datadog/src/opentelemetry/ext/datadog/exporter.py +++ b/ext/opentelemetry-ext-datadog/src/opentelemetry/ext/datadog/exporter.py @@ -16,11 +16,10 @@ import os from urllib.parse import urlparse +import opentelemetry.trace as trace_api from ddtrace.ext import SpanTypes as DatadogSpanTypes from ddtrace.internal.writer import AgentWriter from ddtrace.span import Span as DatadogSpan - -import opentelemetry.trace as trace_api from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult from opentelemetry.trace.status import StatusCanonicalCode diff --git a/ext/opentelemetry-ext-datadog/tests/test_datadog_exporter.py b/ext/opentelemetry-ext-datadog/tests/test_datadog_exporter.py index 14fd5507891..a0fe874a179 100644 --- a/ext/opentelemetry-ext-datadog/tests/test_datadog_exporter.py +++ b/ext/opentelemetry-ext-datadog/tests/test_datadog_exporter.py @@ -19,7 +19,6 @@ from unittest import mock from ddtrace.internal.writer import AgentWriter - from opentelemetry import trace as trace_api from opentelemetry.ext import datadog from opentelemetry.sdk import trace diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 1a6371f3122..50ea751e15d 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -16,8 +16,6 @@ Released 2020-05-27 ([#729](https://github.com/open-telemetry/opentelemetry-python/pull/729)) - deep copy empty attributes ([#714](https://github.com/open-telemetry/opentelemetry-python/pull/714)) -- Add cloud trace exporter - ([#698](https://github.com/open-telemetry/opentelemetry-python/pull/698)) ## 0.7b1 diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 99d6ea014b7..aa716f388da 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -24,7 +24,7 @@ cov ext/opentelemetry-ext-flask cov ext/opentelemetry-ext-requests cov ext/opentelemetry-ext-jaeger cov ext/opentelemetry-ext-opentracing-shim -cov ext/opentelemetry-ext-cloud-trace +cov ext/opentelemetry-exporter-cloud-trace cov ext/opentelemetry-ext-wsgi cov ext/opentelemetry-ext-zipkin cov docs/examples/opentelemetry-example-app diff --git a/tox.ini b/tox.ini index 46df53d6e03..11a1bfdc744 100644 --- a/tox.ini +++ b/tox.ini @@ -150,7 +150,7 @@ changedir = test-ext-opencensusexporter: ext/opentelemetry-ext-opencensusexporter/tests test-ext-prometheus: ext/opentelemetry-ext-prometheus/tests test-ext-pymongo: ext/opentelemetry-ext-pymongo/tests - test-ext-cloud-trace: ext/opentelemetry-ext-cloud-trace/tests + test-exporter-cloud-trace: ext/opentelemetry-exporter-cloud-trace/tests test-ext-psycopg2: ext/opentelemetry-ext-psycopg2/tests test-ext-pymysql: ext/opentelemetry-ext-pymysql/tests test-ext-asgi: ext/opentelemetry-ext-asgi/tests