Skip to content

Commit

Permalink
Merge pull request #73 from agardnerIT/add_status
Browse files Browse the repository at this point in the history
add span status + docs
  • Loading branch information
agardnerIT authored Sep 13, 2023
2 parents 8092fa6 + 35abc3d commit 9fd8323
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ This behaviour can be overridden by using the `--duration-type` parameter.

See [duration type](https://agardnerit.github.io/tracepusher/reference/duration-type/) page.

## Span Status

> Only supported with `v0.9.0` and above.
tracepusher users can set the status of the span (`OK`, `ERROR` or `UNSET`).

Default is `OK`.

See [span status](docs/reference/span-status.md) page.

## Spin up OpenTelemetry Collector

See [OpenTelemetry Collector configuration](https://agardnerit.github.io/tracepusher/reference/otel-col)
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ See the following pages for advanced usage and reference information for the fla
- [Span time shifting](reference/time-shifting.md)
- [Span attributes and span attribute types](reference/span-attribute-types.md)
- [Span events](reference/span-events.md)
- [Span status](reference/span-status.md)
- [tracepusher flag reference pages](reference/index.md)
3 changes: 2 additions & 1 deletion docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
- [Time Shifting](time-shifting.md)
- [Span Events](span-events.md)
- [Span Kind](span-kind.md)
- [Span Durations and Duration Types](duration-type.md)
- [Span Durations and Duration Types](duration-type.md)
- [Span Status](span-status.md)
59 changes: 59 additions & 0 deletions docs/reference/span-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Span Kind

The optional flag `-ss` or `--span-status` allows users to specify the span status.

If not specified, tracepusher assumes an `OK` status.

For reference, these map to values of `0` (Unset), `1` (OK) or `2` (Error) according to the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L270-#L278).

### Valid Span Types

These are case insensitive:

- `OK` (default)
- `ERROR`
- `UNSET` (if you use anything other than "OK" or "ERROR")

### Examples

#### Defaults to OK

```shell
./tracepusher \
-ep http://localhost:4318 \
-sen serviceA \
-spn span1 \
-dur 2
```

#### Explicitly set to OK

```shell
./tracepusher \
-ep http://localhost:4318 \
-sen serviceA \
-spn span1 \
-dur 2 \
--span-status OK
```

#### Explicitly set to Error
```shell
./tracepusher \
-ep http://localhost:4318 \
-sen serviceA \
-spn span1 \
-dur 2 \
--span-status ERROR
```

#### Invalid value (defaults to Unset)

```shell
./tracepusher \
-ep http://localhost:4318 \
-sen serviceA \
-spn span1 \
-dur 2 \
--span-status ABC123
```
14 changes: 12 additions & 2 deletions tracepusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ def check_duration_type(input):
return True
else:
return False


def get_span_status_int(input):
if input.lower() == "ok":
return 1
if input.lower() == "error":
return 2
return 0

parser = argparse.ArgumentParser()

# Notes:
Expand All @@ -181,6 +188,7 @@ def check_duration_type(input):
parser.add_argument('-spnattrs', '--span-attributes', required=False, nargs='*')
parser.add_argument('-spnevnts', '--span-events', required=False, nargs='*')
parser.add_argument('-sk', '--span-kind', required=False, default="INTERNAL")
parser.add_argument('-ss', '--span-status', required=False, default="OK")

args = parser.parse_args()

Expand All @@ -196,6 +204,7 @@ def check_duration_type(input):
trace_id = args.trace_id
span_id = args.span_id
span_kind = args.span_kind
span_status = get_span_status_int(args.span_status)

span_attributes_list, dropped_attribute_count = get_span_attributes_list(args.span_attributes)
span_kind = process_span_kind(span_kind)
Expand Down Expand Up @@ -241,6 +250,7 @@ def check_duration_type(input):
print(f"Span ID: {span_id}")
print(f"Dropped Attribute Count: {dropped_attribute_count}")
print(f"Span Kind: {span_kind}")
print(f"Span Status: {span_status}")

# Generate random chars for trace and span IDs
# of 32 chars and 16 chars respectively
Expand Down Expand Up @@ -327,7 +337,7 @@ def check_duration_type(input):
"events": span_events_list,
"droppedEventsCount": dropped_event_count,
"status": {
"code": 1
"code": span_status
}
}
]
Expand Down
34 changes: 33 additions & 1 deletion tracepusher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,36 @@ def test_check_one_valid_one_invalid_span_attribute():
output = run_tracepusher(args)
assert output.returncode == 0
assert "'droppedAttributesCount': 1" in output.stdout
assert "'intValue': '23'" in output.stdout
assert "'intValue': '23'" in output.stdout

# Check that (by default) span
# has status of OK
def test_check_span_status_ok_when_not_set():
args = "-ep http://otelcollector:4317 -sen serviceA -spn spanOne -dur 2 --dry-run true --debug true"
output = run_tracepusher(args)
assert output.returncode == 0
assert "'status': {'code': 1}" in output.stdout

# Check that span has status of OK
# When explicitly set
def test_check_span_status_ok_when_set():
args = "-ep http://otelcollector:4317 -sen serviceA -spn spanOne -dur 2 --dry-run true --debug true --span-status OK"
output = run_tracepusher(args)
assert output.returncode == 0
assert "'status': {'code': 1}" in output.stdout

# Check that span has status of ERROR
# When explicitly set
def test_check_span_status_error_when_set():
args = "-ep http://otelcollector:4317 -sen serviceA -spn spanOne -dur 2 --dry-run true --debug true --span-status ERROR"
output = run_tracepusher(args)
assert output.returncode == 0
assert "'status': {'code': 2}" in output.stdout

# Check that span has status of UNSET
# When set to something invalid / random
def test_check_span_status_unset_when_set():
args = "-ep http://otelcollector:4317 -sen serviceA -spn spanOne -dur 2 --dry-run true --debug true --span-status ABC123"
output = run_tracepusher(args)
assert output.returncode == 0
assert "'status': {'code': 0}" in output.stdout

0 comments on commit 9fd8323

Please sign in to comment.