diff --git a/CHANGELOG.md b/CHANGELOG.md index e9120929bc..3fd85a7f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `opentelemetry-instrumentation-celery` Record exceptions as events on the span. + ([#1573](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1573)) - Add metric instrumentation for urllib ([#1553](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1553)) - `opentelemetry/sdk/extension/aws` Implement [`aws.ecs.*`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/cloud_provider/aws/ecs.md) and [`aws.logs.*`](https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/cloud_provider/aws/logs/) resource attributes in the `AwsEcsResourceDetector` detector when the ECS Metadata v4 is available diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 6d79f45115..c6a7540ccd 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -250,6 +250,7 @@ def _trace_failure(*args, **kwargs): if ex is not None: status_kwargs["description"] = str(ex) + span.record_exception(ex) span.set_status(Status(**status_kwargs)) @staticmethod diff --git a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py index 4cdf3718fe..1a86154ffc 100644 --- a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py +++ b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py @@ -249,6 +249,7 @@ def fn_task_parameters(user, force_logout=False): run_span.attributes.get("celery.task_name") == "test_celery_functional.fn_task_parameters" ) + assert len(run_span.events) == 0 def test_fn_exception(celery_app, memory_exporter): @@ -275,6 +276,11 @@ def fn_exception(): == "test_celery_functional.fn_exception" ) assert span.status.status_code == StatusCode.ERROR + assert len(span.events) == 1 + event = span.events[0] + assert event.name == "exception" + assert event.attributes[SpanAttributes.EXCEPTION_TYPE] == "ExceptionInfo" + assert SpanAttributes.EXCEPTION_MESSAGE in event.attributes assert ( span.attributes.get(SpanAttributes.MESSAGING_MESSAGE_ID) == result.task_id