Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fa92f3

Browse files
mauriciovasquezbernalOberon00
authored andcommitted
Add Jaeger exporter (open-telemetry#174)
This adds a Jeager exporter for OpenTelemetry. This exporter is based on https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-jaeger. The exporter uses thrift and can be configured to send data to the agent and also to a remote collector. There is a long discussion going on about how to include generated files in the repo, so for now just put them here.
1 parent c94a576 commit 9fa92f3

32 files changed

+3954
-3
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[flake8]
22
ignore = E501,W503,E203
3+
exclude = .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,ext/opentelemetry-ext-jaeger/src/opentelemetry/ext/jaeger/gen/,ext/opentelemetry-ext-jaeger/build/*

.isort.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ line_length=79
1212
; )
1313
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
1414
multi_line_output=3
15+
skip_glob=ext/opentelemetry-ext-jaeger/src/opentelemetry/ext/jaeger/gen/*

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension-pkg-whitelist=
77

88
# Add files or directories to the blacklist. They should be base names, not
99
# paths.
10-
ignore=CVS
10+
ignore=CVS,gen
1111

1212
# Add files or directories matching the regex patterns to the blacklist. The
1313
# regex matches against base names, not paths.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
OpenTelemetry Jaeger Exporter
2+
=============================
3+
4+
Installation
5+
------------
6+
7+
::
8+
9+
pip install opentelemetry-ext-jaeger
10+
11+
12+
Usage
13+
-----
14+
15+
The **OpenTelemetry Jaeger Exporter** allows to export `OpenTelemetry`_ traces to `Jaeger`_.
16+
This exporter always send traces to the configured agent using Thrift compact protocol over UDP.
17+
An optional collector can be configured, in this case Thrift binary protocol over HTTP is used.
18+
gRPC is still not supported by this implementation.
19+
20+
21+
.. _Jaeger: https://www.jaegertracing.io/
22+
.. _OpenTelemetry: https://github.com/opentelemetry/opentelemetry-python/
23+
24+
.. code:: python
25+
26+
from opentelemetry import trace
27+
from opentelemetry.ext import jaeger
28+
from opentelemetry.sdk.trace import Tracer
29+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
30+
31+
trace.set_preferred_tracer_implementation(lambda T: Tracer())
32+
tracer = trace.tracer()
33+
34+
# create a JaegerSpanExporter
35+
jaeger_exporter = jaeger.JaegerSpanExporter(
36+
service_name='my-helloworld-service',
37+
# configure agent
38+
agent_host_name='localhost',
39+
agent_port=6831,
40+
# optional: configure also collector
41+
# collector_host_name='localhost',
42+
# collector_port=14268,
43+
# collector_endpoint='/api/traces?format=jaeger.thrift',
44+
# username=xxxx, # optional
45+
# password=xxxx, # optional
46+
)
47+
48+
# Create a BatchExportSpanProcessor and add the exporter to it
49+
span_processor = BatchExportSpanProcessor(jaeger_exporter)
50+
51+
# add to the tracer
52+
tracer.add_span_processor(span_processor)
53+
54+
with tracer.start_span('foo'):
55+
print('Hello world!')
56+
57+
# shutdown the span processor
58+
# TODO: this has to be improved so user doesn't need to call it manually
59+
span_processor.shutdown()
60+
61+
The `examples <./examples>`_ folder contains more elaborated examples.
62+
63+
References
64+
----------
65+
66+
* `Jaeger <https://www.jaegertracing.io/>`_
67+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import time
2+
3+
from opentelemetry import trace
4+
from opentelemetry.ext import jaeger
5+
from opentelemetry.sdk.trace import Tracer
6+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
7+
8+
trace.set_preferred_tracer_implementation(lambda T: Tracer())
9+
tracer = trace.tracer()
10+
11+
# create a JaegerSpanExporter
12+
jaeger_exporter = jaeger.JaegerSpanExporter(
13+
service_name="my-helloworld-service",
14+
# configure agent
15+
agent_host_name="localhost",
16+
agent_port=6831,
17+
# optional: configure also collector
18+
# collector_host_name="localhost",
19+
# collector_port=14268,
20+
# collector_endpoint="/api/traces?format=jaeger.thrift",
21+
# username=xxxx, # optional
22+
# password=xxxx, # optional
23+
)
24+
25+
# create a BatchExportSpanProcessor and add the exporter to it
26+
span_processor = BatchExportSpanProcessor(jaeger_exporter)
27+
28+
# add to the tracer
29+
tracer.add_span_processor(span_processor)
30+
31+
# create some spans for testing
32+
with tracer.start_span("foo") as foo:
33+
time.sleep(0.1)
34+
foo.set_attribute("my_atribbute", True)
35+
foo.add_event("event in foo", {"name": "foo1"})
36+
with tracer.start_span("bar") as bar:
37+
time.sleep(0.2)
38+
bar.set_attribute("speed", 100.0)
39+
bar.add_link(foo.get_context())
40+
41+
with tracer.start_span("baz") as baz:
42+
time.sleep(0.3)
43+
baz.set_attribute("name", "mauricio")
44+
45+
time.sleep(0.2)
46+
47+
time.sleep(0.1)
48+
49+
# shutdown the span processor
50+
# TODO: this has to be improved so user doesn't need to call it manually
51+
span_processor.shutdown()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2019, 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-jaeger
17+
description = Jaeger Exporter 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-ext-jaeger
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+
thrift >= 0.10.0
43+
opentelemetry-api
44+
opentelemetry-sdk
45+
46+
[options.packages.find]
47+
where = src

ext/opentelemetry-ext-jaeger/setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2019, 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", "jaeger", "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)