Skip to content

Commit

Permalink
add some tests and bump the release version
Browse files Browse the repository at this point in the history
  • Loading branch information
marcdel committed Jul 16, 2023
1 parent 6cc0cbc commit 27e3b71
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# OpenTelemetryDecorator

## v1.4.2

- Bump opentelemetry_exporter from 1.4.1 to 1.5.0 by @dependabot in https://github.com/marcdel/open_telemetry_decorator/pull/111
- Ensure that keys are strings before we call Span.set_attributes (https://github.com/marcdel/open_telemetry_decorator/issues/114)
- Adds with_span decorator (delegates to trace, so you can use either)

## v1.4.1

### Features
Expand Down
2 changes: 0 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import Config

config :opentelemetry, processors: [:otel_simple_processor]
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule OpenTelemetryDecorator.MixProject do
use Mix.Project

@version "1.4.1"
@version "1.4.2"
@github_page "https://github.com/marcdel/open_telemetry_decorator"

def project do
Expand Down
30 changes: 30 additions & 0 deletions test/open_telemetry_decorator/attributes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,36 @@ defmodule OpenTelemetryDecorator.AttributesTest do
end
end

describe "set prefixes attributes with the configured prefix" do
setup do
prev = Application.get_env(:open_telemetry_decorator, :attr_prefix)
Application.put_env(:open_telemetry_decorator, :attr_prefix, "app.")
on_exit(fn -> Application.put_env(:open_telemetry_decorator, :attr_prefix, prev) end)
end

test "when prefix is configured, prefixes attribute names" do
Tracer.with_span "important_stuff" do
Attributes.set(beep: "boop", count: 12)
Attributes.set(%{maths: 1.2, failed: true})
Attributes.set(:result, {:error, "too sick bro"})
Attributes.set(:color, "pink")
end

expected = %{
"app.beep": "boop",
"app.color": "pink",
"app.count": 12,
"app.failed": true,
"app.maths": 1.2,
"app.result": "{:error, \"too sick bro\"}"
}

assert_receive {:span, span(name: "important_stuff", attributes: attrs)}

assert get_span_attributes(attrs) == expected
end
end

describe "get" do
setup do
prev = Application.get_env(:open_telemetry_decorator, :attr_joiner)
Expand Down
5 changes: 4 additions & 1 deletion test/support/otel_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ defmodule OtelHelper do
Application.load(:opentelemetry)

Application.put_env(:opentelemetry, :processors, [
{:otel_batch_processor, %{scheduled_delay_ms: 1, exporter: {:otel_exporter_pid, self()}}}
{
:otel_batch_processor,
%{scheduled_delay_ms: 1, exporter: {:otel_exporter_pid, self()}}
}
])

{:ok, _} = Application.ensure_all_started(:opentelemetry)
Expand Down

0 comments on commit 27e3b71

Please sign in to comment.