Skip to content

Commit 63208c3

Browse files
committed
Changes to add more standard information to the spans, and to fix specs to comply with some simplifications and memory-pressure related fixes to the API/SDK.
1 parent 8fae1e3 commit 63208c3

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

spec/instrumentation/crystal_db_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ describe DB::Statement, tags: "DB::Statement" do
8484
traces[0]["spans"][0]["name"].should eq "Do a bunch of DB Queries"
8585
parent_span_id = traces[0]["spans"][0]["spanId"]
8686
traces[0]["spans"][1]["kind"].should eq 3
87-
traces[0]["spans"][1]["name"].should eq "data.db->CREATE"
87+
traces[0]["spans"][1]["name"].should eq "data.db->SELECT"
8888
traces[0]["spans"][1]["attributes"]["db.name"].should eq "data.db"
8989
traces[0]["spans"][1]["parentSpanId"].should eq parent_span_id
90-
traces[0]["spans"][5]["attributes"]["db.statement"].should eq "select name, age, timestamp from contacts order by age desc"
90+
traces[0]["spans"][5]["attributes"]["db.statement"].should eq "create table contacts (name text, age integer, timestamp time)"
9191
end
9292
end

src/opentelemetry/instrumentation/crystal/http_server.cr

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ unless_enabled?("OTEL_CRYSTAL_DISABLE_INSTRUMENTATION_HTTP_SERVER") do
137137

138138
OpenTelemetry.in_span(trace_name) do |span|
139139
if request.is_a?(HTTP::Request) && request.headers["traceparent"]?
140-
parent = OpenTelemetry::Span.build do |pspan|
140+
parent = OpenTelemetry::Span.build("Phantom Parent") do |pspan|
141141
pspan.is_recording = false
142142

143143
pspan.context = OpenTelemetry::Propagation::TraceContext.new(span.context).extract(request.headers).not_nil!
@@ -169,6 +169,7 @@ unless_enabled?("OTEL_CRYSTAL_DISABLE_INSTRUMENTATION_HTTP_SERVER") do
169169
response.version = request.version
170170
response.headers["Connection"] = "keep-alive" if request.keep_alive?
171171
context = Context.new(request, response)
172+
puts ">> #{context.object_id.to_s(16)}"
172173

173174
if span
174175
span["http.host"] = request.hostname.to_s
@@ -191,19 +192,20 @@ unless_enabled?("OTEL_CRYSTAL_DISABLE_INSTRUMENTATION_HTTP_SERVER") do
191192
Log.with_context do
192193
@handler.call(context)
193194
rescue ex : ClientError
194-
handler_span.add_event("ClientError") do |event|
195-
event["message"] = ex.message.to_s
195+
handler_span.add_event("exception") do |event|
196+
event["exception.type"] = ex.class.name
197+
event["exception.message"] = ex.message.to_s
198+
event["exception.backtrace"] = ex.backtrace.join("\n")
196199
end
197200
Log.debug(exception: ex.cause) { ex.message }
198201
rescue ex
199202
Log.error(exception: ex) { "Unhandled exception on HTTP::Handler" }
200-
handler_span.add_event("Unhandled exception on HTTP::Handler") do |event|
201-
event["message"] = ex.message.to_s
203+
handler_span.add_event("exception") do |event|
204+
event["exception.type"] = ex.class.name
205+
event["exception.message"] = ex.message.to_s
206+
event["exception.backtrace"] = ex.backtrace.join("\n")
202207
end
203208
span.status.error!(ex.message.to_s)
204-
handler_span["exception.type"] = ex.class.name
205-
handler_span["exception.message"] = ex.message.to_s
206-
handler_span["exception.stacktrace"] = ex.backtrace.join("\n")
207209
unless response.closed?
208210
unless response.wrote_headers?
209211
span["http.status_code"] = HTTP::Status::INTERNAL_SERVER_ERROR.value if span

0 commit comments

Comments
 (0)