Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
added test for autoinstrumentation on inherited methods (#152)
Browse files Browse the repository at this point in the history
* added test for inheritance tracing

* lint
  • Loading branch information
PietroPasotti authored Jul 26, 2024
1 parent 3f94027 commit 0034357
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/scenario/test_charm_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,39 @@ def test_trace_staticmethods_bork(caplog):
f.return_value = opentelemetry.sdk.trace.export.SpanExportResult.SUCCESS
ctx = Context(MyCharmStaticMethods, meta=MyCharmStaticMethods.META)
ctx.run("update-status", State())


class SuperCharm(CharmBase):
def foo(self):
return "bar"


class MyInheritedCharm(SuperCharm):
META = {"name": "godcat"}

def __init__(self, framework: Framework):
super().__init__(framework)
framework.observe(self.on.start, self._on_start)

def _on_start(self, _):
self.foo()

@property
def tempo(self):
return "foo.bar:80"


autoinstrument(MyInheritedCharm, "tempo")


def test_inheritance_tracing(caplog):
import opentelemetry

with patch(
"opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter.export"
) as f:
f.return_value = opentelemetry.sdk.trace.export.SpanExportResult.SUCCESS
ctx = Context(MyInheritedCharm, meta=MyInheritedCharm.META)
ctx.run("start", State())
spans = f.call_args_list[0].args[0]
assert spans[0].name == "method call: SuperCharm.foo"

0 comments on commit 0034357

Please sign in to comment.