-
Notifications
You must be signed in to change notification settings - Fork 683
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
add Jaeger exporter #174
add Jaeger exporter #174
Changes from 10 commits
6124eea
515527e
3bc29a2
f32aee8
6b93079
3d2f089
11cac7c
fd91817
a0e3402
93e49f1
3b6872a
88e02b4
6de0518
b40a30f
508e166
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[flake8] | ||
ignore = E501,W503,E203 | ||
exclude = .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,ext/opentelemetry-ext-jaeger/build/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
OpenTelemetry Jaeger Exporter | ||
============================= | ||
|
||
Installation | ||
------------ | ||
|
||
:: | ||
|
||
pip install opentelemetry-ext-jaeger | ||
|
||
|
||
Usage | ||
----- | ||
|
||
The **OpenTelemetry Jaeger Exporter** allows to export `OpenTelemetry`_ traces to `Jaeger`_. | ||
This exporter always send traces to the configured agent using Thrift compact protocol over UDP. | ||
An optional collector can be configured, in this case Thrift binary protocol over HTTP is used. | ||
gRPC is still not supported by this implementation. | ||
|
||
|
||
.. _Jaeger: https://www.jaegertracing.io/ | ||
.. _OpenTelemetry: https://github.com/opentelemetry/opentelemetry-python/ | ||
|
||
.. code:: python | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.ext import jaeger | ||
from opentelemetry.sdk.trace import Tracer | ||
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor | ||
|
||
trace.set_preferred_tracer_implementation(lambda T: Tracer()) | ||
tracer = trace.tracer() | ||
|
||
# create a JaegerSpanExporter | ||
jaeger_exporter = jaeger.JaegerSpanExporter( | ||
service_name='my-helloworld-service', | ||
# configure agent | ||
agent_host_name='localhost', | ||
agent_port=6831, | ||
# optional: configure also collector | ||
# collector_host_name='localhost', | ||
# collector_port=14268, | ||
# collector_endpoint='/api/traces?format=jaeger.thrift', | ||
# username=xxxx, # optional | ||
# password=xxxx, # optional | ||
) | ||
|
||
# Create a BatchExportSpanProcessor and add the exporter to it | ||
span_processor = BatchExportSpanProcessor(jaeger_exporter) | ||
|
||
# add to the tracer | ||
tracer.add_span_processor(span_processor) | ||
|
||
with tracer.start_span('foo'): | ||
print('Hello world!') | ||
|
||
# shutdown the span processor | ||
# TODO: this has to be improved so user doesn't need to call it manually | ||
span_processor.shutdown() | ||
|
||
The `examples <./examples>`_ folder contains more elaborated examples. | ||
|
||
References | ||
---------- | ||
|
||
* `Jaeger <https://www.jaegertracing.io/>`_ | ||
* `OpenTelemetry Project <https://opentelemetry.io/>`_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import time | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.ext import jaeger | ||
from opentelemetry.sdk.trace import Tracer | ||
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor | ||
|
||
trace.set_preferred_tracer_implementation(lambda T: Tracer()) | ||
tracer = trace.tracer() | ||
|
||
# create a JaegerSpanExporter | ||
jaeger_exporter = jaeger.JaegerSpanExporter( | ||
service_name="my-helloworld-service", | ||
# configure agent | ||
agent_host_name="localhost", | ||
agent_port=6831, | ||
# optional: configure also collector | ||
# collector_host_name="localhost", | ||
# collector_port=14268, | ||
# collector_endpoint="/api/traces?format=jaeger.thrift", | ||
# username=xxxx, # optional | ||
# password=xxxx, # optional | ||
) | ||
|
||
# create a BatchExportSpanProcessor and add the exporter to it | ||
span_processor = BatchExportSpanProcessor(jaeger_exporter) | ||
|
||
# add to the tracer | ||
tracer.add_span_processor(span_processor) | ||
|
||
# create some spans for testing | ||
with tracer.start_span("foo") as foo: | ||
time.sleep(0.1) | ||
foo.set_attribute("my_atribbute", True) | ||
foo.add_event("event in foo", {"name": "foo1"}) | ||
with tracer.start_span("bar") as bar: | ||
time.sleep(0.2) | ||
bar.set_attribute("speed", 100.0) | ||
bar.add_link(foo.get_context()) | ||
|
||
with tracer.start_span("baz") as baz: | ||
time.sleep(0.3) | ||
baz.set_attribute("name", "mauricio") | ||
|
||
time.sleep(0.2) | ||
|
||
time.sleep(0.1) | ||
|
||
# shutdown the span processor | ||
# TODO: this has to be improved so user doesn't need to call it manually | ||
span_processor.shutdown() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2019, 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-jaeger | ||
description = Jaeger Exporter 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-ext-jaeger | ||
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 = | ||
thrift >= 0.10.0 | ||
opentelemetry-api | ||
opentelemetry-sdk | ||
|
||
[options.packages.find] | ||
where = src |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2019, 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 | ||
from setuptools.command.install import install | ||
|
||
BASE_DIR = os.path.dirname(__file__) | ||
VERSION_FILENAME = os.path.join( | ||
BASE_DIR, "src", "opentelemetry", "ext", "jaeger", "version.py" | ||
) | ||
PACKAGE_INFO = {} | ||
with open(VERSION_FILENAME) as f: | ||
exec(f.read(), PACKAGE_INFO) | ||
|
||
BASE_CMD = """docker run --user `id -u` -v "$PWD:/data" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds an install-time dependency on docker? That is a pretty big dependency. Also it looks like the install depends on the pwd being the dir that includes
I understand not wanting to check in the generated thrift files, but we should consider generating them before releases instead. As it is now, a user would have to have |
||
thrift:0.10.0 thrift \ | ||
-out /data/build/lib/opentelemetry/ext/jaeger/gen/ \ | ||
--gen py /data/thrift/{} | ||
""" | ||
|
||
init_py_str = """ | ||
import sys | ||
from os.path import dirname | ||
sys.path.append(dirname(__file__)) | ||
""" | ||
|
||
|
||
def gen_thrift(path): | ||
os.system(BASE_CMD.format(path)) | ||
|
||
|
||
class JaegerInstallCommand(install): | ||
"""Generates Jaeger thrift files before installing""" | ||
|
||
def run(self): | ||
path = "build/lib/opentelemetry/ext/jaeger/gen" | ||
os.makedirs(path, exist_ok=True) | ||
|
||
with open(path + "/__init__.py", "w") as init_py_f: | ||
init_py_f.write(init_py_str) | ||
|
||
gen_thrift("agent.thrift") | ||
gen_thrift("zipkincore.thrift") | ||
gen_thrift("jaeger.thrift") | ||
|
||
install.run(self) | ||
|
||
|
||
setuptools.setup( | ||
version=PACKAGE_INFO["__version__"], | ||
cmdclass={"install": JaegerInstallCommand}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: this link is incorrect. it should be open-telemetry for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!, I think I'm contributor number one with more typos done...
Will be solved in #289.