Skip to content

Commit

Permalink
Fix ameba/linting and bump version for release.
Browse files Browse the repository at this point in the history
The Ameba version was too old, so it was bumped.
An .ameba.yml file was introduced to better control linting rules, and the issues that Ameba identified were fixed.
The shard.yml version and VERSION were bumped to 0.5.2 to prepare for a release.
  • Loading branch information
wyhaines committed May 10, 2023
1 parent ea8dae3 commit c3a58b6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 27 deletions.
16 changes: 16 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.1
0.5.2
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: opentelemetry-instrumentation
version: 0.5.1
version: 0.5.2

authors:
- Kirk Haines <[email protected]>
Expand All @@ -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.
Expand Down
38 changes: 19 additions & 19 deletions spec/instrumentation/crystal_log_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/instrumentation/websocket_spec_helper.cr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/opentelemetry-instrumentation/log_backend.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3a58b6

Please sign in to comment.