Skip to content

Commit b10204a

Browse files
authored
Merge branch 'develop-hybrid-core-tracing' into hybrid-agent-wsgi-traces
2 parents c60fdaf + 2eebf4f commit b10204a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

newrelic/api/opentelemetry.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ def __exit__(self, exc_type, exc_val, exc_tb):
384384

385385
super().__exit__(exc_type, exc_val, exc_tb)
386386

387+
def __exit__(self, exc_type, exc_val, exc_tb):
388+
"""
389+
Ends context manager and calls `end` on the `Span`.
390+
This is used when span is called as a context manager
391+
i.e. `with tracer.start_span() as span:`
392+
"""
393+
if exc_val and self.is_recording():
394+
if self._record_exception:
395+
self.record_exception(exception=exc_val, escaped=True)
396+
if self.set_status_on_exception:
397+
self.set_status(Status(status_code=StatusCode.ERROR, description=f"{exc_type.__name__}: {exc_val}"))
398+
399+
super().__exit__(exc_type, exc_val, exc_tb)
400+
387401

388402
class Tracer(otel_api_trace.Tracer):
389403
def __init__(self, resource=None, instrumentation_library=None, *args, **kwargs):

tests/hybridagent_opentelemetry/test_status.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,4 @@ def _test():
193193
if span.status.status_code == StatusCode.ERROR:
194194
assert span.status.description in [None, "This is where I belong"]
195195

196-
197196
_test()

0 commit comments

Comments
 (0)