Skip to content

Commit

Permalink
feat(receiver-mock): add querying the spans and traces by span name
Browse files Browse the repository at this point in the history
  • Loading branch information
aboguszewski-sumo committed Sep 9, 2022
1 parent 601884b commit 38a97c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/rust/receiver-mock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The following endpoints provide information about received traces:
It accepts a list of key value pairs being an attribute set that the span will
have to fullfil in order to be returned.
Attribute values can be omitted in which case only presence of a particular attribute
will be checked.
will be checked. `__name__` is handled specially as it will be matched against the span name.

Exemplary output:

Expand Down Expand Up @@ -102,7 +102,7 @@ The following endpoints provide information about received traces:
It accepts a list of key value pairs being an attribute set.
If any span in a trace contains all of these attributes, this trace will be in the list.
Attribute values can be omitted in which case only presence of a particular attribute
will be checked.
will be checked. Similarly as in `/spans-list`, `__name__` is handled specially as it will be matched against the name of any span.

Exemplary output:

Expand Down
12 changes: 11 additions & 1 deletion src/rust/receiver-mock/src/traces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ impl std::fmt::Display for Span {
}

fn is_span_ok(span: &Span, params: &HashMap<String, String>) -> bool {
// TODO: This can be expanded to query by other parameters. As for now, it only filters by label.
for (key, value) in params.iter() {
// Identically as in the metric's case,
// we use "__name__" as key for span's name
// to keep the querying simple.
if key == "__name__" {
if span.name == *value {
continue;
} else {
return false;
}
}

if let Some(val) = span.attributes.get(key) {
if val.eq(value) {
continue;
Expand Down

0 comments on commit 38a97c3

Please sign in to comment.