Skip to content

Commit

Permalink
cloud-trace: Cloud Trace exporter (#698)
Browse files Browse the repository at this point in the history
Co-authored-by: Cheng-Lung Sung <clsung@gmail.com>
  • Loading branch information
Andrew Xue and clsung committed Jun 4, 2020
1 parent 2ad9f49 commit c42749a
Show file tree
Hide file tree
Showing 13 changed files with 922 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ thrift>=0.10.0
wrapt>=1.0.0,<2.0.0
psutil~=5.7.0
boto~=2.0
google-cloud-trace >=0.23.0
34 changes: 34 additions & 0 deletions docs/examples/cloud_trace_exporter/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Cloud Trace Exporter Example
============================

These examples show how to use OpenTelemetry to send tracing data to Cloud Trace.


Basic Example
-------------

To use this exporter you first need to:
* A Google Cloud project. You can `create one here. <https://console.cloud.google.com/projectcreate>`_
* Enable Cloud Trace API (aka StackDriver Trace API) in the project `here. <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
* Enable `Default Application Credentials. <https://developers.google.com/identity/protocols/application-default-credentials>`_

* Installation

.. code-block:: sh
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-exporter-cloud-trace
* Run example

.. code-block:: sh
python basic_trace.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.

* `More information about exporters in general <https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html#configure-exporters-to-emit-spans-elsewhere>`_
14 changes: 14 additions & 0 deletions docs/examples/cloud_trace_exporter/basic_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
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)
)
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("foo"):
print("Hello world!")
7 changes: 7 additions & 0 deletions docs/ext/cloud_trace/cloud_trace.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenTelemetry Cloud Trace Exporter
==================================

.. automodule:: opentelemetry.exporter.cloud_trace
:members:
:undoc-members:
:show-inheritance:
43 changes: 43 additions & 0 deletions ext/opentelemetry-exporter-cloud-trace/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
OpenTelemetry Cloud Trace Exporters
===================================

This library provides classes for exporting trace data to Google Cloud Trace.

Installation
------------

::

pip install opentelemetry-exporter-cloud-trace

Usage
-----

.. code:: python
from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
SimpleExportSpanProcessor,
)
trace.set_tracer_provider(TracerProvider())
cloud_trace_exporter = CloudTraceSpanExporter(
project_id='my-gcloud-project',
)
trace.get_tracer_provider().add_span_processor(
SimpleExportSpanProcessor(cloud_trace_exporter)
)
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span('foo'):
print('Hello world!')
References
----------

* `Cloud Trace <https://cloud.google.com/trace/>`_
* `OpenTelemetry Project <https://opentelemetry.io/>`_
47 changes: 47 additions & 0 deletions ext/opentelemetry-exporter-cloud-trace/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.
#
[metadata]
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-exporter-cloud-trace
platforms = any
license = Apache-2.0
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7

[options]
python_requires = >=3.4
package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api
opentelemetry-sdk
google-cloud-trace

[options.packages.find]
where = src
26 changes: 26 additions & 0 deletions ext/opentelemetry-exporter-cloud-trace/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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 os

import setuptools

BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "exporter", "cloud_trace", "version.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(version=PACKAGE_INFO["__version__"])
Loading

0 comments on commit c42749a

Please sign in to comment.