Skip to content

Add "origin" and "user" segment metadata #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2024
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
11 changes: 9 additions & 2 deletions lib/aws_ex_ray/segment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
metadata: map,
error: map | nil,
http: map,
aws: map | nil
aws: map | nil,
user: String.t | nil
}

defstruct id: "",
Expand All @@ -36,7 +37,8 @@
annotation: %{},
metadata: %{},
http: %{},
aws: nil
aws: nil,
user: nil

@spec new(trace :: Trace.t, name :: String.t) :: t
def new(trace, name) do
Expand Down Expand Up @@ -105,6 +107,11 @@
end)
end

@spec set_user(seg :: t, user :: String.t) :: t
def set_user(seg, user) do
Map.put(seg, :user, user)
end

@spec set_http_request(seg :: t, req :: HTTPRequest.t) :: t
def set_http_request(seg, req) do
put_in(seg.http.request, req)
Expand Down
17 changes: 16 additions & 1 deletion lib/aws_ex_ray/segment/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
|> embed_http(seg)
|> embed_error(seg)
|> embed_aws(seg)
|> embed_user(seg)
end

defp embed_error(m, seg) do
Expand Down Expand Up @@ -98,7 +99,21 @@
nil ->
m
aws_metadata when is_map(aws_metadata) ->
Map.put(m, :aws, aws_metadata)
m = Map.put(m, :aws, aws_metadata)
if Map.has_key?(aws_metadata, "ec2") do
Map.put(m, :origin, "AWS::EC2::Instance")
else
m
end
end
end

defp embed_user(m, seg) do
case seg.user do
nil ->
m
user ->
Map.put(m, :user, user)
end
end

Expand Down