Skip to content

Commit

Permalink
chore: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc committed Nov 6, 2024
1 parent cf8bc96 commit 98c26fb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 63 deletions.
4 changes: 2 additions & 2 deletions lib/logflare/logs/otel_trace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ defmodule Logflare.Logs.OtelTrace do

[
%{
"message" => span.name,
"event_message" => span.name,
"metadata" => metadata,
"span_id" => Base.encode16(span.span_id),
"parent_span_id" => Base.encode16(span.parent_span_id),
Expand All @@ -77,7 +77,7 @@ defmodule Logflare.Logs.OtelTrace do
metadata = Map.merge(metadata, resource)

%{
"message" => event.name,
"event_message" => event.name,
"metadata" => metadata,
"parent_span_id" => Base.encode16(span_id),
"trace_id" => Ecto.UUID.cast!(trace_id),
Expand Down
60 changes: 60 additions & 0 deletions test/logflare/logs/otel_trace_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
defmodule Logflare.Logs.OtelTraceTest do
use Logflare.DataCase
alias Logflare.Logs.OtelTrace

describe "handle_batch/1" do
setup do
user = build(:user)
source = insert(:source, user: user)
%{resource_spans: TestUtilsGrpc.random_resource_span(), source: source}
end

test "Creates params from a list with one Resource Span that contains an Event", %{
resource_spans: resource_spans,
source: source
} do
batch = OtelTrace.handle_batch(resource_spans, source)

span =
resource_spans
|> hd()
|> then(fn rs -> rs.scope_spans end)
|> hd()
|> then(fn ss -> ss.spans end)
|> hd()

le_span = Enum.find(batch, fn params -> params["metadata"]["type"] == "span" end)

assert le_span["trace_id"] == elem(Ecto.UUID.cast(span.trace_id), 1)
assert le_span["span_id"] == Base.encode16(span.span_id)
assert le_span["parent_span_id"] == Base.encode16(span.parent_span_id)
assert le_span["event_message"] == span.name

assert elem(DateTime.from_iso8601(le_span["timestamp"]), 1) ==
DateTime.from_unix!(span.start_time_unix_nano, :nanosecond)

assert elem(DateTime.from_iso8601(le_span["start_time"]), 1) ==
elem(DateTime.from_unix(span.start_time_unix_nano, :nanosecond), 1)

assert elem(DateTime.from_iso8601(le_span["end_time"]), 1) ==
elem(DateTime.from_unix(span.end_time_unix_nano, :nanosecond), 1)

event = hd(span.events)
le_event = Enum.find(batch, fn params -> params["metadata"]["type"] == "event" end)

assert le_event["event_message"] == event.name
assert le_event["parent_span_id"] == Base.encode16(span.span_id)

assert elem(DateTime.from_iso8601(le_event["timestamp"]), 1) ==
DateTime.from_unix!(event.time_unix_nano, :nanosecond)
end

test "json parsable log event body", %{
resource_spans: resource_spans,
source: source
} do
[params | _] = resource_spans |> OtelTrace.handle_batch(source)
assert {:ok, _} = Jason.encode(params)
end
end
end
61 changes: 0 additions & 61 deletions test/logflare_grpc/trace/transform_test.exs

This file was deleted.

0 comments on commit 98c26fb

Please sign in to comment.