Skip to content

Commit

Permalink
Enrich span names in OTEL traces (#6)
Browse files Browse the repository at this point in the history
* feature: Added activity name to the span name for better readability in traces. This makes it easier for users viewing the trace in a backend to be able to understand the flow and which activity is which without having to carry the context mentally

---------

Signed-off-by: Chris Doyle <uk.chris.doyle+cdsre@gmail.com>
  • Loading branch information
cdsre committed Apr 9, 2024
1 parent fea8b7a commit a1ed9ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

[Unreleased]: https://github.com/chaostoolkit-incubator/chaostoolkit-opentracing/compare/0.16.1..HEAD

### Fixed

- Added the ctk activity name in activity spans to enrich the user readability in backend tracing systems. [#5][ctk-opentracing-5]

[ctk-opentracing-5]: https://github.com/chaostoolkit-incubator/chaostoolkit-opentracing/issues/5

## [0.16.1][] - 2023-12-18

Expand Down
13 changes: 9 additions & 4 deletions chaostracing/oltp.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,15 @@ def continuous_hypothesis_iteration(self, iteration_index: int, state: Any) -> N
.timestamp()
* 1e9
)
activity_name: str = probe["activity"]["name"]
with new_span(
"activity", span, start_time=child_start_ts, end_on_exit=False
f"activity: {activity_name}",
span,
start_time=child_start_ts,
end_on_exit=False,
) as child:
activity = probe["activity"]
child.set_attribute("chaostoolkit.activity.name", activity["name"])
child.set_attribute("chaostoolkit.activity.name", activity_name)
child.set_attribute(
"chaostoolkit.activity.background",
activity.get("background", False),
Expand Down Expand Up @@ -330,13 +334,14 @@ def rollbacks_completed(self, experiment: Experiment, journal: Journal) -> None:

def start_activity(self, activity: Activity) -> None:
parent = self.current_span
activity_name: str = activity.get("name")
if self.continuous_span is not None:
if "tolerance" in activity:
return

stack = ExitStack()
span = stack.enter_context(new_span("activity", parent))
span.set_attribute("chaostoolkit.activity.name", activity.get("name"))
span = stack.enter_context(new_span(f"activity: {activity_name}", parent))
span.set_attribute("chaostoolkit.activity.name", activity_name)
span.set_attribute(
"chaostoolkit.activity.background", activity.get("background", False)
)
Expand Down

0 comments on commit a1ed9ce

Please sign in to comment.