Skip to content

Commit a756492

Browse files
hectorhdzgc24t
andauthored
OT Collector trace exporter (#405)
Based on the OpenCensus agent exporter. Fixes #343 Co-authored-by: Chris Kleinknecht <[email protected]>
1 parent 2578b37 commit a756492

File tree

15 files changed

+831
-3
lines changed

15 files changed

+831
-3
lines changed

examples/basic_tracer/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ Click on the trace to view its details.
5353

5454
<p align="center"><img src="./images/jaeger-ui-detail.png?raw=true"/></p>
5555

56+
### Collector
57+
58+
* Start Collector
59+
60+
```sh
61+
$ pip install docker-compose
62+
$ cd docker
63+
$ docker-compose up
64+
65+
* Run the sample
66+
67+
$ pip install opentelemetry-ext-otcollector
68+
$ # from this directory
69+
$ EXPORTER=collector python tracer.py
70+
```
71+
72+
Collector is configured to export to Jaeger, follow Jaeger UI isntructions to find the traces.
73+
74+
75+
5676
## Useful links
5777
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
5878
- For more information on tracing in Python, visit: <https://github.com/open-telemetry/opentelemetry-python>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
receivers:
2+
opencensus:
3+
endpoint: "0.0.0.0:55678"
4+
5+
exporters:
6+
jaeger_grpc:
7+
endpoint: jaeger-all-in-one:14250
8+
logging: {}
9+
10+
processors:
11+
batch:
12+
queued_retry:
13+
14+
service:
15+
pipelines:
16+
traces:
17+
receivers: [opencensus]
18+
exporters: [jaeger_grpc, logging]
19+
processors: [batch, queued_retry]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "2"
2+
services:
3+
4+
# Collector
5+
collector:
6+
image: omnition/opentelemetry-collector-contrib:latest
7+
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
8+
volumes:
9+
- ./collector-config.yaml:/conf/collector-config.yaml
10+
ports:
11+
- "55678:55678"
12+
13+
jaeger-all-in-one:
14+
image: jaegertracing/all-in-one:latest
15+
ports:
16+
- "16686:16686"
17+
- "6831:6831/udp"
18+
- "6832:6832/udp"
19+
- "14268"
20+
- "14250"

examples/basic_tracer/tracer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@
2626
if os.getenv("EXPORTER") == "jaeger":
2727
from opentelemetry.ext.jaeger import JaegerSpanExporter
2828

29+
print("Using JaegerSpanExporter")
2930
exporter = JaegerSpanExporter(
3031
service_name="basic-service",
3132
agent_host_name="localhost",
3233
agent_port=6831,
3334
)
35+
elif os.getenv("EXPORTER") == "collector":
36+
from opentelemetry.ext.otcollector.trace_exporter import (
37+
CollectorSpanExporter,
38+
)
39+
40+
print("Using CollectorSpanExporter")
41+
exporter = CollectorSpanExporter(
42+
service_name="basic-service", endpoint="localhost:55678"
43+
)
3444
else:
45+
print("Using ConsoleSpanExporter")
3546
exporter = ConsoleSpanExporter()
3647

3748
# The preferred tracer implementation must be set, as the opentelemetry-api
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## Unreleased
4+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
OpenTelemetry Collector Exporter
2+
================================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-otcollector.svg
7+
:target: https://pypi.org/project/opentelemetry-ext-otcollector/
8+
9+
This library allows to export data to `OpenTelemetry Collector <https://github.com/open-telemetry/opentelemetry-collector/>`_.
10+
11+
Installation
12+
------------
13+
14+
::
15+
16+
pip install opentelemetry-ext-otcollector
17+
18+
19+
Usage
20+
-----
21+
22+
The **OpenTelemetry Collector Exporter** allows to export `OpenTelemetry`_ traces to `OpenTelemetry Collector`_.
23+
24+
.. code:: python
25+
26+
from opentelemetry import trace
27+
from opentelemetry.ext.otcollector.trace_exporter import CollectorSpanExporter
28+
from opentelemetry.sdk.trace import TracerProvider
29+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
30+
31+
32+
# create a CollectorSpanExporter
33+
collector_exporter = CollectorSpanExporter(
34+
# optional:
35+
# endpoint="myCollectorUrl:55678",
36+
# service_name="test_service",
37+
# host_name="machine/container name",
38+
)
39+
40+
# Create a BatchExportSpanProcessor and add the exporter to it
41+
span_processor = BatchExportSpanProcessor(collector_exporter)
42+
43+
# Configure the tracer to use the collector exporter
44+
tracer_provider = TracerProvider()
45+
tracer_provider.add_span_processor(span_processor)
46+
tracer = TracerProvider().get_tracer(__name__)
47+
48+
with tracer.start_as_current_span("foo"):
49+
print("Hello world!")
50+
51+
References
52+
----------
53+
54+
* `OpenTelemetry Collector <https://github.com/open-telemetry/opentelemetry-collector/>`_
55+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2020, 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-ext-otcollector
17+
description = OpenTelemetry Collector Exporter
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-ext-otcollector
23+
platforms = any
24+
license = Apache-2.0
25+
classifiers =
26+
Development Status :: 3 - Alpha
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+
grpcio >= 1.0.0, < 2.0.0
43+
opencensus-proto >= 0.1.0, < 1.0.0
44+
opentelemetry-api >= 0.5.dev0
45+
opentelemetry-sdk >= 0.5.dev0
46+
protobuf >= 3.8.0
47+
48+
[options.packages.find]
49+
where = src
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2020, 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", "ext", "otcollector", "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__"])
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2020, 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.

0 commit comments

Comments
 (0)