Replies: 1 comment 4 replies
-
Hello @guettli ✌️ I would suggest using this example as inspiration. Maybe something like this would work for you? from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
ConsoleSpanExporter,
)
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(ConsoleSpanExporter())
)
tracer = trace.get_tracer(__name__)
def test_bar():
def bar(color):
if color == "blue":
return "sunshine"
return "moonlight"
def call_bar(color):
with tracer.start_as_current_span("test"):
assert bar(color) == "sunshine"
call_bar("blue")
call_bar("blue")
call_bar("red") I saved this code in a file named
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am new to opentelemetry. Can it help in this use case?
I have a flaky test which failure is not reproducible for me.
Up to now I only see a meaningless error message of the test fails.
like
moonlight != sunshine
I would like to trace
bar()
every time it is called in the test.If the assertion fails, then I want to see the trace as text.
The trace should contain all lines which get executed by
bar()
(excluding Python stdlib).Maybe something like this:
Can opentelemetry-python provide something like
SomeTracer
andtrace_to_text()
?I am using pytest.
AFAIK I am forced to the constrained text output.
Beta Was this translation helpful? Give feedback.
All reactions