From fb2595d2fbf4935c169c561aaf169bab3c527e9a Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Wed, 5 Jan 2022 10:23:10 -0700 Subject: [PATCH] Do not attempt to end a span if ctx wasn't found (#59) * Do not attempt to end a span if ctx is undefined --- utilities/opentelemetry_telemetry/CHANGELOG.md | 6 ++++++ .../opentelemetry_telemetry/src/otel_telemetry.erl | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/utilities/opentelemetry_telemetry/CHANGELOG.md b/utilities/opentelemetry_telemetry/CHANGELOG.md index c5abb3f..1b03d80 100644 --- a/utilities/opentelemetry_telemetry/CHANGELOG.md +++ b/utilities/opentelemetry_telemetry/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +* Do not attempt to end a span with if the ctx is undefined. + ## 1.0.0-beta.7 ### Changes diff --git a/utilities/opentelemetry_telemetry/src/otel_telemetry.erl b/utilities/opentelemetry_telemetry/src/otel_telemetry.erl index f4a47e9..16dff82 100644 --- a/utilities/opentelemetry_telemetry/src/otel_telemetry.erl +++ b/utilities/opentelemetry_telemetry/src/otel_telemetry.erl @@ -56,10 +56,15 @@ set_current_telemetry_span(TracerId, EventMetadata) -> -spec end_telemetry_span(atom(), telemetry:event_metadata()) -> ok. end_telemetry_span(TracerId, EventMetadata) -> - {ParentCtx, Ctx} = pop_ctx(TracerId, EventMetadata), - otel_span:end_span(Ctx), - otel_tracer:set_current_span(ParentCtx), - ok. + Ctx = pop_ctx(TracerId, EventMetadata), + case Ctx of + {ParentCtx, SpanCtx} -> + otel_span:end_span(SpanCtx), + otel_tracer:set_current_span(ParentCtx), + ok; + undefined -> + ok + end. -spec store_ctx(ctx_set(), atom(), telemetry:event_metadata()) -> ok. store_ctx(SpanCtxSet, TracerId, EventMetadata) ->