Skip to content

Commit d8d7027

Browse files
committed
Bump version, fix a bug, and make specs a little more robust.
Some DBs, like Postgresql, can handle more types for args than what are supported in DB::Any. With procs for arg filters, this breaks. However, without resorting to more chicanery than I am willing to right now, pluggable argument filters won't work without procs. So, pluggable argument filter goes away, for now, and we let the compiler sort out the types itself. Also, the HTTP Server specs start a test server, normally on port 8080. I have added a port scanner that will scan for the next available port (up to 1000 attempts) if 8080 is unavailable. Bumping version for a quick release.
1 parent 1427f7a commit d8d7027

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.4
1+
0.3.5

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: opentelemetry-instrumentation
2-
version: 0.3.4
2+
version: 0.3.5
33

44
authors:
55
- Kirk Haines <wyhaines@gmail.com>

spec/instrumentation/crystal_http_server_spec.cr

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ require "../../src/opentelemetry/instrumentation/crystal/http_server"
55
require "io/memory"
66
require "json"
77

8+
HTTP_SERVER_TEST_PORT = [8080]
9+
10+
1000.times do |t|
11+
begin
12+
server = HTTP::Server.new do |context|
13+
context.response.content_type = "text/plain"
14+
context.response.print "Hello world!"
15+
end
16+
17+
try_port = 8080 + t
18+
server.bind_tcp try_port
19+
20+
HTTP_SERVER_TEST_PORT[0] = try_port
21+
break
22+
rescue ex
23+
# NOP
24+
end
25+
end
26+
827
describe HTTP::Server, tags: ["HTTP::Server"] do
928
it_may_focus_and_it "should have instrumented HTTP::Server" do
1029
Tracer::TRACED_METHODS_BY_RECEIVER[HTTP::Server]?.should be_truthy
@@ -35,15 +54,15 @@ describe HTTP::Server, tags: ["HTTP::Server"] do
3554
end
3655

3756
# Start the server.
38-
address = server.bind_tcp 8080
57+
address = server.bind_tcp HTTP_SERVER_TEST_PORT[0]
3958
server.listen
4059
end
4160

4261
sleep 1
4362

4463
# Send requests to the server. These will generate OTel traces.
4564
1.times do
46-
HTTP::Client.get("http://127.0.0.1:8080")
65+
HTTP::Client.get("http://127.0.0.1:#{HTTP_SERVER_TEST_PORT[0]}/")
4766
sleep((rand() * 100) / 1000)
4867
end
4968

@@ -59,7 +78,7 @@ describe HTTP::Server, tags: ["HTTP::Server"] do
5978

6079
client_traces[0]["spans"][0]["name"].should eq("HTTP::Client GET")
6180
client_traces[0]["spans"][0]["kind"].should eq 3
62-
client_traces[0]["spans"][0]["attributes"]["http.url"].should eq "http://127.0.0.1:8080/"
81+
client_traces[0]["spans"][0]["attributes"]["http.url"].should eq "http://127.0.0.1:#{HTTP_SERVER_TEST_PORT[0]}/"
6382

6483
server_traces[0]["spans"][0]["name"].should eq "HTTP::Server connection"
6584
server_traces[0]["resource"]["service.name"].should eq "Crystal OTel Instrumentation - HTTP::Server"

src/opentelemetry/instrumentation/crystal/db.cr

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ unless_enabled?("OTEL_CRYSTAL_DISABLE_INSTRUMENTATION_DB") do
3939
# :nodoc:
4040
module OpenTelemetry::Instrumentation
4141
class CrystalDB < OpenTelemetry::Instrumentation::Instrument
42+
def self.filter(arg)
43+
arg.inspect
44+
end
45+
4246
{% begin %}
43-
alias DB::Types = {% for type in DB::Any.union_types %}Array({{ type.id }}) | {% end %}DB::Any
47+
alias DB::Types = {% for type in DB::Any.union_types %}Array({{ type.id }}) | {% end %}DB::Any | UUID | Array(UUID)
4448
{% end %}
45-
# One can add their own procs to this array (prepend them to the array) to add other data filtration"
46-
ArgFilters = [
47-
->(arg : DB::Types) do
48-
arg.inspect
49-
end,
50-
]
5149
end
5250
end
5351

@@ -91,10 +89,11 @@ unless_enabled?("OTEL_CRYSTAL_DISABLE_INSTRUMENTATION_DB") do
9189
OpenTelemetry.trace.in_span("#{db_name}->#{operation.upcase}") do |span| # My kingdom for a SQL parser that can extract table names from a SQL query!
9290
query_args = [] of String
9391
args.each do |arg|
94-
OpenTelemetry::Instrumentation::CrystalDB::ArgFilters.each do |filter|
95-
filter_result = filter.call(arg)
96-
arg = filter_result if filter_result
97-
end
92+
# OpenTelemetry::Instrumentation::CrystalDB::ArgFilters.each do |filter|
93+
# filter_result = filter.call(arg)
94+
# arg = filter_result if filter_result
95+
# end
96+
arg = OpenTelemetry::Instrumentation::CrystalDB.filter(arg)
9897

9998
arg = arg.to_s unless arg.is_a?(String)
10099
query_args << arg

0 commit comments

Comments
 (0)