Skip to content

Commit 8df6628

Browse files
authored
Report Redix error messages through OTel status (#81)
Instead of custom attributes, leverage the status description as described in Semantic Conventions. This approach is taken from current `opentelemetry_ecto` implementation. Small non-related change is a fix the license description in `mix.exs`.
1 parent e856486 commit 8df6628

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.1.1
4+
5+
### Bug fixes
6+
7+
* Report errors via OpenTelemetry SetStatus API instead of custom
8+
attributes
9+
310
## 0.1.0
411

512
* Initial release

instrumentation/opentelemetry_redix/lib/opentelemetry_redix.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ defmodule OpentelemetryRedix do
6060
}
6161
|> Map.merge(net_attributes(connection))
6262
|> Map.merge(redix_attributes(meta))
63-
|> Map.merge(error_attributes(meta))
6463

6564
s =
6665
OpenTelemetry.Tracer.start_span(operation, %{
@@ -69,8 +68,8 @@ defmodule OpentelemetryRedix do
6968
attributes: attributes
7069
})
7170

72-
if meta[:reason] do
73-
OpenTelemetry.Span.set_status(s, OpenTelemetry.status(:error, ""))
71+
if meta[:kind] == :error do
72+
OpenTelemetry.Span.set_status(s, OpenTelemetry.status(:error, format_error(meta.reason)))
7473
end
7574

7675
OpenTelemetry.Span.end_span(s)
@@ -87,6 +86,6 @@ defmodule OpentelemetryRedix do
8786
defp redix_attributes(%{connection_name: name}), do: %{"db.redix.connection_name": name}
8887
defp redix_attributes(_), do: %{}
8988

90-
defp error_attributes(%{reason: reason}), do: %{"db.redix.error": inspect(reason)}
91-
defp error_attributes(_), do: %{}
89+
defp format_error(%{__exception__: true} = exception), do: Exception.message(exception)
90+
defp format_error(reason), do: inspect(reason)
9291
end

instrumentation/opentelemetry_redix/mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule OpentelemetryRedix.MixProject do
55
[
66
app: :opentelemetry_redix,
77
description: description(),
8-
version: "0.1.0",
8+
version: "0.1.1",
99
elixir: "~> 1.10",
1010
start_permanent: Mix.env() == :prod,
1111
deps: deps(),
@@ -23,7 +23,7 @@ defmodule OpentelemetryRedix.MixProject do
2323
defp package do
2424
[
2525
files: ~w(lib .formatter.exs mix.exs README* LICENSE* CHANGELOG*),
26-
licenses: ["Apache-2"],
26+
licenses: ["Apache-2.0"],
2727
links: %{
2828
"GitHub" =>
2929
"https://github.com/open-telemetry/opentelemetry-erlang-contrib/tree/main/instrumentation/opentelemetry_redix",

0 commit comments

Comments
 (0)