Skip to content

Commit

Permalink
Fixes OpenTelemetry::Traces -> OpenTelemetry::Trace.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 11, 2025
1 parent d6af750 commit fd4adff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/traces/backend/open_telemetry/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def trace(name, attributes: nil, &block)
end
rescue Exception => error
span&.record_exception(error)
span&.status = ::OpenTelemetry::Traces::Status.error("Unhandled exception of type: #{error.class}")
span&.status = ::OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{error.class}")
raise
ensure
span&.finish
end
end

def trace_context=(context)
span_context = ::OpenTelemetry::Traces::SpanContext.new(
span_context = ::OpenTelemetry::Trace::SpanContext.new(
trace_id: context.trace_id,
span_id: context.parent_id,
trace_flags: ::OpenTelemetry::Traces::TracesFlags.from_byte(context.flags),
trace_flags: ::OpenTelemetry::Trace::TraceFlags.from_byte(context.flags),
tracestate: context.state,
remote: context.remote?
)
Expand Down
14 changes: 14 additions & 0 deletions test/traces/backend/open_telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def my_method(argument)
def my_method_without_attributes(arguments)
Traces.trace("my_method_without_attributes") {}
end

def my_method_with_exception
Traces.trace("my_method_with_exception") {raise "Error"}
end
end

describe Traces::Backend::OpenTelemetry do
Expand All @@ -42,4 +46,14 @@ def my_method_without_attributes(arguments)

instance.my_method_without_attributes(10)
end

it "can invoke trace wrapper with exception" do
instance = MyClass.new

expect(Traces::Backend::OpenTelemetry::TRACER).to receive(:start_span)

expect do
instance.my_method_with_exception
end.to raise_exception(RuntimeError, message: be == "Error")
end
end

0 comments on commit fd4adff

Please sign in to comment.