|
4 | 4 |
|
5 | 5 | require 'datadog/lambda' |
6 | 6 | require 'net/http' |
| 7 | +require_relative '../../lambdacontextversion' |
7 | 8 |
|
8 | 9 | describe Datadog::Utils do |
9 | 10 | let(:headers) do |
|
25 | 26 |
|
26 | 27 | describe '#send_start_invocation_request' do |
27 | 28 | context 'when extension is running' do |
| 29 | + ctx = LambdaContextVersion.new |
28 | 30 | before(:each) do |
29 | 31 | # Stub the extension_running? method to return true |
30 | 32 | allow(Datadog::Utils).to receive(:extension_running?).and_return(true) |
|
39 | 41 |
|
40 | 42 | it 'applies trace context from extension' do |
41 | 43 | # Stub POST request to return a trace context |
| 44 | + all_headers = Datadog::Utils.request_headers |
| 45 | + all_headers['lambda-runtime-aws-request-id'] = ctx.aws_request_id |
42 | 46 | expect(Net::HTTP).to receive(:post) |
43 | | - .with(Datadog::Utils::START_INVOCATION_URI, 'null', Datadog::Utils.request_headers) { headers } |
| 47 | + .with(Datadog::Utils::START_INVOCATION_URI, 'null', all_headers) { headers } |
44 | 48 |
|
45 | 49 | # Call the start request with an empty event |
46 | | - digest = Datadog::Utils.send_start_invocation_request(event: nil) |
| 50 | + digest = Datadog::Utils.send_start_invocation_request(event: nil, request_context: ctx) |
47 | 51 |
|
48 | 52 | expect(digest.trace_id.to_s).to eq('4110911582297405557') |
49 | 53 | expect(digest.span_id.to_s).to eq('797643193680388254') |
|
52 | 56 |
|
53 | 57 | it 'skips applying trace context when headers are not present' do |
54 | 58 | # Stub POST request to return a trace context |
| 59 | + all_headers = Datadog::Utils.request_headers |
| 60 | + all_headers['lambda-runtime-aws-request-id'] = ctx.aws_request_id |
55 | 61 | expect(Net::HTTP).to receive(:post) |
56 | | - .with(Datadog::Utils::START_INVOCATION_URI, 'null', Datadog::Utils.request_headers) { {} } |
| 62 | + .with(Datadog::Utils::START_INVOCATION_URI, 'null', all_headers) { {} } |
57 | 63 |
|
58 | 64 | # Call the start request with an empty event |
59 | | - Datadog::Utils.send_start_invocation_request(event: nil) |
| 65 | + Datadog::Utils.send_start_invocation_request(event: nil, request_context: ctx) |
60 | 66 |
|
61 | 67 | digest = Datadog::Tracing.active_trace.to_digest |
62 | 68 |
|
|
66 | 72 | end |
67 | 73 |
|
68 | 74 | context 'when extension is not running' do |
| 75 | + ctx = LambdaContextVersion.new |
69 | 76 | it 'does nothing' do |
70 | | - result = Datadog::Utils.send_start_invocation_request(event: nil) |
| 77 | + result = Datadog::Utils.send_start_invocation_request(event: nil, request_context: ctx) |
71 | 78 | expect(result).to eq(nil) |
72 | 79 | end |
73 | 80 | end |
74 | 81 | end |
75 | 82 |
|
76 | 83 | describe '#send_end_invocation_request' do |
77 | 84 | context 'when extension is running' do |
| 85 | + ctx = LambdaContextVersion.new |
78 | 86 | before(:each) do |
79 | 87 | # Stub the extension_running? method to return true |
80 | 88 | allow(Datadog::Utils).to receive(:extension_running?).and_return(true) |
|
92 | 100 | allow(Net::HTTP).to receive(:post) { nil } |
93 | 101 |
|
94 | 102 | # Call the start request with an empty event |
95 | | - Datadog::Utils.send_end_invocation_request(response: nil, span_id: nil) |
| 103 | + Datadog::Utils.send_end_invocation_request(response: nil, span_id: nil, request_context: ctx) |
96 | 104 | end |
97 | 105 | end |
98 | 106 |
|
99 | 107 | context 'when extension is not running' do |
| 108 | + ctx = LambdaContextVersion.new |
100 | 109 | it 'does nothing' do |
101 | | - result = Datadog::Utils.send_end_invocation_request(response: nil, span_id: nil) |
| 110 | + result = Datadog::Utils.send_end_invocation_request(response: nil, span_id: nil, request_context: ctx) |
102 | 111 | expect(result).to eq(nil) |
103 | 112 | end |
104 | 113 | end |
|
0 commit comments