-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69f9114
commit aefdfd9
Showing
17 changed files
with
617 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Basic Trace | ||
=========== | ||
|
||
These examples show how to use OpenTelemetry to create and export Spans. | ||
|
||
There are two different examples: | ||
|
||
* basic_trace: Shows how to configure a SpanProcessor and Exporter, and how to create a tracer and span. | ||
|
||
* resources: Shows how to add resource information to a Provider. Note that this must be run on a Google Compute Engine instance. | ||
|
||
The source files of these examples are available :scm_web:`here <docs/examples/basic_tracer/>`. | ||
|
||
Installation | ||
------------ | ||
|
||
.. code-block:: sh | ||
pip install opentelemetry-api | ||
pip install opentelemetry-sdk | ||
Run the Example | ||
--------------- | ||
|
||
.. code-block:: sh | ||
python <example_name>.py | ||
The output will be shown in the console. | ||
|
||
Useful links | ||
------------ | ||
|
||
- OpenTelemetry_ | ||
- :doc:`../../api/trace` | ||
|
||
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ |
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,14 @@ | ||
from opentelemetry import trace | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import ( | ||
ConsoleSpanExporter, | ||
SimpleExportSpanProcessor, | ||
) | ||
|
||
trace.set_tracer_provider(TracerProvider()) | ||
trace.get_tracer_provider().add_span_processor( | ||
SimpleExportSpanProcessor(ConsoleSpanExporter()) | ||
) | ||
tracer = trace.get_tracer(__name__) | ||
with tracer.start_as_current_span("foo"): | ||
print("Hello world!") |
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,19 @@ | ||
from opentelemetry import trace | ||
from opentelemetry.sdk.resources import get_aggregated_resources | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import ( | ||
ConsoleSpanExporter, | ||
SimpleExportSpanProcessor, | ||
) | ||
from opentelemetry.tools.resource_detector import GoogleCloudResourceDetector | ||
|
||
resources = get_aggregated_resources([GoogleCloudResourceDetector()]) | ||
|
||
trace.set_tracer_provider(TracerProvider(resource=resources)) | ||
|
||
trace.get_tracer_provider().add_span_processor( | ||
SimpleExportSpanProcessor(ConsoleSpanExporter()) | ||
) | ||
tracer = trace.get_tracer(__name__) | ||
with tracer.start_as_current_span("foo"): | ||
print("Hello world!") |
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
Oops, something went wrong.