-
Notifications
You must be signed in to change notification settings - Fork 649
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
sdk: add Exporter interface, SimpleSpanProcessor and InMemorySpanExporter #119
sdk: add Exporter interface, SimpleSpanProcessor and InMemorySpanExporter #119
Conversation
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py
Outdated
Show resolved
Hide resolved
423346a
to
fc0bfd9
Compare
Given that we are already talking about names, should it be called |
I'd suggest On a related note, maybe we need to update this Specification part ;) |
Sorry Carlos, I think go is also using |
+1 for SpanExporter (I have no strong opinion though) |
fc0bfd9
to
624ac51
Compare
Oh, interesting. Go used to use |
72d2031
to
e864c58
Compare
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'm approving this already to speed things up, but the logging issue should really be fixed before merging.
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py
Outdated
Show resolved
Hide resolved
3f2f63e
to
139e960
Compare
I pushed a new commit to expose span members using properties. @Oberon00 I kindly as you to check if your approval is still valid after this update. |
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.
3d8f4fa seems like it belongs in a different PR, but I have no blocking comments otherwise. It SGTM to merge this and change the relationship between processors and exporters in another PR as needed.
""" | ||
|
||
|
||
class SimpleExportSpanProcessor(SpanProcessor): |
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.
Why put this in the export
module instead of with other processors?
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.
This SimpleExportSpanProcessor
is strictly related to the exporters it is the glue code between SpanProcessor
and Exporter
. For this reason I decided to place it there.
self.span_exporter = span_exporter | ||
|
||
def on_start(self, span: Span) -> None: | ||
pass # do nothing |
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.
Nit: I think it's a safe bet that people will know that pass
does nothing.
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.
Definitely it is.
"""Implementation of :class:`.Exporter` that stores spans in memory. | ||
|
||
This class can be used for testing purposes. It stores the exported spans | ||
in a list in memory that can be retrieve using the |
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.
in a list in memory that can be retrieve using the | |
in a list in memory that can be retrieved using the |
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.
Done.
def export(self, spans: typing.Sequence[Span]) -> SpanExportResult: | ||
"""Stores a list of spans in memory.""" | ||
if self._stopped: | ||
return SpanExportResult.FAILED_NOT_RETRYABLE |
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.
We say that the API shouldn't prescribe throwing exceptions, and that implementations of the API shouldn't throw either, but what about methods like this that only exist in the SDK? This does look like the right approach to me, but I don't know why exporters and processors aren't in the API in the first place.
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.
They aren't in the API because if you create a specialized implementation of the API, you probably won't need to provide as much customization as the generic SDK. At least that's my understanding.
|
||
@property | ||
def parent(self) -> trace_api.ParentSpan: | ||
return self._parent |
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.
3d8f4fa looks to me like a lot of boilerplate for little value. Should every attribute in the SDK be hidden behind a property? If the property decorator signals that the attribute is meant to be read-only, should name
be a regular attribute since there's a trivial setter? What about the attributes without getters here?
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'm also not a fan of such trivial Java-like boilerplate properties.
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.
OK, I am removing that then. For now we'll keep passing the the whole Span
to the exporters, later on we can improve it by passing a readonly span, a SpanView or something similar.
|
||
|
||
class SimpleExportSpanProcessor(SpanProcessor): | ||
"""An implementation of `SpanProcessor` that passes ended spans directly |
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.
Style nit: I think it helps readability for docstrings to have a short first line and longer wrapping text in another line below.
From #61 (review):
"""A short, single-line description of the function.
A longer description that may include :class:`.SphinxStuff` and can wrap
and wrap and wrap.
Args:
arg: Short description, no need to include the type.
Returns:
The thing we return, or "Yields:" for context managers.
"""
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.
Done!. Thanks.
Exporter is an interface that allows different services to export recorded spans in its own format. SimpleExportSpanProcessor is an implementation of SpanProcessor that passes ended spans directly to a configured Exporter. The current interface for exporters directly receives an SDK Span, it could be improved in the future to receive a different object containing a representation of the Span.
InMemorySpanExporter is a simple implementation of the Exporter interface that saves the exported spans in a list in memory. This class is useful for testing purposes.
3d8f4fa
to
f4ef8eb
Compare
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.
Due to the force push, I have no idea what actually changed, but I see that the span properties have been removed, so I re-approve, trusting that the force push changed nothing else of relevance.
This PR is a follow up of #115
It adds the
Exporter
interface, theSimpleSpanProcessor
as described in the specs: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-exporter.md and anInMemorySpanExporter
class that implements the interface and saves Spans in a list.The following is an example of how the
SpanExporter
interface could be used:Finally, the following is an example of the
InMemorySpanExporter
usage: