-
Notifications
You must be signed in to change notification settings - Fork 848
Add stackdriver trace exporter #288
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
75e3653
Add stackdriver trace exporter
clsung 850d12a
pat py3.4
clsung 3cbc0f2
pat py3.4
clsung 086d5eb
missing item
clsung 3b43730
black
clsung 3fb85da
fix by review
clsung caa3847
enrich exception, remove unused imports
clsung d4d3806
fix conflict
clsung f88135b
refine test
clsung 54896ef
fix example
clsung 0dff8bc
fix README
clsung 6b9b68c
remove span initialization in grpc
clsung e1b07e7
remove OC header, file has changed a lot
clsung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,44 @@ | ||
| OpenTelemetry Stackdriver Exporters | ||
| ===================================== | ||
|
|
||
| This library provides integration with Google Cloud Stackdriver. | ||
|
|
||
| Installation | ||
| ------------ | ||
|
|
||
| :: | ||
|
|
||
| pip install opentelemetry-ext-stackdriver | ||
|
|
||
| Usage | ||
| ----- | ||
|
|
||
| .. code:: python | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.ext import stackdriver | ||
| 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 StackdriverSpanExporter | ||
| stackdriver_exporter = stackdriver.trace.StackdriverSpanExporter( | ||
| project_id='my-helloworld-project', | ||
| ) | ||
|
|
||
| # Create a BatchExportSpanProcessor and add the exporter to it | ||
| span_processor = BatchExportSpanProcessor(stackdriver_exporter) | ||
|
|
||
| # add to the tracer | ||
| tracer.add_span_processor(span_processor) | ||
|
|
||
| with tracer.start_as_current_span('foo'): | ||
| print('Hello world!') | ||
|
|
||
| References | ||
| ---------- | ||
|
|
||
| * `Stackdriver <https://cloud.google.com/stackdriver/>`_ | ||
| * `OpenTelemetry Project <https://opentelemetry.io/>`_ |
This file contains hidden or 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,32 @@ | ||
| # 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 requests | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.ext import http_requests | ||
| from opentelemetry.ext.stackdriver.trace import StackdriverSpanExporter | ||
| from opentelemetry.sdk.trace import Tracer | ||
| from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor | ||
|
|
||
| trace.set_preferred_tracer_implementation(lambda T: Tracer()) | ||
| tracer = trace.tracer() | ||
| span_processor = SimpleExportSpanProcessor( | ||
| StackdriverSpanExporter(project_id="my-helloworld-project") | ||
| ) | ||
| tracer.add_span_processor(span_processor) | ||
|
|
||
| http_requests.enable(tracer) | ||
| response = requests.get(url="http://localhost:7777/hello") | ||
| span_processor.shutdown() | ||
This file contains hidden or 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,44 @@ | ||
| # 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 flask | ||
| import requests | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.ext import http_requests | ||
| from opentelemetry.ext.stackdriver.trace import StackdriverSpanExporter | ||
| from opentelemetry.ext.wsgi import OpenTelemetryMiddleware | ||
| from opentelemetry.sdk.trace import Tracer | ||
| from opentelemetry.sdk.trace.export import BatchExportSpanProcessor | ||
|
|
||
| trace.set_preferred_tracer_implementation(lambda T: Tracer()) | ||
|
|
||
| span_processor = BatchExportSpanProcessor(StackdriverSpanExporter()) | ||
| http_requests.enable(trace.tracer()) | ||
| trace.tracer().add_span_processor(span_processor) | ||
|
|
||
| app = flask.Flask(__name__) | ||
| app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app) | ||
|
|
||
|
|
||
| @app.route("/") | ||
| def hello(): | ||
| with trace.tracer().start_as_current_span("parent"): | ||
| requests.get("https://www.wikipedia.org/wiki/Rabbit") | ||
| return "hello" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run(debug=True) | ||
| span_processor.shutdown() |
This file contains hidden or 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,25 @@ | ||
| # 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. | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.ext.stackdriver.trace import StackdriverSpanExporter | ||
| from opentelemetry.sdk.trace import Tracer | ||
| from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor | ||
|
|
||
| trace.set_preferred_tracer_implementation(lambda T: Tracer()) | ||
| tracer = trace.tracer() | ||
| tracer.add_span_processor(SimpleExportSpanProcessor(StackdriverSpanExporter())) | ||
|
|
||
| with tracer.start_as_current_span("hello") as span: | ||
| print("Hello, World!") |
This file contains hidden or 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,48 @@ | ||
| # 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-stackdriver | ||
| description = Stackdriver integration 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-stackdriver | ||
| 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 = | ||
| opentelemetry-api | ||
| opentelemetry-sdk | ||
| google-cloud-monitoring | ||
| google-cloud-trace | ||
|
|
||
| [options.packages.find] | ||
| where = src |
This file contains hidden or 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,26 @@ | ||
| # 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 | ||
|
|
||
| BASE_DIR = os.path.dirname(__file__) | ||
| VERSION_FILENAME = os.path.join( | ||
| BASE_DIR, "src", "opentelemetry", "ext", "stackdriver", "version.py" | ||
| ) | ||
| PACKAGE_INFO = {} | ||
| with open(VERSION_FILENAME) as f: | ||
| exec(f.read(), PACKAGE_INFO) | ||
|
|
||
| setuptools.setup(version=PACKAGE_INFO["__version__"]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I believe that this should use Named tracers work from #301. Examples in other places: Here or here.