Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Fix issues-48 #56

Merged
merged 1 commit into from
Jun 2, 2020
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
15 changes: 8 additions & 7 deletions lib/open_telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ defmodule OpenTelemetry do

OpenTelemetry.register_application_tracer(:this_otp_app)

Tracer.start_span(\"some-span\")
Tracer.start_span("some-span")
...
ecto_event = OpenTelemetry.event(\"ecto.query\", [{\"query\", query}, {\"total_time\", total_time}])
OpenTelemetry.Span.add_event(ecto_event)
event = "ecto.query"
ecto_attributes = OpenTelemetry.event([{"query", query}, {"total_time", total_time}])
OpenTelemetry.Span.add_event(event, ecto_event)
...
Tracer.end_span()
"""
Expand Down Expand Up @@ -64,10 +65,10 @@ defmodule OpenTelemetry do

Examples of attributes:

[{\"/http/user_agent\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36\"}
{\"/http/server_latency\", 300}
{\"abc.com/myattribute\", True}
{\"abc.com/score\", 10.239}]
[{"/http/user_agent" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"}
{"/http/server_latency", 300}
{"abc.com/myattribute", True}
{"abc.com/score", 10.239}]
"""
@type attributes() :: [{attribute_key(), attribute_value()}]

Expand Down
26 changes: 19 additions & 7 deletions lib/open_telemetry/span.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ defmodule OpenTelemetry.Span do

require OpenTelemetry.Span
...
ecto_event = OpenTelemetry.event(\"ecto.query\", [{\"query\", query}, {\"total_time\", total_time}])
OpenTelemetry.Span.add_event(ecto_event)
event = "ecto.query"
ecto_attributes = OpenTelemetry.event([{"query", query}, {"total_time", total_time}])
OpenTelemetry.Span.add_event(event, ecto_event)
...

A Span represents a single operation within a trace. Spans can be nested to form a trace tree.
Expand Down Expand Up @@ -44,15 +45,20 @@ defmodule OpenTelemetry.Span do
@spec tracestate(OpenTelemetry.span_ctx()) :: OpenTelemetry.tracestate()
defdelegate tracestate(span), to: :ot_span


@doc """
Set an attribute with key and value on the currently active Span.
"""
@spec set_attribute(OpenTelemetry.attribute_key(), OpenTelemetry.attribute_value()) :: boolean()
defmacro set_attribute(key, value) do
quote do
tracer = :opentelemetry.get_tracer(__MODULE__)
:ot_span.set_attribute(tracer, :ot_tracer.current_span_ctx(tracer), unquote(key), unquote(value))

:ot_span.set_attribute(
tracer,
:ot_tracer.current_span_ctx(tracer),
unquote(key),
unquote(value)
)
end
end

Expand All @@ -70,11 +76,17 @@ defmodule OpenTelemetry.Span do
@doc """
Add an event to the currently active Span.
"""
@spec add_event(OpenTelemetry.event()) :: boolean()
defmacro add_event(event) do
@spec add_event(String.t(), [OpenTelemetry.attribute()]) :: boolean()
defmacro add_event(event, attributes) do
quote do
tracer = :opentelemetry.get_tracer(__MODULE__)
:ot_span.add_event(tracer, :ot_tracer.current_span_ctx(tracer), unquote(event))

:ot_span.add_event(
tracer,
:ot_tracer.current_span_ctx(tracer),
unquote(event),
unquote(attributes)
)
end
end

Expand Down