-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: do not export empty sqs polling spans
- Loading branch information
1 parent
a960fc4
commit a063aa7
Showing
5 changed files
with
73 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AUTO_FILTER_EMPTY_SQS = 'AUTO_FILTER_EMPTY_SQS' |
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,37 @@ | ||
from opentelemetry.trace import Span | ||
from opentelemetry.sdk.trace import ReadableSpan | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
|
||
from lumigo_opentelemetry import logger | ||
|
||
|
||
class LumigoSpanProcessor(BatchSpanProcessor): | ||
|
||
def on_end(self, span: ReadableSpan) -> None: | ||
if should_not_export_span(span): | ||
logger.debug('Not exporting span because it has NO_EXPORT=True attribute') | ||
return | ||
|
||
return super().on_end(span) | ||
|
||
|
||
def should_not_export_span(span: ReadableSpan) -> bool: | ||
""" | ||
Given a span, returns an answer if the span should be exported or not. | ||
@param span: A readable span to check | ||
@return: True if the span should not be exported, False otherwise | ||
""" | ||
return span.attributes.get('NO_EXPORT') is True | ||
|
||
|
||
def set_span_no_export(span: Span, no_export: bool = True): | ||
""" | ||
marks the span as a span not intended for export (for example in spans that create a lot of noise and customers | ||
do not want to trace) | ||
@param span: The span to mark (The span is altered in place) | ||
@param no_export: Should the span be exported or not (default is True, the span will not be exported) | ||
@return: | ||
""" | ||
|
||
span.set_attributes({'NO_EXPORT': no_export}) |