|
1 | 1 | import { makeSession } from '@sentry/core'; |
2 | | -import type { Breadcrumb } from '@sentry/types'; |
3 | 2 |
|
4 | 3 | import { OpenTelemetryScope } from '../../src/custom/scope'; |
5 | | -import { InternalSentrySemanticAttributes } from '../../src/semanticAttributes'; |
6 | | -import { setSpanParent } from '../../src/utils/spanData'; |
7 | | -import { createSpan } from '../helpers/createSpan'; |
8 | | -import * as GetActiveSpan from './../../src/utils/getActiveSpan'; |
9 | 4 |
|
10 | 5 | describe('NodeExperimentalScope', () => { |
11 | 6 | afterEach(() => { |
@@ -93,130 +88,4 @@ describe('NodeExperimentalScope', () => { |
93 | 88 |
|
94 | 89 | expect(scope['_span']).toBeUndefined(); |
95 | 90 | }); |
96 | | - |
97 | | - describe('_getBreadcrumbs', () => { |
98 | | - it('gets from scope if no span is found', () => { |
99 | | - jest.spyOn(GetActiveSpan, 'getActiveSpan').mockReturnValue(undefined); |
100 | | - |
101 | | - const scope = new OpenTelemetryScope(); |
102 | | - const breadcrumbs: Breadcrumb[] = [ |
103 | | - { message: 'test1', timestamp: 1234 }, |
104 | | - { message: 'test2', timestamp: 12345 }, |
105 | | - { message: 'test3', timestamp: 12346 }, |
106 | | - ]; |
107 | | - scope['_breadcrumbs'] = breadcrumbs; |
108 | | - |
109 | | - expect(scope['_getBreadcrumbs']()).toEqual(breadcrumbs); |
110 | | - }); |
111 | | - |
112 | | - it('gets events from active span if found', () => { |
113 | | - const span = createSpan(); |
114 | | - jest.spyOn(GetActiveSpan, 'getActiveSpan').mockReturnValue(span); |
115 | | - |
116 | | - const scope = new OpenTelemetryScope(); |
117 | | - |
118 | | - const now = Date.now(); |
119 | | - |
120 | | - span.addEvent('basic event', now); |
121 | | - span.addEvent('breadcrumb event', {}, now + 1000); |
122 | | - span.addEvent( |
123 | | - 'breadcrumb event 2', |
124 | | - { |
125 | | - [InternalSentrySemanticAttributes.BREADCRUMB_DATA]: JSON.stringify({ nested: { indeed: true } }), |
126 | | - [InternalSentrySemanticAttributes.BREADCRUMB_TYPE]: 'test-type', |
127 | | - [InternalSentrySemanticAttributes.BREADCRUMB_LEVEL]: 'info', |
128 | | - [InternalSentrySemanticAttributes.BREADCRUMB_EVENT_ID]: 'test-event-id', |
129 | | - [InternalSentrySemanticAttributes.BREADCRUMB_CATEGORY]: 'test-category', |
130 | | - }, |
131 | | - now + 3000, |
132 | | - ); |
133 | | - span.addEvent( |
134 | | - 'breadcrumb event invalid JSON data', |
135 | | - { |
136 | | - [InternalSentrySemanticAttributes.BREADCRUMB_DATA]: 'this is not JSON...', |
137 | | - }, |
138 | | - now + 2000, |
139 | | - ); |
140 | | - |
141 | | - expect(scope['_getBreadcrumbs']()).toEqual([ |
142 | | - { message: 'basic event', timestamp: now / 1000 }, |
143 | | - { message: 'breadcrumb event', timestamp: now / 1000 + 1 }, |
144 | | - { |
145 | | - message: 'breadcrumb event 2', |
146 | | - timestamp: now / 1000 + 3, |
147 | | - data: { nested: { indeed: true } }, |
148 | | - level: 'info', |
149 | | - event_id: 'test-event-id', |
150 | | - category: 'test-category', |
151 | | - type: 'test-type', |
152 | | - }, |
153 | | - { message: 'breadcrumb event invalid JSON data', timestamp: now / 1000 + 2 }, |
154 | | - ]); |
155 | | - }); |
156 | | - |
157 | | - it('gets events from spans up the parent chain if found', () => { |
158 | | - const span = createSpan(); |
159 | | - const parentSpan = createSpan(); |
160 | | - const rootSpan = createSpan(); |
161 | | - jest.spyOn(GetActiveSpan, 'getActiveSpan').mockReturnValue(span); |
162 | | - |
163 | | - setSpanParent(span, parentSpan); |
164 | | - setSpanParent(parentSpan, rootSpan); |
165 | | - |
166 | | - const scope = new OpenTelemetryScope(); |
167 | | - |
168 | | - const now = Date.now(); |
169 | | - |
170 | | - span.addEvent('basic event', now); |
171 | | - parentSpan.addEvent('parent breadcrumb event', {}, now + 1000); |
172 | | - span.addEvent( |
173 | | - 'breadcrumb event 2', |
174 | | - { |
175 | | - [InternalSentrySemanticAttributes.BREADCRUMB_DATA]: JSON.stringify({ nested: true }), |
176 | | - }, |
177 | | - now + 3000, |
178 | | - ); |
179 | | - rootSpan.addEvent( |
180 | | - 'breadcrumb event invalid JSON data', |
181 | | - { |
182 | | - [InternalSentrySemanticAttributes.BREADCRUMB_DATA]: 'this is not JSON...', |
183 | | - }, |
184 | | - now + 2000, |
185 | | - ); |
186 | | - |
187 | | - expect(scope['_getBreadcrumbs']()).toEqual([ |
188 | | - { message: 'basic event', timestamp: now / 1000 }, |
189 | | - { message: 'breadcrumb event 2', timestamp: now / 1000 + 3, data: { nested: true } }, |
190 | | - { message: 'parent breadcrumb event', timestamp: now / 1000 + 1 }, |
191 | | - { message: 'breadcrumb event invalid JSON data', timestamp: now / 1000 + 2 }, |
192 | | - ]); |
193 | | - }); |
194 | | - |
195 | | - it('combines scope & span breadcrumbs if both exist', () => { |
196 | | - const span = createSpan(); |
197 | | - jest.spyOn(GetActiveSpan, 'getActiveSpan').mockReturnValue(span); |
198 | | - |
199 | | - const scope = new OpenTelemetryScope(); |
200 | | - |
201 | | - const breadcrumbs: Breadcrumb[] = [ |
202 | | - { message: 'test1', timestamp: 1234 }, |
203 | | - { message: 'test2', timestamp: 12345 }, |
204 | | - { message: 'test3', timestamp: 12346 }, |
205 | | - ]; |
206 | | - scope['_breadcrumbs'] = breadcrumbs; |
207 | | - |
208 | | - const now = Date.now(); |
209 | | - |
210 | | - span.addEvent('basic event', now); |
211 | | - span.addEvent('breadcrumb event', {}, now + 1000); |
212 | | - |
213 | | - expect(scope['_getBreadcrumbs']()).toEqual([ |
214 | | - { message: 'test1', timestamp: 1234 }, |
215 | | - { message: 'test2', timestamp: 12345 }, |
216 | | - { message: 'test3', timestamp: 12346 }, |
217 | | - { message: 'basic event', timestamp: now / 1000 }, |
218 | | - { message: 'breadcrumb event', timestamp: now / 1000 + 1 }, |
219 | | - ]); |
220 | | - }); |
221 | | - }); |
222 | 91 | }); |
0 commit comments