Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/draive/aws/observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def record_log(
attributes["exception.message"] = str(exception)

ctx.spawn_background(
AWSCloudwatch.log_putting,
AWSCloudwatch.put_log,
log_stream=self.log_stream,
log_group=self.log_group,
message=_json_dumps(
Expand All @@ -336,7 +336,7 @@ def record_exception(
/,
) -> None:
ctx.spawn_background(
AWSCloudwatch.event_putting,
AWSCloudwatch.put_event,
event_bus=self.event_bus,
event_source=self.event_source,
detail_type="exception",
Expand Down Expand Up @@ -374,7 +374,7 @@ def record_event(
attributes: Mapping[str, ObservabilityAttribute],
) -> None:
ctx.spawn_background(
AWSCloudwatch.event_putting,
AWSCloudwatch.put_event,
event_bus=self.event_bus,
event_source=self.event_source,
detail_type="event",
Expand Down Expand Up @@ -410,7 +410,7 @@ def record_metric(
)
metric_attributes.setdefault("otel.metric.kind", kind)
ctx.spawn_background(
AWSCloudwatch.metric_putting,
AWSCloudwatch.put_metric,
namespace=self.metrics_namespace,
metric=name,
value=value,
Expand Down
40 changes: 28 additions & 12 deletions tests/test_aws_state_observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ async def metric_putting(
metrics_namespace="metrics",
)

scope.record_scope_start()
scope.record_scope_end(None)
await asyncio.gather(*tasks)
async with ctx.scope(
"test",
AWSCloudwatch(
log_putting=log_putting,
metric_putting=metric_putting,
event_putting=event_putting,
),
):
scope.record_scope_start()
scope.record_scope_end(None)
await asyncio.gather(*tasks)

assert len(events) == 2
detail_types = {event["detail_type"] for event in events}
Expand Down Expand Up @@ -159,15 +167,23 @@ async def metric_putting(
event_source="draive",
)

scope.record_attributes({"user": "alice"}, level=ObservabilityLevel.INFO)
scope.record_metric(
"latency",
value=1,
unit=None,
kind="gauge",
attributes={"service": "draive"},
)
await asyncio.gather(*tasks)
async with ctx.scope(
"test",
AWSCloudwatch(
log_putting=log_putting,
metric_putting=metric_putting,
event_putting=event_putting,
),
):
scope.record_attributes({"user": "alice"}, level=ObservabilityLevel.INFO)
scope.record_metric(
"latency",
value=1,
unit=None,
kind="gauge",
attributes={"service": "draive"},
)
await asyncio.gather(*tasks)

assert recorded_metrics
assert recorded_metrics[0]["attributes"] == {
Expand Down
Loading