-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
…try-python into labelset
- Loading branch information
Showing
60 changed files
with
1,557 additions
and
930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
opentelemetry.ext.opentracing_shim package | ||
========================================== | ||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: opentelemetry.ext.opentracing_shim | ||
:no-show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Examples | ||
This folder contains various examples to demonstrate using OpenTelemetry. | ||
|
||
##### basic_tracer | ||
This example shows how to use OpenTelemetry to instrument an application - e.g. a batch job. | ||
|
||
##### http | ||
This example shows how to use [OpenTelemetryMiddleware](https://github.com/open-telemetry/opentelemetry-python/tree/master/ext/opentelemetry-ext-wsgi) and [requests](https://github.com/open-telemetry/opentelemetry-python/tree/master/ext/opentelemetry-ext-http-requests) integrations to instrument a client and a server. | ||
|
||
##### opentelemetry-example-app | ||
This package is a complete example of an application instrumented with OpenTelemetry. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Overview | ||
|
||
This example shows how to use OpenTelemetry to instrument a Python application - e.g. a batch job. | ||
It supports exporting spans either to the console or to [Jaeger](https://www.jaegertracing.io). | ||
|
||
## Installation | ||
|
||
```sh | ||
$ pip install opentelemetry-api opentelemetry-sdk | ||
``` | ||
|
||
Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/#all-in-one) | ||
|
||
## Run the Application | ||
|
||
### Console | ||
|
||
* Run the sample | ||
|
||
```bash | ||
$ # from this directory | ||
$ python tracer.py | ||
``` | ||
|
||
The output will be displayed at the console | ||
|
||
```bash | ||
AsyncRuntimeContext({'current_span': Span(name="baz", context=SpanContext(trace_id=0xf906f80f64d57c71ea8da4dfbbd2ddf2, span_id=0x5611c1407e06e4d7, trace_state={}))}) | ||
Span(name="baz", context=SpanContext(trace_id=0xf906f80f64d57c71ea8da4dfbbd2ddf2, span_id=0x5611c1407e06e4d7, trace_state={}), kind=SpanKind.INTERNAL, parent=Span(name="bar", context=SpanContext(trace_id=0xf906f80f64d57c71ea8da4dfbbd2ddf2, span_id=0x1b9db0e0cc1a3f60, trace_state={})), start_time=2019-11-07T21:26:45.934412Z, end_time=2019-11-07T21:26:45.934567Z) | ||
Span(name="bar", context=SpanContext(trace_id=0xf906f80f64d57c71ea8da4dfbbd2ddf2, span_id=0x1b9db0e0cc1a3f60, trace_state={}), kind=SpanKind.INTERNAL, parent=Span(name="foo", context=SpanContext(trace_id=0xf906f80f64d57c71ea8da4dfbbd2ddf2, span_id=0x1d5d87441ec2f410, trace_state={})), start_time=2019-11-07T21:26:45.934396Z, end_time=2019-11-07T21:26:45.934576Z) | ||
Span(name="foo", context=SpanContext(trace_id=0xf906f80f64d57c71ea8da4dfbbd2ddf2, span_id=0x1d5d87441ec2f410, trace_state={}), kind=SpanKind.INTERNAL, parent=None, start_time=2019-11-07T21:26:45.934369Z, end_time=2019-11-07T21:26:45.934580Z) | ||
``` | ||
|
||
|
||
### Jaeger | ||
|
||
* Run the sample | ||
|
||
```sh | ||
$ pip install opentelemetry-ext-jaeger | ||
$ # from this directory | ||
$ EXPORTER=jaeger python tracer.py | ||
``` | ||
|
||
#### Jaeger UI | ||
|
||
Open the Jaeger UI in your browser [http://localhost:16686](http://localhost:16686) | ||
|
||
<p align="center"><img src="images/jaeger-ui.png?raw=true"/></p> | ||
Select `basic-service` under *Service Name* and click on *Find Traces*. | ||
|
||
Click on the trace to view its details. | ||
|
||
<p align="center"><img src="./images/jaeger-ui-detail.png?raw=true"/></p> | ||
|
||
## 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> | ||
|
||
## LICENSE | ||
|
||
Apache License 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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 subprocess | ||
import sys | ||
import unittest | ||
|
||
|
||
class TestBasicTracerExample(unittest.TestCase): | ||
def test_basic_tracer(self): | ||
dirpath = os.path.dirname(os.path.realpath(__file__)) | ||
test_script = "{}/../tracer.py".format(dirpath) | ||
output = subprocess.check_output( | ||
(sys.executable, test_script) | ||
).decode() | ||
|
||
self.assertIn('name="foo"', output) | ||
self.assertIn('name="bar"', output) | ||
self.assertIn('name="baz"', output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# 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 | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.context import Context | ||
from opentelemetry.sdk.trace import Tracer | ||
from opentelemetry.sdk.trace.export import ( | ||
BatchExportSpanProcessor, | ||
ConsoleSpanExporter, | ||
) | ||
|
||
if os.getenv("EXPORTER") == "jaeger": | ||
from opentelemetry.ext.jaeger import JaegerSpanExporter | ||
|
||
exporter = JaegerSpanExporter( | ||
service_name="basic-service", | ||
agent_host_name="localhost", | ||
agent_port=6831, | ||
) | ||
else: | ||
exporter = ConsoleSpanExporter() | ||
|
||
# The preferred tracer implementation must be set, as the opentelemetry-api | ||
# defines the interface with a no-op implementation. | ||
trace.set_preferred_tracer_implementation(lambda T: Tracer()) | ||
tracer = trace.tracer() | ||
|
||
# SpanExporter receives the spans and send them to the target location. | ||
span_processor = BatchExportSpanProcessor(exporter) | ||
|
||
tracer.add_span_processor(span_processor) | ||
with tracer.start_as_current_span("foo"): | ||
with tracer.start_as_current_span("bar"): | ||
with tracer.start_as_current_span("baz"): | ||
print(Context) |
Oops, something went wrong.