- Notifications
You must be signed in to change notification settings - Fork 235
opentelemetry bridge #1411
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
Merged
Merged
opentelemetry bridge #1411
Changes from 5 commits
Commits
Show all changes
46 commits Select commit Hold shift + click to select a range
3ec54a9 Add class stubs for otel bridge
basepi 2713b13 Switch execution_context to use stacks and store span extra data
basepi 2e6b3d4 Add stub for span.py
basepi 781dc51 Switch to tuples for execution_context
basepi e44e195 Switch span ending to unset_span instead of setting parent
basepi f7810b6 Update elasticapm/context/contextvars.py
basepi 2bbc87c Use `with_extra` when fetching spans
basepi 9bbd996 Implement otel Span wrapper
basepi 4da03fd More Tracer work
basepi 1db14bc Transaction creation + utils
basepi 00b2696 Handle transaction activation/deactivation
basepi 2c43687 Add context api
basepi 7776f67 Remove `extra` from execution_context
basepi 11bb7f4 Simplify to make Hound happy
basepi 649aac5 Handle SpanKind + otel attributes properly
basepi a0c08fe Add transaction type inference
basepi 477ae51 Add span type/subtype
basepi 3b10883 Handle otel attributes for exceptions
basepi d62ce9a Handle end_time for otel spans
basepi f99f6ac Handle tracestate and traceflags
basepi b6a33fd Handle set_status_on_exception
basepi 55b65ae Handle remote tracestate
basepi 360e89b Instrument on Tracer instantiation
basepi 108361d Merge remote-tracking branch 'upstream/main' into otel
basepi cbcd719 Add first test (and many fixes for it)
basepi b8b1f32 Remove compat
basepi 4bb37d3 Fix other failing tests
basepi 513278e Add another test (plus more fixes)
basepi 27d3fcf Merge remote-tracking branch 'upstream/main' into otel
basepi 2678177 Remove contextvars/threadlocal test for py3.6
basepi cd15f03 Don't make Tracer a singleton (should fix tests?)
basepi 6031d8b Add test for spans without auto-attach
basepi f2d2754 Rename otel_tests.py to tests.py
basepi 9e9ea9c Add more tests
basepi 2e0c2ea Docs + a couple of changes to more closely match opentracing bridge
basepi 5fc8c0d Merge remote-tracking branch 'upstream/main' into otel
basepi a6bbc37 Deprecate opentracing bridge
basepi bff1d31 More docs
basepi b29b2ce Move opentelemetry to its own matrix
basepi bd74132 Merge remote-tracking branch 'upstream/main' into otel
basepi 8ff7fcd Merge branch 'main' into otel
basepi 0d934a2 Review comments for context.py
basepi dfb6534 Reintroduce test_execution_context_backing
basepi e3e2fc3 Fix a typo
basepi b9ff8d6 Add note about extra get_client() check
basepi 8343fc9 Use `end_time` correctly
basepi 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
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
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
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,33 @@ | ||
| # BSD 3-Clause License | ||
| # | ||
| # Copyright (c) 2019, Elasticsearch BV | ||
| # All rights reserved. | ||
| # | ||
| # Redistribution and use in source and binary forms, with or without | ||
| # modification, are permitted provided that the following conditions are met: | ||
| # | ||
| # * Redistributions of source code must retain the above copyright notice, this | ||
| # list of conditions and the following disclaimer. | ||
| # | ||
| # * Redistributions in binary form must reproduce the above copyright notice, | ||
| # this list of conditions and the following disclaimer in the documentation | ||
| # and/or other materials provided with the distribution. | ||
| # | ||
| # * Neither the name of the copyright holder nor the names of its | ||
| # contributors may be used to endorse or promote products derived from | ||
| # this software without specific prior written permission. | ||
| # | ||
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| | ||
| | ||
| def get_tracer(name): | ||
| pass |
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,123 @@ | ||
| # BSD 3-Clause License | ||
| # | ||
| # Copyright (c) 2019, Elasticsearch BV | ||
| # All rights reserved. | ||
| # | ||
| # Redistribution and use in source and binary forms, with or without | ||
| # modification, are permitted provided that the following conditions are met: | ||
| # | ||
| # * Redistributions of source code must retain the above copyright notice, this | ||
| # list of conditions and the following disclaimer. | ||
| # | ||
| # * Redistributions in binary form must reproduce the above copyright notice, | ||
| # this list of conditions and the following disclaimer in the documentation | ||
| # and/or other materials provided with the distribution. | ||
| # | ||
| # * Neither the name of the copyright holder nor the names of its | ||
| # contributors may be used to endorse or promote products derived from | ||
| # this software without specific prior written permission. | ||
| # | ||
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| | ||
| import types as python_types | ||
| import typing | ||
| | ||
| from opentelemetry import trace as oteltrace | ||
| from opentelemetry.trace.span import SpanContext | ||
| from opentelemetry.trace.status import Status | ||
| from opentelemetry.util import types | ||
| | ||
| | ||
| class Span(oteltrace.Span): | ||
| """A span represents a single operation within a trace.""" | ||
| | ||
| def end(self, end_time: typing.Optional[int] = None) -> None: | ||
| """Sets the current time as the span's end time. | ||
| The span's end time is the wall time at which the operation finished. | ||
| Only the first call to `end` should modify the span, and | ||
| implementations are free to ignore or raise on further calls. | ||
| """ | ||
| | ||
| def get_span_context(self) -> "SpanContext": | ||
| """Gets the span's SpanContext. | ||
| Get an immutable, serializable identifier for this span that can be | ||
| used to create new child spans. | ||
| Returns: | ||
| A :class:`opentelemetry.trace.SpanContext` with a copy of this span's immutable state. | ||
| """ | ||
| | ||
| def set_attributes(self, attributes: typing.Dict[str, types.AttributeValue]) -> None: | ||
| """Sets Attributes. | ||
| Sets Attributes with the key and value passed as arguments dict. | ||
| Note: The behavior of `None` value attributes is undefined, and hence strongly discouraged. | ||
| """ | ||
| | ||
| def set_attribute(self, key: str, value: types.AttributeValue) -> None: | ||
| """Sets an Attribute. | ||
| Sets a single Attribute with the key and value passed as arguments. | ||
| Note: The behavior of `None` value attributes is undefined, and hence strongly discouraged. | ||
| """ | ||
| | ||
| def add_event( | ||
| self, | ||
| name: str, | ||
| attributes: types.Attributes = None, | ||
| timestamp: typing.Optional[int] = None, | ||
| ) -> None: | ||
| """Adds an `Event`. | ||
| Adds a single `Event` with the name and, optionally, a timestamp and | ||
| attributes passed as arguments. Implementations should generate a | ||
| timestamp if the `timestamp` argument is omitted. | ||
| """ | ||
| | ||
| def update_name(self, name: str) -> None: | ||
| """Updates the `Span` name. | ||
| This will override the name provided via :func:`opentelemetry.trace.Tracer.start_span`. | ||
| Upon this update, any sampling behavior based on Span name will depend | ||
| on the implementation. | ||
| """ | ||
| | ||
| def is_recording(self) -> bool: | ||
| """Returns whether this span will be recorded. | ||
| Returns true if this Span is active and recording information like | ||
| events with the add_event operation and attributes using set_attribute. | ||
| """ | ||
| | ||
| def set_status(self, status: Status) -> None: | ||
| """Sets the Status of the Span. If used, this will override the default | ||
| Span status. | ||
| """ | ||
| | ||
| def record_exception( | ||
| self, | ||
| exception: Exception, | ||
| attributes: types.Attributes = None, | ||
| timestamp: typing.Optional[int] = None, | ||
| escaped: bool = False, | ||
| ) -> None: | ||
| """Records an exception as a span event.""" | ||
| | ||
| def __enter__(self) -> "Span": | ||
| """Invoked when `Span` is used as a context manager. | ||
| Returns the `Span` itself. | ||
| """ | ||
| return self | ||
| | ||
| def __exit__( | ||
| self, | ||
| exc_type: typing.Optional[typing.Type[BaseException]], | ||
| exc_val: typing.Optional[BaseException], | ||
| exc_tb: typing.Optional[python_types.TracebackType], | ||
| ) -> None: | ||
| """Ends context manager and calls `end` on the `Span`.""" | ||
| | ||
| self.end() |
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.
Uh oh!
There was an error while loading. Please reload this page.