Skip to content
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

Support partial timelimit for celery tasks #847

Merged
merged 7 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `opentelemetry-instrumentation-flask` Flask: Conditionally create SERVER spans
([#828](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/828))
- `opentelemetry-instrumentation-celery` Celery: Support partial task time limit
([#846](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/846))

- `opentelemetry-instrumentation-asgi` ASGI: Conditionally create SERVER spans
([#843](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/843))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ def set_attributes_from_context(span, context):

# Skip `timelimit` if it is not set (it's default/unset value is a
# tuple or a list of `None` values
if key == "timelimit" and value in [(None, None), [None, None]]:
continue
if key == "timelimit":
if value in [(None, None), [None, None]]:
continue
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
if None in value:
value = ["" if tl is None else tl for tl in value]

# Skip `retries` if it's value is `0`
if key == "retries" and value == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,46 @@ def test_set_attributes_not_recording(self):
self.assertFalse(mock_span.set_attribute.called)
self.assertFalse(mock_span.set_status.called)

def test_set_attributes_partial_timelimit_hard_limit(self):
# it should extract only relevant keys
context = {
"correlation_id": "44b7f305",
"delivery_info": {"eager": True},
"eta": "soon",
"expires": "later",
"hostname": "localhost",
"id": "44b7f305",
"reply_to": "44b7f305",
"retries": 4,
"timelimit": ("now", None),
"custom_meta": "custom_value",
"routing_key": "celery",
}
span = trace._Span("name", mock.Mock(spec=trace_api.SpanContext))
utils.set_attributes_from_context(span, context)
self.assertEqual(span.attributes.get("celery.timelimit"), ("now", ""))

def test_set_attributes_partial_timelimit_soft_limit(self):
# it should extract only relevant keys
context = {
"correlation_id": "44b7f305",
"delivery_info": {"eager": True},
"eta": "soon",
"expires": "later",
"hostname": "localhost",
"id": "44b7f305",
"reply_to": "44b7f305",
"retries": 4,
"timelimit": (None, "later"),
"custom_meta": "custom_value",
"routing_key": "celery",
}
span = trace._Span("name", mock.Mock(spec=trace_api.SpanContext))
utils.set_attributes_from_context(span, context)
self.assertEqual(
span.attributes.get("celery.timelimit"), ("", "later")
)

def test_set_attributes_from_context_empty_keys(self):
# it should not extract empty keys
context = {
Expand Down