Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Xue committed May 29, 2020
1 parent 7732d03 commit a131d1a
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 134 deletions.
32 changes: 4 additions & 28 deletions docs/examples/cloud_trace_exporter/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,17 @@ 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

.. code-block:: sh
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 <https://console.cloud.google.com/traces/list>`_ to see the results.
After running any of these examples, you can go to `Cloud Trace overview <https://console.cloud.google.com/traces/list>`_ to see the results.

* `More information about exporters in general <https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html#configure-exporters-to-emit-spans-elsewhere>`_
2 changes: 1 addition & 1 deletion docs/examples/cloud_trace_exporter/basic_trace.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
34 changes: 0 additions & 34 deletions docs/examples/cloud_trace_exporter/client.py

This file was deleted.

46 changes: 0 additions & 46 deletions docs/examples/cloud_trace_exporter/server.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/ext/cloud_trace/cloud_trace.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OpenTelemetry Cloud Trace Exporter
==================================

.. automodule:: opentelemetry.ext.cloud_trace
.. automodule:: opentelemetry.exporter.cloud_trace
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Installation

::

pip install opentelemetry-ext-cloud-trace
pip install opentelemetry-exporter-cloud-trace

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,25 +88,25 @@ 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(
"projects/{}".format(self.project_id), cloud_trace_spans,
)
# 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.
Expand Down Expand Up @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,15 +29,15 @@
_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


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"
Expand Down Expand Up @@ -254,6 +254,3 @@ def test_extract_links(self):
]
),
)

def test_truncate_string(self):
self.assertEqual("111", _truncate_str("1111", 3)[0])
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a131d1a

Please sign in to comment.