Skip to content

Commit c42749a

Browse files
Andrew Xueclsung
Andrew Xue
andauthored
cloud-trace: Cloud Trace exporter (#698)
Co-authored-by: Cheng-Lung Sung <[email protected]>
1 parent 2ad9f49 commit c42749a

File tree

13 files changed

+922
-0
lines changed

13 files changed

+922
-0
lines changed

docs-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ thrift>=0.10.0
2121
wrapt>=1.0.0,<2.0.0
2222
psutil~=5.7.0
2323
boto~=2.0
24+
google-cloud-trace >=0.23.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Cloud Trace Exporter Example
2+
============================
3+
4+
These examples show how to use OpenTelemetry to send tracing data to Cloud Trace.
5+
6+
7+
Basic Example
8+
-------------
9+
10+
To use this exporter you first need to:
11+
* A Google Cloud project. You can `create one here. <https://console.cloud.google.com/projectcreate>`_
12+
* Enable Cloud Trace API (aka StackDriver Trace API) in the project `here. <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
13+
* Enable `Default Application Credentials. <https://developers.google.com/identity/protocols/application-default-credentials>`_
14+
15+
* Installation
16+
17+
.. code-block:: sh
18+
19+
pip install opentelemetry-api
20+
pip install opentelemetry-sdk
21+
pip install opentelemetry-exporter-cloud-trace
22+
23+
* Run example
24+
25+
.. code-block:: sh
26+
27+
python basic_trace.py
28+
29+
Checking Output
30+
--------------------------
31+
32+
After running any of these examples, you can go to `Cloud Trace overview <https://console.cloud.google.com/traces/list>`_ to see the results.
33+
34+
* `More information about exporters in general <https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html#configure-exporters-to-emit-spans-elsewhere>`_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from opentelemetry import trace
2+
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
3+
from opentelemetry.sdk.trace import TracerProvider
4+
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
5+
6+
trace.set_tracer_provider(TracerProvider())
7+
8+
cloud_trace_exporter = CloudTraceSpanExporter()
9+
trace.get_tracer_provider().add_span_processor(
10+
SimpleExportSpanProcessor(cloud_trace_exporter)
11+
)
12+
tracer = trace.get_tracer(__name__)
13+
with tracer.start_as_current_span("foo"):
14+
print("Hello world!")

docs/ext/cloud_trace/cloud_trace.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OpenTelemetry Cloud Trace Exporter
2+
==================================
3+
4+
.. automodule:: opentelemetry.exporter.cloud_trace
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
OpenTelemetry Cloud Trace Exporters
2+
===================================
3+
4+
This library provides classes for exporting trace data to Google Cloud Trace.
5+
6+
Installation
7+
------------
8+
9+
::
10+
11+
pip install opentelemetry-exporter-cloud-trace
12+
13+
Usage
14+
-----
15+
16+
.. code:: python
17+
18+
from opentelemetry import trace
19+
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
20+
from opentelemetry.sdk.trace import TracerProvider
21+
from opentelemetry.sdk.trace.export import (
22+
SimpleExportSpanProcessor,
23+
)
24+
25+
trace.set_tracer_provider(TracerProvider())
26+
27+
cloud_trace_exporter = CloudTraceSpanExporter(
28+
project_id='my-gcloud-project',
29+
)
30+
trace.get_tracer_provider().add_span_processor(
31+
SimpleExportSpanProcessor(cloud_trace_exporter)
32+
)
33+
tracer = trace.get_tracer(__name__)
34+
with tracer.start_as_current_span('foo'):
35+
print('Hello world!')
36+
37+
38+
39+
References
40+
----------
41+
42+
* `Cloud Trace <https://cloud.google.com/trace/>`_
43+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
[metadata]
16+
name = opentelemetry-exporter-cloud-trace
17+
description = Cloud Trace integration for OpenTelemetry
18+
long_description = file: README.rst
19+
long_description_content_type = text/x-rst
20+
author = OpenTelemetry Authors
21+
author_email = [email protected]
22+
url = https://github.com/open-telemetry/opentelemetry-python/ext/opentelemetry-exporter-cloud-trace
23+
platforms = any
24+
license = Apache-2.0
25+
classifiers =
26+
Development Status :: 4 - Beta
27+
Intended Audience :: Developers
28+
License :: OSI Approved :: Apache Software License
29+
Programming Language :: Python
30+
Programming Language :: Python :: 3
31+
Programming Language :: Python :: 3.4
32+
Programming Language :: Python :: 3.5
33+
Programming Language :: Python :: 3.6
34+
Programming Language :: Python :: 3.7
35+
36+
[options]
37+
python_requires = >=3.4
38+
package_dir=
39+
=src
40+
packages=find_namespace:
41+
install_requires =
42+
opentelemetry-api
43+
opentelemetry-sdk
44+
google-cloud-trace
45+
46+
[options.packages.find]
47+
where = src
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import os
15+
16+
import setuptools
17+
18+
BASE_DIR = os.path.dirname(__file__)
19+
VERSION_FILENAME = os.path.join(
20+
BASE_DIR, "src", "opentelemetry", "exporter", "cloud_trace", "version.py"
21+
)
22+
PACKAGE_INFO = {}
23+
with open(VERSION_FILENAME) as f:
24+
exec(f.read(), PACKAGE_INFO)
25+
26+
setuptools.setup(version=PACKAGE_INFO["__version__"])

0 commit comments

Comments
 (0)