|
| 1 | +/** |
| 2 | + * Copyright 2019, OpenTelemetry Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import * as assert from 'assert'; |
| 18 | +import { NoopSpan } from '../../src/trace/NoopSpan'; |
| 19 | +import { CanonicalCode, TraceOptions } from '@opentelemetry/types'; |
| 20 | + |
| 21 | +describe('NoopSpan', () => { |
| 22 | + it('do not crash', () => { |
| 23 | + const spanContext = { |
| 24 | + traceId: 'd4cda95b652f4a1592b449d5929fda1b', |
| 25 | + spanId: '6e0c63257de34c92', |
| 26 | + traceOptions: TraceOptions.UNSAMPLED, |
| 27 | + }; |
| 28 | + |
| 29 | + const span = new NoopSpan(spanContext); |
| 30 | + span.setAttribute('my_string_attribute', 'foo'); |
| 31 | + span.setAttribute('my_number_attribute', 123); |
| 32 | + span.setAttribute('my_boolean_attribute', false); |
| 33 | + span.setAttribute('my_obj_attribute', { a: true }); |
| 34 | + span.setAttribute('my_sym_attribute', Symbol('a')); |
| 35 | + span.setAttributes({ |
| 36 | + my_string_attribute: 'foo', |
| 37 | + my_number_attribute: 123, |
| 38 | + }); |
| 39 | + |
| 40 | + span.addEvent('sent'); |
| 41 | + span.addEvent('sent', { id: '42', key: 'value' }); |
| 42 | + |
| 43 | + span.addLink({ |
| 44 | + traceId: 'd4cda95b652f4a1592b449d5929fda1b', |
| 45 | + spanId: '6e0c63257de34c92', |
| 46 | + }); |
| 47 | + span.addLink( |
| 48 | + { |
| 49 | + traceId: 'd4cda95b652f4a1592b449d5929fda1b', |
| 50 | + spanId: '6e0c63257de34c92', |
| 51 | + }, |
| 52 | + { id: '42', key: 'value' } |
| 53 | + ); |
| 54 | + |
| 55 | + span.setStatus({ code: CanonicalCode.CANCELLED }); |
| 56 | + |
| 57 | + span.updateName('my-span'); |
| 58 | + |
| 59 | + assert.ok(!span.isRecordingEvents()); |
| 60 | + assert.deepStrictEqual(span.context(), spanContext); |
| 61 | + span.end(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments