Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/traces/backend/open_telemetry/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module OpenTelemetry
TRACER = ::OpenTelemetry.tracer_provider.tracer(Traces::Backend::OpenTelemetry.name, Traces::Backend::OpenTelemetry::VERSION)

module Interface
def trace(name, attributes: nil, &block)
def trace(name, resource: nil, attributes: nil, &block)
Copy link
Author

@mjq mjq May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently ignoring the value of resource as, as far as I can tell, there isn't an equivalent in OpenTelemetry's span data model for it like there is in DataDog's.

Merging e.g. {"resource" => resource} into the attributes hash would be another option.

TRACER.in_span(name, attributes: attributes&.transform_keys(&:to_s), &block)
end

Expand Down
10 changes: 10 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_resource(argument)
Traces.trace("my_method_with_resource", resource: "my_resource") {}
end

def my_method_with_exception
Traces.trace("my_method_with_exception") {raise "Error"}
Expand Down Expand Up @@ -56,6 +60,12 @@ def my_span_and_context

instance.my_method_without_attributes(10)
end

it "can invoke trace wrapper with a resource" do
expect(Traces::Backend::OpenTelemetry::TRACER).to receive(:start_span)

instance.my_method_with_resource(10)
end

it "can invoke trace wrapper with exception" do
expect(Traces::Backend::OpenTelemetry::TRACER).to receive(:start_span)
Expand Down