Skip to content

Commit

Permalink
Run tests against Ruby. The default extraction is failing, but the de…
Browse files Browse the repository at this point in the history
…fault inject is successful.
  • Loading branch information
zacharycmontoya committed Jan 24, 2025
1 parent ca1e4e8 commit 5704c0d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions manifests/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ tests/:
Test_AWS_API_Gateway_Inferred_Span_Creation: missing_feature
test_otel_drop_in.py:
Test_Otel_Drop_In: missing_feature
Test_Otel_Drop_In_Default_Propagator:
'*': irrelevant (endpoint not implemented)
rails70: v2.0.0
k8s_lib_injection/:
test_k8s_lib_injection_profiling.py:
TestK8sLibInjectioProfilingClusterEnabled: missing_feature
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/test_otel_drop_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def setup_propagation_extract(self):
}
self.r = weblog.get("/otel_drop_in_default_propagator_extract", headers=extract_headers)

@incomplete_test_app(library="ruby", reason="Ruby extract seems to fail even though it should be supported")
def test_propagation_extract(self):
content = json.loads(self.r.text)

Expand Down
4 changes: 4 additions & 0 deletions utils/build/docker/ruby/rails70/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ gem "jbuilder"
# Talk with Kafka for propagation tests
gem "ruby-kafka"

# Use the OpenTelemetry API and SDK
gem "opentelemetry-api"
gem "opentelemetry-sdk"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

Expand Down
18 changes: 16 additions & 2 deletions utils/build/docker/ruby/rails70/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ GEM
racc (~> 1.4)
nokogiri (1.13.1-x86_64-linux)
racc (~> 1.4)
opentelemetry-api (1.4.0)
opentelemetry-common (0.21.0)
opentelemetry-api (~> 1.0)
opentelemetry-registry (0.3.1)
opentelemetry-api (~> 1.1)
opentelemetry-sdk (1.6.0)
opentelemetry-api (~> 1.1)
opentelemetry-common (~> 0.20)
opentelemetry-registry (~> 0.2)
opentelemetry-semantic_conventions
opentelemetry-semantic_conventions (1.10.1)
opentelemetry-api (~> 1.0)
orm_adapter (0.5.0)
pry (0.14.1)
coderay (~> 1.1)
Expand Down Expand Up @@ -257,11 +269,11 @@ GEM
zeitwerk (2.5.4)

PLATFORMS
aarch64-linux-gnu
aarch64-linux
arm64-darwin
ruby
x86_64-darwin
x86_64-linux-gnu
x86_64-linux

DEPENDENCIES
bootsnap
Expand All @@ -271,6 +283,8 @@ DEPENDENCIES
devise
importmap-rails
jbuilder
opentelemetry-api
opentelemetry-sdk
pry
puma (~> 5.0)
rails (~> 7.0.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'datadog/kit/appsec/events'
require 'kafka'
require 'opentelemetry'

class SystemTestController < ApplicationController
skip_before_action :verify_authenticity_token
Expand Down Expand Up @@ -250,4 +251,34 @@ def return_headers
end
render json: JSON.generate(request_headers), content_type: 'application/json'
end

def otel_drop_in_default_propagator_extract
# The extract operation succeeds with a custom OpenTelemetry propagator, but not with the default one.
# To see this, uncomment the next line, and use that propagator to do the context extraction
# propagator = OpenTelemetry::Context::Propagation::CompositeTextMapPropagator.compose_propagators([OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator, OpenTelemetry::Baggage::Propagation.text_map_propagator])
context = OpenTelemetry.propagation.extract(request.headers)

span_context = OpenTelemetry::Trace.current_span(context).context

baggage = OpenTelemetry::Baggage.raw_entries()
baggage_str = ""
baggage.each_pair do |key, value|
baggage_str << value << ','
end
baggage_str.chop!

result = {}
result["trace_id"] = span_context.hex_trace_id.from(16).to_i(16)
result["span_id"] = span_context.hex_span_id.to_i(16)
result["tracestate"] = span_context.tracestate.to_s
result["baggage"] = baggage_str

render json: JSON.generate(result), content_type: 'application/json'
end

def otel_drop_in_default_propagator_inject
headers = {}
OpenTelemetry.propagation.inject(headers)
render json: JSON.generate(headers), content_type: 'application/json'
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require 'opentelemetry/sdk'
require 'datadog/opentelemetry'

Datadog.configure do |c|
c.diagnostics.debug = true
end

::OpenTelemetry::SDK.configure do |_c|
end

# Send non-web init event

if defined?(Datadog::Tracing)
Expand Down
3 changes: 3 additions & 0 deletions utils/build/docker/ruby/rails70/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
get '/requestdownstream' => 'system_test#request_downstream'
get '/returnheaders' => 'system_test#return_headers'

get '/otel_drop_in_default_propagator_extract' => 'system_test#otel_drop_in_default_propagator_extract'
get '/otel_drop_in_default_propagator_inject' => 'system_test#otel_drop_in_default_propagator_inject'

get '/debugger/init' => 'debugger#init'
get '/debugger/pii' => 'debugger#pii'
get '/debugger/log' => 'debugger#log_probe'
Expand Down

0 comments on commit 5704c0d

Please sign in to comment.