Skip to content

Commit

Permalink
chore: update charm libraries (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
observability-noctua-bot authored Jun 13, 2024
1 parent c67e35d commit eda1588
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
3 changes: 2 additions & 1 deletion lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, *args):
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 35
LIBPATCH = 36

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1050,6 +1050,7 @@ def __init__(

self.framework.observe(self._charm.on.leader_elected, self._update_all_dashboards_from_dir)
self.framework.observe(self._charm.on.upgrade_charm, self._update_all_dashboards_from_dir)
self.framework.observe(self._charm.on.config_changed, self._update_all_dashboards_from_dir)

self.framework.observe(
self._charm.on[self._relation_name].relation_created,
Expand Down
24 changes: 9 additions & 15 deletions lib/charms/tempo_k8s/v1/charm_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def my_tracing_endpoint(self) -> Optional[str]:
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 7
LIBPATCH = 8

PYDEPS = ["opentelemetry-exporter-otlp-proto-http==1.21.0"]

Expand Down Expand Up @@ -509,18 +509,20 @@ def trace_type(cls: _T) -> _T:
logger.info(f"skipping {method} (dunder)")
continue

isstatic = isinstance(inspect.getattr_static(cls, method.__name__), staticmethod)
setattr(cls, name, trace_method(method, static=isstatic))
new_method = trace_method(method)
if isinstance(inspect.getattr_static(cls, method.__name__), staticmethod):
new_method = staticmethod(new_method)
setattr(cls, name, new_method)

return cls


def trace_method(method: _F, static: bool = False) -> _F:
def trace_method(method: _F) -> _F:
"""Trace this method.
A span will be opened when this method is called and closed when it returns.
"""
return _trace_callable(method, "method", static=static)
return _trace_callable(method, "method")


def trace_function(function: _F) -> _F:
Expand All @@ -531,22 +533,14 @@ def trace_function(function: _F) -> _F:
return _trace_callable(function, "function")


def _trace_callable(callable: _F, qualifier: str, static: bool = False) -> _F:
def _trace_callable(callable: _F, qualifier: str) -> _F:
logger.info(f"instrumenting {callable}")

# sig = inspect.signature(callable)
@functools.wraps(callable)
def wrapped_function(*args, **kwargs): # type: ignore
name = getattr(callable, "__qualname__", getattr(callable, "__name__", str(callable)))
with _span(f"{'(static) ' if static else ''}{qualifier} call: {name}"): # type: ignore
if static:
# The _trace_callable decorator doesn't play super nice with @staticmethods.
# if you call MyObj().mystaticmethod we'll receive the MyObj instance as first argument,
# if you call MyObj.mystaticmethod we won't.
try:
inspect.signature(callable).bind(*args, **kwargs)
except TypeError:
return callable(*args[1:], **kwargs) # type: ignore
with _span(f"{qualifier} call: {name}"): # type: ignore
return callable(*args, **kwargs) # type: ignore

# wrapped_function.__signature__ = sig
Expand Down

0 comments on commit eda1588

Please sign in to comment.