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

[DO NOT MERGE] tracing middleware example #146

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/charms/tempo_k8s/v1/charm_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,19 @@ def trace(obj: Union[Type, Callable]):
raise UntraceableObjectError(
f"cannot create span from {type(obj)}; instrument {obj} manually."
)


from ops.middlewares import Middleware
class TracingMiddleware(Middleware):
"""Middleware to add tracing to your charm."""
def __init__(self, endpoint, cert):
self.endpoint = endpoint
self.cert = cert

# we could also achieve this in a slightly nicer way by using post_init instead,
# but that'd require us to refactor _setup_root_span_initializer to not directly do __init__
# patching.
def setup_class(self, charm_type: Type[CharmBase]):
_autoinstrument(charm_type, self.endpoint, self.cert)


Loading