|
117 | 117 | expect(set.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION))
|
118 | 118 | .to eq('cache')
|
119 | 119 | end
|
| 120 | + |
| 121 | + context 'when cache_key.enabled is false' do |
| 122 | + before do |
| 123 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 124 | + end |
| 125 | + |
| 126 | + it do |
| 127 | + expect(read).to eq(50) |
| 128 | + |
| 129 | + expect(spans).to have(2).items |
| 130 | + get, = spans |
| 131 | + expect(get.name).to eq('rails.cache') |
| 132 | + expect(get.get_tag('rails.cache.key')).to be_nil |
| 133 | + end |
| 134 | + end |
120 | 135 | end
|
121 | 136 |
|
122 | 137 | describe '#read_multi' do
|
|
149 | 164 | .to eq('cache')
|
150 | 165 | end
|
151 | 166 | end
|
| 167 | + |
| 168 | + context 'when cache_key.enabled is false' do |
| 169 | + before do |
| 170 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 171 | + end |
| 172 | + |
| 173 | + it do |
| 174 | + expect(read_multi).to eq(Hash[multi_keys.zip([51, 52, 53])]) |
| 175 | + expect(spans).to have(1 + multi_keys.size).items |
| 176 | + get = spans[0] |
| 177 | + expect(get.name).to eq('rails.cache') |
| 178 | + expect(get.get_tag('rails.cache.keys')).to be_nil |
| 179 | + end |
| 180 | + end |
152 | 181 | end
|
153 | 182 |
|
154 | 183 | describe '#write' do
|
|
191 | 220 | expect(span.get_tag('rails.cache.key')).to eq('custom-key/x/y/User:3')
|
192 | 221 | end
|
193 | 222 | end
|
| 223 | + |
| 224 | + context 'when cache_key.enabled is false' do |
| 225 | + before do |
| 226 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 227 | + end |
| 228 | + |
| 229 | + let(:key) { ['custom-key', %w[x y], user] } |
| 230 | + let(:user) { double('User', cache_key: 'User:3') } |
| 231 | + |
| 232 | + it 'does not expand key using ActiveSupport when cache_key.enabled false' do |
| 233 | + write |
| 234 | + expect(span.get_tag('rails.cache.key')).to be_nil |
| 235 | + end |
| 236 | + end |
194 | 237 | end
|
195 | 238 |
|
196 | 239 | describe '#write_multi' do
|
|
240 | 283 | expect(span.get_tag('rails.cache.keys')).to eq('["custom-key/x/y/User:3"]')
|
241 | 284 | end
|
242 | 285 | end
|
| 286 | + |
| 287 | + context 'when cache_key.enabled is false' do |
| 288 | + before do |
| 289 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 290 | + end |
| 291 | + |
| 292 | + it do |
| 293 | + write_multi |
| 294 | + expect(span.name).to eq('rails.cache') |
| 295 | + expect(span.type).to eq('cache') |
| 296 | + expect(span.resource).to eq('MSET') |
| 297 | + expect(span.service).to eq('rails-cache') |
| 298 | + expect(span.get_tag('rails.cache.backend')).to eq('file_store') |
| 299 | + expect(span.get_tag('rails.cache.keys')).to be_nil |
| 300 | + |
| 301 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) |
| 302 | + .to eq('active_support') |
| 303 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) |
| 304 | + .to eq('cache') |
| 305 | + end |
| 306 | + end |
243 | 307 | end
|
244 | 308 |
|
245 | 309 | context 'when the method is not defined' do
|
|
278 | 342 | expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION))
|
279 | 343 | .to eq('cache')
|
280 | 344 | end
|
| 345 | + |
| 346 | + context 'when cache_key.enabled is false' do |
| 347 | + before do |
| 348 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 349 | + end |
| 350 | + |
| 351 | + it do |
| 352 | + delete |
| 353 | + expect(span.name).to eq('rails.cache') |
| 354 | + expect(span.type).to eq('cache') |
| 355 | + expect(span.resource).to eq('DELETE') |
| 356 | + expect(span.service).to eq('rails-cache') |
| 357 | + expect(span.get_tag('rails.cache.backend')).to eq('file_store') |
| 358 | + expect(span.get_tag('rails.cache.key')).to be_nil |
| 359 | + |
| 360 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) |
| 361 | + .to eq('active_support') |
| 362 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) |
| 363 | + .to eq('cache') |
| 364 | + end |
| 365 | + end |
281 | 366 | end
|
282 | 367 |
|
283 | 368 | describe '#fetch' do
|
|
306 | 391 | .to eq('cache')
|
307 | 392 | end
|
308 | 393 | end
|
| 394 | + |
| 395 | + context 'when cache_key.enabled is false' do |
| 396 | + before do |
| 397 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 398 | + end |
| 399 | + |
| 400 | + subject(:fetch) { cache.fetch('exception') { raise 'oops' } } |
| 401 | + |
| 402 | + it do |
| 403 | + expect { fetch }.to raise_error(StandardError) |
| 404 | + |
| 405 | + expect(span.name).to eq('rails.cache') |
| 406 | + expect(span.type).to eq('cache') |
| 407 | + expect(span.resource).to eq('GET') |
| 408 | + expect(span.service).to eq('rails-cache') |
| 409 | + expect(span.get_tag('rails.cache.backend')).to eq('file_store') |
| 410 | + expect(span.get_tag('rails.cache.key')).to be_nil |
| 411 | + expect(span.get_tag('error.type')).to eq('RuntimeError') |
| 412 | + expect(span.get_tag('error.message')).to eq('oops') |
| 413 | + |
| 414 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) |
| 415 | + .to eq('active_support') |
| 416 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) |
| 417 | + .to eq('cache') |
| 418 | + end |
| 419 | + end |
309 | 420 | end
|
310 | 421 |
|
311 | 422 | describe '#fetch_multi' do
|
|
340 | 451 | .to eq('cache')
|
341 | 452 | end
|
342 | 453 | end
|
| 454 | + |
| 455 | + context 'with exception and when cache_key.enabled is false' do |
| 456 | + before do |
| 457 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 458 | + end |
| 459 | + subject(:fetch_multi) { cache.fetch_multi('exception', 'another', 'one') { raise 'oops' } } |
| 460 | + |
| 461 | + it do |
| 462 | + expect { fetch_multi }.to raise_error(StandardError) |
| 463 | + expect(span.name).to eq('rails.cache') |
| 464 | + expect(span.type).to eq('cache') |
| 465 | + expect(span.resource).to eq('MGET') |
| 466 | + expect(span.service).to eq('rails-cache') |
| 467 | + expect(span.get_tag('rails.cache.backend')).to eq('file_store') |
| 468 | + expect(span.get_tag('rails.cache.keys')).to be_nil |
| 469 | + expect(span.get_tag('error.type')).to eq('RuntimeError') |
| 470 | + expect(span.get_tag('error.message')).to eq('oops') |
| 471 | + |
| 472 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) |
| 473 | + .to eq('active_support') |
| 474 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) |
| 475 | + .to eq('cache') |
| 476 | + end |
| 477 | + end |
343 | 478 | end
|
344 | 479 |
|
345 | 480 | context 'when the method is not defined' do
|
|
378 | 513 | .to eq('cache')
|
379 | 514 | end
|
380 | 515 | end
|
| 516 | + |
| 517 | + context 'with very large cache key and when cache_key.enabled is false' do |
| 518 | + before do |
| 519 | + Datadog.configuration.tracing[:active_support][:cache_key].enabled = false |
| 520 | + end |
| 521 | + it 'truncates key too large' do |
| 522 | + max_key_size = Datadog::Tracing::Contrib::ActiveSupport::Ext::QUANTIZE_CACHE_MAX_KEY_SIZE |
| 523 | + large_key = ''.ljust(max_key_size * 2, SecureRandom.hex) |
| 524 | + cache.write(large_key, 'foobar') |
| 525 | + |
| 526 | + expect(large_key.size).to be > max_key_size |
| 527 | + expect(span.name).to eq('rails.cache') |
| 528 | + expect(span.get_tag('rails.cache.key')).to be_nil |
| 529 | + |
| 530 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)) |
| 531 | + .to eq('active_support') |
| 532 | + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) |
| 533 | + .to eq('cache') |
| 534 | + end |
| 535 | + end |
381 | 536 | end
|
0 commit comments