Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OT Collector trace exporter #405

Merged
merged 25 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d6aa116
Initial commit
hectorhdzg Jan 7, 2020
83267f6
Blocked on proto python compiled files
hectorhdzg Jan 8, 2020
1c79ae6
WIP
hectorhdzg Feb 11, 2020
444334c
Merge remote-tracking branch 'upstream/master' into hectorhdzg/otcoll…
hectorhdzg Feb 11, 2020
2bab1cc
WIP
hectorhdzg Feb 11, 2020
bd7a021
Adding protobuf dependency
hectorhdzg Feb 11, 2020
e36cf3e
Adding more checks in tests
hectorhdzg Feb 11, 2020
809a27c
Removing pypy3 because if is not supported for GRPC
hectorhdzg Feb 11, 2020
3c769e1
Removing pypy3 Collector env from tox
hectorhdzg Feb 11, 2020
f90526d
Adding readme details
hectorhdzg Feb 13, 2020
242704a
Adding sample
hectorhdzg Feb 19, 2020
3c794df
Fix lint
hectorhdzg Feb 19, 2020
3a66e47
Addressing comments
hectorhdzg Feb 20, 2020
744b372
Merge branch 'master' into hectorhdzg/otcollector
hectorhdzg Feb 20, 2020
402e6d6
Fix lint
hectorhdzg Feb 20, 2020
4c48178
Merge branch 'hectorhdzg/otcollector' of https://github.com/hectorhdz…
hectorhdzg Feb 20, 2020
a4d93b9
Addressing comments
hectorhdzg Feb 21, 2020
9cac0c2
Merge branch 'master' into hectorhdzg/otcollector
hectorhdzg Feb 21, 2020
bb43c70
Merge branch 'master' into hectorhdzg/otcollector
c24t Feb 26, 2020
2c9c018
Add missing init file
c24t Feb 26, 2020
dc1274e
Use TracerSource in OTC example
c24t Feb 26, 2020
8f5bbe9
Update tox.ini
hectorhdzg Feb 27, 2020
f7feccb
Addressing comments
hectorhdzg Feb 27, 2020
64250e0
Merge branch 'hectorhdzg/otcollector' of https://github.com/hectorhdz…
hectorhdzg Feb 27, 2020
3df18a4
Adding exporter version
hectorhdzg Feb 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/basic_tracer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ Click on the trace to view its details.

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

### Collector

* Start Collector

```sh
$ pip install docker-compose
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
$ cd docker
$ docker-compose up

* Run the sample

$ pip install opentelemetry-ext-otcollector
$ # from this directory
$ EXPORTER=collector python tracer.py
```

Collector is configured to export to Jaeger, follow Jaeger UI isntructions to find the traces.



## Useful links
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more information on tracing in Python, visit: <https://github.com/open-telemetry/opentelemetry-python>
Expand Down
18 changes: 18 additions & 0 deletions examples/basic_tracer/docker/collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
receivers:
opencensus:
endpoint: "0.0.0.0:55678"

exporters:
jaeger_grpc:
endpoint: jaeger-all-in-one:14250

processors:
batch:
queued_retry:

service:
pipelines:
traces:
receivers: [opencensus]
exporters: [jaeger_grpc]
processors: [batch, queued_retry]
20 changes: 20 additions & 0 deletions examples/basic_tracer/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "2"
services:

# Collector
collector:
image: omnition/opentelemetry-collector-contrib:latest
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
volumes:
- ./collector-config.yaml:/conf/collector-config.yaml
ports:
- "55678:55678"

jaeger-all-in-one:
image: jaegertracing/all-in-one:latest
ports:
- "16686:16686"
- "6831:6831/udp"
- "6832:6832/udp"
- "14268"
- "14250"
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions examples/basic_tracer/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@
if os.getenv("EXPORTER") == "jaeger":
from opentelemetry.ext.jaeger import JaegerSpanExporter

print("Using JaegerSpanExporter")
exporter = JaegerSpanExporter(
service_name="basic-service",
agent_host_name="localhost",
agent_port=6831,
)
elif os.getenv("EXPORTER") == "collector":
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
from opentelemetry.ext.otcollector.trace_exporter import (
CollectorSpanExporter,
)

print("Using CollectorSpanExporter")
exporter = CollectorSpanExporter(
service_name="basic-service", endpoint="localhost:55678"
)
else:
print("Using ConsoleSpanExporter")
exporter = ConsoleSpanExporter()

# The preferred tracer implementation must be set, as the opentelemetry-api
Expand Down
4 changes: 4 additions & 0 deletions ext/opentelemetry-ext-otcollector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## Unreleased

55 changes: 55 additions & 0 deletions ext/opentelemetry-ext-otcollector/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
OpenTelemetry Collector Exporter
=============================
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-otcollector.svg
:target: https://pypi.org/project/opentelemetry-ext-otcollector/

This library allows to export data to `OpenTelemetry Collector <https://github.com/open-telemetry/opentelemetry-collector/>`_.

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

::

pip install opentelemetry-ext-otcollector


Usage
-----

The **OpenTelemetry Collector Exporter** allows to export `OpenTelemetry`_ traces to `OpenTelemetry Collector`_.

.. code:: python

from opentelemetry import trace
from opentelemetry.ext.otcollector.trace_exporter import CollectorSpanExporter
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
tracer = trace.get_tracer(__name__)

# create a CollectorSpanExporter
collector_exporter = CollectorSpanExporter(
# optional:
# endpoint="myCollectorUrl:55678",
# service_name="test_service",
# host_name="machine/container name",
)

# Create a BatchExportSpanProcessor and add the exporter to it
span_processor = BatchExportSpanProcessor(collector_exporter)

# add to the tracer
trace.tracer_source().add_span_processor(span_processor)

with tracer.start_as_current_span("foo"):
print("Hello world!")

References
----------

* `OpenTelemetry Collector <https://github.com/open-telemetry/opentelemetry-collector/>`_
* `OpenTelemetry Project <https://opentelemetry.io/>`_
49 changes: 49 additions & 0 deletions ext/opentelemetry-ext-otcollector/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2020, 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-ext-otcollector
description = OpenTelemetry Collector Exporter
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-otcollector
platforms = any
license = Apache-2.0
classifiers =
Development Status :: 3 - Alpha
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 =
grpcio >= 1.0.0, < 2.0.0
opencensus-proto >= 0.1.0, < 1.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an OpenCensus exporter? You write OT exporter in the title.

Copy link
Member Author

@hectorhdzg hectorhdzg Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well is in fact exporting to OT Collector through OpenCensus receiver, OT receiver will be ready in several weeks I added more details in first comment in the PR, we will need to revisit this one and add code to handle OT receiver using OT proto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I spent some time trying to make it work with OT proto building the protobuf files myself then realizing the receiver is not there yet, people are interested in having this ready so decided to take same approach as JS SDK and support it through OpenCensus receiver, once OT receiver is ready hopefully changes only affect the span transformation and some other small pieces of code

opentelemetry-api >= 0.4.dev0
opentelemetry-sdk >= 0.4.dev0
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved
protobuf >= 3.8.0

[options.packages.find]
where = src
26 changes: 26 additions & 0 deletions ext/opentelemetry-ext-otcollector/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020, 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", "ext", "otcollector", "version.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

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