|
1 | | -import type { Event, EventEnvelope, EventItem, SeverityLevel } from '@sentry/core'; |
| 1 | +import type { |
| 2 | + Event, |
| 3 | + EventEnvelope, |
| 4 | + EventItem, |
| 5 | + LogEnvelope, |
| 6 | + LogSeverityLevel, |
| 7 | + MetricEnvelope, |
| 8 | + MetricType, |
| 9 | + SeverityLevel, |
| 10 | +} from '@sentry/core'; |
2 | 11 | import { createEnvelope, debug } from '@sentry/core'; |
3 | 12 | import * as RN from 'react-native'; |
4 | 13 | import type { Spec } from '../src/js/NativeRNSentry'; |
@@ -391,7 +400,7 @@ describe('Tests Native Wrapper', () => { |
391 | 400 | base64StringFromByteArray( |
392 | 401 | utf8ToBytes( |
393 | 402 | '{"event_id":"event0","sent_at":"123"}\n' + |
394 | | - '{"type":"event","content_type":"application/vnd.sentry.items.log+json","length":87}\n' + |
| 403 | + '{"type":"event","content_type":"application/json","length":87}\n' + |
395 | 404 | '{"event_id":"event0","message":"test","sdk":{"name":"test-sdk-name","version":"2.1.3"}}\n', |
396 | 405 | ), |
397 | 406 | ), |
@@ -423,7 +432,7 @@ describe('Tests Native Wrapper', () => { |
423 | 432 | base64StringFromByteArray( |
424 | 433 | utf8ToBytes( |
425 | 434 | '{"event_id":"event0","sent_at":"123"}\n' + |
426 | | - '{"type":"event","content_type":"application/vnd.sentry.items.log+json","length":93}\n' + |
| 435 | + '{"type":"event","content_type":"application/json","length":93}\n' + |
427 | 436 | '{"event_id":"event0","sdk":{"name":"test-sdk-name","version":"2.1.3"},"instance":{"value":0}}\n', |
428 | 437 | ), |
429 | 438 | ), |
@@ -466,7 +475,7 @@ describe('Tests Native Wrapper', () => { |
466 | 475 | base64StringFromByteArray( |
467 | 476 | utf8ToBytes( |
468 | 477 | '{"event_id":"event0","sent_at":"123"}\n' + |
469 | | - '{"type":"event","content_type":"application/vnd.sentry.items.log+json","length":50}\n' + |
| 478 | + '{"type":"event","content_type":"application/json","length":50}\n' + |
470 | 479 | '{"event_id":"event0","message":{"message":"test"}}\n', |
471 | 480 | ), |
472 | 481 | ), |
@@ -505,7 +514,7 @@ describe('Tests Native Wrapper', () => { |
505 | 514 | base64StringFromByteArray( |
506 | 515 | utf8ToBytes( |
507 | 516 | '{"event_id":"event0","sent_at":"123"}\n' + |
508 | | - '{"type":"event","content_type":"application/vnd.sentry.items.log+json","length":124}\n' + |
| 517 | + '{"type":"event","content_type":"application/json","length":124}\n' + |
509 | 518 | '{"event_id":"event0","exception":{"values":[{"mechanism":{"handled":true,"type":""}}]},"breadcrumbs":[{"message":"crumb!"}]}\n', |
510 | 519 | ), |
511 | 520 | ), |
@@ -534,7 +543,7 @@ describe('Tests Native Wrapper', () => { |
534 | 543 | base64StringFromByteArray( |
535 | 544 | utf8ToBytes( |
536 | 545 | '{"event_id":"event0","sent_at":"123"}\n' + |
537 | | - '{"type":"event","content_type":"application/vnd.sentry.items.log+json","length":58}\n' + |
| 546 | + '{"type":"event","content_type":"application/json","length":58}\n' + |
538 | 547 | '{"event_id":"event0","breadcrumbs":[{"message":"crumb!"}]}\n', |
539 | 548 | ), |
540 | 549 | ), |
@@ -573,13 +582,120 @@ describe('Tests Native Wrapper', () => { |
573 | 582 | base64StringFromByteArray( |
574 | 583 | utf8ToBytes( |
575 | 584 | '{"event_id":"event0","sent_at":"123"}\n' + |
576 | | - '{"type":"event","content_type":"application/vnd.sentry.items.log+json","length":132}\n' + |
| 585 | + '{"type":"event","content_type":"application/json","length":132}\n' + |
577 | 586 | '{"event_id":"event0","exception":{"values":[{"mechanism":{"handled":false,"type":"onerror"}}]},"breadcrumbs":[{"message":"crumb!"}]}\n', |
578 | 587 | ), |
579 | 588 | ), |
580 | 589 | { hardCrashed: true }, |
581 | 590 | ); |
582 | 591 | }); |
| 592 | + |
| 593 | + test('preserves content_type for logs (application/vnd.sentry.items.log+json)', async () => { |
| 594 | + const logPayload = { |
| 595 | + timestamp: 1234567890, |
| 596 | + level: 'info' as LogSeverityLevel, |
| 597 | + body: 'test log message', |
| 598 | + logger: 'test-logger', |
| 599 | + }; |
| 600 | + |
| 601 | + const env = createEnvelope<LogEnvelope>({ event_id: 'log0', sent_at: '123' }, [ |
| 602 | + [ |
| 603 | + { |
| 604 | + type: 'log', |
| 605 | + content_type: 'application/vnd.sentry.items.log+json', |
| 606 | + item_count: 1, |
| 607 | + }, |
| 608 | + { items: [logPayload] }, |
| 609 | + ], |
| 610 | + ]); |
| 611 | + |
| 612 | + await NATIVE.sendEnvelope(env); |
| 613 | + |
| 614 | + const expectedPayload = JSON.stringify({ items: [logPayload] }); |
| 615 | + const expectedLength = utf8ToBytes(expectedPayload).length; |
| 616 | + |
| 617 | + expect(RNSentry.captureEnvelope).toHaveBeenCalledWith( |
| 618 | + base64StringFromByteArray( |
| 619 | + utf8ToBytes( |
| 620 | + '{"event_id":"log0","sent_at":"123"}\n' + |
| 621 | + `{"type":"log","content_type":"application/vnd.sentry.items.log+json","item_count":1,"length":${expectedLength}}\n` + |
| 622 | + `${expectedPayload}\n`, |
| 623 | + ), |
| 624 | + ), |
| 625 | + { hardCrashed: false }, |
| 626 | + ); |
| 627 | + }); |
| 628 | + |
| 629 | + test('preserves content_type for metrics (application/vnd.sentry.items.trace-metric+json)', async () => { |
| 630 | + const metricsPayload = { |
| 631 | + timestamp: 1234567890, |
| 632 | + trace_id: 'trace_id', |
| 633 | + name: 'metric.name', |
| 634 | + type: 'counter' as MetricType, |
| 635 | + value: 42, |
| 636 | + measurements: { |
| 637 | + 'metric.name': { value: 42 }, |
| 638 | + }, |
| 639 | + }; |
| 640 | + |
| 641 | + const env = createEnvelope<MetricEnvelope>({ event_id: 'metric0', sent_at: '123' }, [ |
| 642 | + [ |
| 643 | + { |
| 644 | + type: 'trace_metric', |
| 645 | + content_type: 'application/vnd.sentry.items.trace-metric+json', |
| 646 | + item_count: 1, |
| 647 | + }, |
| 648 | + { items: [metricsPayload] }, |
| 649 | + ], |
| 650 | + ]); |
| 651 | + |
| 652 | + await NATIVE.sendEnvelope(env); |
| 653 | + |
| 654 | + const expectedPayload = JSON.stringify({ items: [metricsPayload] }); |
| 655 | + const expectedLength = utf8ToBytes(expectedPayload).length; |
| 656 | + |
| 657 | + expect(RNSentry.captureEnvelope).toHaveBeenCalledWith( |
| 658 | + base64StringFromByteArray( |
| 659 | + utf8ToBytes( |
| 660 | + '{"event_id":"metric0","sent_at":"123"}\n' + |
| 661 | + `{"type":"trace_metric","content_type":"application/vnd.sentry.items.trace-metric+json","item_count":1,"length":${expectedLength}}\n` + |
| 662 | + `${expectedPayload}\n`, |
| 663 | + ), |
| 664 | + ), |
| 665 | + { hardCrashed: false }, |
| 666 | + ); |
| 667 | + }); |
| 668 | + |
| 669 | + test('preserves custom content_type when provided', async () => { |
| 670 | + const payload = { |
| 671 | + event_id: 'event0', |
| 672 | + message: 'test', |
| 673 | + }; |
| 674 | + const env = createEnvelope({ event_id: 'foo1', sent_at: '123' }, [ |
| 675 | + [ |
| 676 | + { |
| 677 | + type: 'event', |
| 678 | + content_type: 'application/custom-type', |
| 679 | + }, |
| 680 | + payload, |
| 681 | + ], |
| 682 | + ]); |
| 683 | + |
| 684 | + await NATIVE.sendEnvelope(env); |
| 685 | + |
| 686 | + const expectedPayload = JSON.stringify(payload); |
| 687 | + const expectedLength = utf8ToBytes(expectedPayload).length; |
| 688 | + expect(RNSentry.captureEnvelope).toHaveBeenCalledWith( |
| 689 | + base64StringFromByteArray( |
| 690 | + utf8ToBytes( |
| 691 | + '{"event_id":"foo1","sent_at":"123"}\n' + |
| 692 | + `{"type":"event","content_type":"application/custom-type","length":${expectedLength}}\n` + |
| 693 | + `${expectedPayload}\n`, |
| 694 | + ), |
| 695 | + ), |
| 696 | + { hardCrashed: false }, |
| 697 | + ); |
| 698 | + }); |
583 | 699 | }); |
584 | 700 |
|
585 | 701 | describe('fetchRelease', () => { |
|
0 commit comments