diff --git a/.ameba.yml b/.ameba.yml new file mode 100644 index 0000000..e53f600 --- /dev/null +++ b/.ameba.yml @@ -0,0 +1,16 @@ +# This configuration file was generated by `ameba --gen-config` +# on 2023-05-10 14:20:09 UTC using Ameba version 1.4.3. +# The point is for the user to remove these configuration records +# one by one as the reported problems are removed from the code base. + +# Problems found: 643 +# Run `ameba --only Lint/NotNil` for details +Lint/NotNil: + Description: Identifies usage of `not_nil!` calls + Excluded: + - spec/instrumentation/crystal_http_websocket_spec.cr + - spec/instrumentation/stefanwille_redis_spec.cr + - src/opentelemetry/instrumentation/crystal/http_server.cr + - src/opentelemetry/instrumentation/crystal/http_client.cr + Enabled: false + Severity: Warning diff --git a/VERSION b/VERSION index 4b9fcbe..cb0c939 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.1 +0.5.2 diff --git a/shard.yml b/shard.yml index 24748fa..e3804c7 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: opentelemetry-instrumentation -version: 0.5.1 +version: 0.5.2 authors: - Kirk Haines @@ -19,7 +19,7 @@ dependencies: development_dependencies: ameba: github: crystal-ameba/ameba - version: ~> 1.0.0 + version: ~> 1.4.3 sqlite3: github: crystal-lang/crystal-sqlite3 # Only one of these can be enabled, since they sit in the exact same namespace. diff --git a/spec/instrumentation/crystal_log_spec.cr b/spec/instrumentation/crystal_log_spec.cr index 30db7eb..258c78b 100644 --- a/spec/instrumentation/crystal_log_spec.cr +++ b/spec/instrumentation/crystal_log_spec.cr @@ -16,26 +16,26 @@ describe Log, tags: "Log" do it "can log as normal and send attach the log as an event to a span" do checkout_config do - memory = IO::Memory.new - OpenTelemetry.configure do |config| - config.service_name = "Crystal OTel Instrumentation - HTTP::Server" - config.service_version = "1.0.0" - config.exporter = OpenTelemetry::Exporter.new(variant: :io, io: memory) - end - backend = Log::MemoryBackend.new - message = "I am a message, and there is an active span." - Log.setup(:info, backend) + memory = IO::Memory.new + OpenTelemetry.configure do |config| + config.service_name = "Crystal OTel Instrumentation - HTTP::Server" + config.service_version = "1.0.0" + config.exporter = OpenTelemetry::Exporter.new(variant: :io, io: memory) + end + backend = Log::MemoryBackend.new + message = "I am a message, and there is an active span." + Log.setup(:info, backend) - OpenTelemetry.trace.in_span("logging test span") do |_span| - Log.info { message } - end + OpenTelemetry.trace.in_span("logging test span") do |_span| + Log.info { message } + end - backend.entries.first.message.should eq message - _client_traces, server_traces = FindJson.from_io(memory) - server_traces[0]["spans"][0]["name"].should eq "logging test span" - server_traces[0]["spans"][0]["events"].size.should be > 0 - server_traces[0]["spans"][0]["events"][0]["name"].should eq "Log.INFO" - server_traces[0]["spans"][0]["events"][0]["attributes"]["message"].as_s.should contain(message) + backend.entries.first.message.should eq message + _client_traces, server_traces = FindJson.from_io(memory) + server_traces[0]["spans"][0]["name"].should eq "logging test span" + server_traces[0]["spans"][0]["events"].size.should be > 0 + server_traces[0]["spans"][0]["events"][0]["name"].should eq "Log.INFO" + server_traces[0]["spans"][0]["events"][0]["attributes"]["message"].as_s.should contain(message) + end end end -end diff --git a/spec/instrumentation/websocket_spec_helper.cr b/spec/instrumentation/websocket_spec_helper.cr index 79a1a92..092e210 100644 --- a/spec/instrumentation/websocket_spec_helper.cr +++ b/spec/instrumentation/websocket_spec_helper.cr @@ -1,7 +1,7 @@ require "../spec_helper" require "../support/fibers" -private def wait_for(timeout = 5.seconds) +private def wait_for(timeout = 5.seconds, &) now = Time.monotonic until yield @@ -22,7 +22,7 @@ end # shut down before continuing execution in the current fiber. # 6. If the listening fiber raises an exception, it is rescued and re-raised # in the current fiber. -def run_server(server) +def run_server(server, &) server_done = Channel(Exception?).new f = spawn do @@ -49,7 +49,7 @@ end # Helper method which runs a *handler* # Similar to `run_server` but doesn't go through the network stack. -def run_handler(handler) +def run_handler(handler, &) done = Channel(Exception?).new begin diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 3953634..de81621 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -16,7 +16,7 @@ def clear_env end end -def checkout_config(clear : Bool = true) +def checkout_config(clear : Bool = true, &) config = OpenTelemetry.config clear_env if clear yield diff --git a/src/opentelemetry-instrumentation/log_backend.cr b/src/opentelemetry-instrumentation/log_backend.cr index cab974b..9a58eed 100644 --- a/src/opentelemetry-instrumentation/log_backend.cr +++ b/src/opentelemetry-instrumentation/log_backend.cr @@ -42,7 +42,7 @@ class OpenTelemetry::Instrumentation::LogBackend < ::Log::Backend end def write(entry : ::Log::Entry) - if (span = OpenTelemetry::Trace.current_span) + if span = OpenTelemetry::Trace.current_span span.add_event("Log.#{entry.severity.label}#{" - #{entry.source}" unless entry.source.empty?}") do |event| self.class.apply_log_entry(entry, event) end