Skip to content

Commit

Permalink
chore: update charm libraries (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
observability-noctua-bot authored Jun 19, 2024
1 parent fa2780b commit 9eade9c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/charms/tempo_k8s/v1/charm_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,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 = 9
LIBPATCH = 10

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

Expand Down Expand Up @@ -297,13 +297,14 @@ def wrap_init(self: CharmBase, framework: Framework, *args, **kwargs):
# default service name isn't just app name because it could conflict with the workload service name
_service_name = service_name or f"{self.app.name}-charm"

unit_name = self.unit.name
resource = Resource.create(
attributes={
"service.name": _service_name,
"compose_service": _service_name,
"charm_type": type(self).__name__,
# juju topology
"juju_unit": self.unit.name,
"juju_unit": unit_name,
"juju_application": self.app.name,
"juju_model": self.model.name,
"juju_model_uuid": self.model.uuid,
Expand Down Expand Up @@ -341,16 +342,18 @@ def wrap_init(self: CharmBase, framework: Framework, *args, **kwargs):
_tracer = get_tracer(_service_name) # type: ignore
_tracer_token = tracer.set(_tracer)

dispatch_path = os.getenv("JUJU_DISPATCH_PATH", "")
dispatch_path = os.getenv("JUJU_DISPATCH_PATH", "") # something like hooks/install
event_name = dispatch_path.split("/")[1] if "/" in dispatch_path else dispatch_path
root_span_name = f"{unit_name}: {event_name} event"
span = _tracer.start_span(root_span_name, attributes={"juju.dispatch_path": dispatch_path})

# all these shenanigans are to work around the fact that the opentelemetry tracing API is built
# on the assumption that spans will be used as contextmanagers.
# Since we don't (as we need to close the span on framework.commit),
# we need to manually set the root span as current.
span = _tracer.start_span("charm exec", attributes={"juju.dispatch_path": dispatch_path})
ctx = set_span_in_context(span)

# log a trace id so we can look it up in tempo.
# log a trace id, so we can pick it up from the logs (and jhack) to look it up in tempo.
root_trace_id = hex(span.get_span_context().trace_id)[2:] # strip 0x prefix
logger.debug(f"Starting root trace with id={root_trace_id!r}.")

Expand Down

0 comments on commit 9eade9c

Please sign in to comment.