Open MartinWolke opened 1 year ago
Hi @MartinWolke ,
I can't reproduce this error on my linux environment with Julia@v1.9.0 . This error seems to be found in several issues in the Julia repo:
https://github.com/JuliaLang/julia/issues?q=is%3Aissue+physreg+is%3Aclosed
So I'm tagging @vtjnash here. Maybe Jameson is familiar with such errors.
Hi @findmyway ,
thanks for checking this out! That's very interesting; Maybe it's something particular to the Linux versions or the Python versions that I was using. I'll have a look and try different setups and document my findings here.
I was able to narrow down the point at which Julia crashes:
using OpenTelemetry
using OpenTelemetry.OpenTelemetryAPI
using OpenTelemetry.OpenTelemetrySDK
using PythonCall
tracer = Tracer()
span = OpenTelemetryAPI.create_span("foo", tracer)
# this works
span.status[] = OpenTelemetryAPI.SpanStatus(
OpenTelemetryAPI.SPAN_STATUS_ERROR, nothing
)
## this works, too
function foo(status)
return span.status[] = status
end
status = OpenTelemetryAPI.SpanStatus(
OpenTelemetryAPI.SPAN_STATUS_ERROR, nothing
)
foo(status)
## this crashes Julia
function foo(s, code, description=nothing)
return s.status[] = OpenTelemetryAPI.SpanStatus(code, description)
end
foo(span, OpenTelemetryAPI.SPAN_STATUS_ERROR)
I have no clue why the last example crashes Julia while the prior ones do not. Tested with:
Julia Version 1.9.1
Commit 147bdf428cd (2023-06-07 08:27 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 32 × Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, icelake-server)
Threads: 1 on 32 virtual cores
and
Julia Version 1.9.0
Commit 8e630552924 (2023-05-07 11:25 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 2 × Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, broadwell)
Threads: 1 on 2 virtual cores
With this information, I tried the following code which seems to work for me:
function my_span_status!(
span::OpenTelemetrySDK.Span, status::OpenTelemetryAPI.SpanStatus
)
if OpenTelemetryAPI.is_recording(span)
if span.status[].code === OpenTelemetryAPI.SPAN_STATUS_OK
# no further updates
else
if code === OpenTelemetryAPI.SPAN_STATUS_UNSET
# ignore
else
span.status[] = status
end
end
else
@warn "the span is not recording."
end
end
function OpenTelemetryAPI.with_span(
f::Function,
name::String,
tracer::OpenTelemetryAPI.Tracer=OpenTelemetryAPI.Tracer();
end_on_exit=true,
record_exception=true,
set_status_on_exception=true,
kw...,
)
s = OpenTelemetryAPI.create_span(name, tracer; kw...)
OpenTelemetryAPI.with_context(;
OpenTelemetryAPI.SPAN_KEY_IN_CONTEXT => s
) do
try
f()
catch ex
if OpenTelemetryAPI.is_recording(s)
if record_exception
push!(s, ex; is_rethrow_followed=true)
end
if set_status_on_exception
status = OpenTelemetryAPI.SpanStatus(
OpenTelemetryAPI.SPAN_STATUS_ERROR, string(ex)
)
my_span_status!(s, status)
end
end
rethrow(ex)
finally
if end_on_exit
OpenTelemetryAPI.end_span!(s)
end
end
end
end
I get an assertion error in codegen on this, so it is like a Julia bug. I see there is a package being used (by PythonCall) called UnsafePointers, and inference is accidentally inferring it might be used on a struct called SpanStatus. The struct SpanStatus does not have a C-compatible definition, so it is not well defined what happens when you use it with unsafe pointer-based operations. But this is in dead-code, so codegen should not crash.
The error could likely also be avoided by removing uses of Ref
from this package (those are probably slowing things down anyways over making the struct mutable instead, so it is likely a good QOL change too).
Hi!
Thank you for writing this package; it's awesome!
I've been experimenting with
OpenTelemetry
(OpenTelemetry v0.3.0
) and stumbled over a weird interaction when combined with thePythonCall
(PythonCall v0.9.13
) Package. Running the following code reliably crashes Julia (I tried with Julia 1.9.0, Julia 1.9.1, and Julia 1.8.5; all installed with Juliaup) for me.The weird thing is that
PythonCall
isn't even used.Julia crashes with
Do you have any idea what might cause the issue? I couldn't find anything so far. I'll post a complete stack trace below.