Skip to content

Commit

Permalink
version 0.5.0
Browse files Browse the repository at this point in the history
allows specifying the error level at which we log spans/traces
  • Loading branch information
marcdel committed Apr 23, 2023
1 parent 6e13a12 commit 3c341da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ The package can be installed by adding `opentelemetry_log_exporter` to your list
```elixir
def deps do
[
{:opentelemetry_log_exporter, "~> 0.4.0"}
{:opentelemetry_log_exporter, "~> 0.5.0"}
]
end
```

and as a trace exporter in `config/dev.exs`.

```elixir
config :opentelemetry, traces_exporter: {Elixir.OpenTelemetryLogExporter, []}
config :opentelemetry, traces_exporter: {Elixir.OpenTelemetryLogExporter, [level: :info]}
```

You will need to change the scheduled delay in `config/test.exs` because by default the test process will exit before the spans are exported.

```elixir
config :opentelemetry,
processors: [
{:otel_batch_processor, %{scheduled_delay_ms: 1, exporter: {Elixir.OpenTelemetryLogExporter, []}}}
{:otel_batch_processor, %{scheduled_delay_ms: 1, exporter: {Elixir.OpenTelemetryLogExporter, [level: :warning]}}}
]
```
```

You can change the level at which spans are logged by passing the `:level` keyword
14 changes: 10 additions & 4 deletions lib/opentelemetry_log_exporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,31 @@ defmodule OpenTelemetryLogExporter do

def shutdown(_), do: :ok

def export(_traces, span_table_id, _resource, _config) do
def export(_traces, span_table_id, _resource, config) do
try do
do_export(span_table_id)
span_table_id
|> get_messages_to_be_logged()
|> log_messages(config)
rescue
e -> Logger.error(Exception.format(:error, e, __STACKTRACE__))
end

:ok
end

defp do_export(span_table_id) do
defp get_messages_to_be_logged(span_table_id) do
span_table_id
|> :ets.tab2list()
|> Enum.reverse()
|> Enum.map(&Span.new/1)
|> TraceBuilder.build()
|> Enum.map(&generate_trace_messages/1)
|> List.flatten()
|> Enum.each(&Logger.info/1)
end

defp log_messages(messages, config) do
level = Keyword.get(config, :level, :info)
Enum.each(messages, fn message -> Logger.log(level, message) end)
end

def generate_trace_messages(span) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule OpenTelemetryLogExporter.MixProject do
use Mix.Project

@version "0.4.0"
@version "0.5.0"
@github_page "https://github.com/marcdel/opentelemetry_log_exporter"

def project do
Expand Down
2 changes: 1 addition & 1 deletion test/opentelemetry_log_exporter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule OpenTelemetryLogExporterTest do

:application.start(:opentelemetry)

:otel_batch_processor.set_exporter(Elixir.OpenTelemetryLogExporter, [])
:otel_batch_processor.set_exporter(Elixir.OpenTelemetryLogExporter, level: :warning)

on_exit(fn ->
:application.stop(:opentelemetry)
Expand Down

0 comments on commit 3c341da

Please sign in to comment.