14
14
* limitations under the License.
15
15
*/
16
16
17
+ import * as assert from 'assert' ;
17
18
import { RAW_ENVIRONMENT } from '@opentelemetry/core' ;
18
19
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' ;
19
20
import { envDetector , Resource } from '../../../src' ;
@@ -27,7 +28,7 @@ describeBrowser('envDetector() on web browser', () => {
27
28
describe ( 'with valid env' , ( ) => {
28
29
before ( ( ) => {
29
30
( globalThis as typeof globalThis & RAW_ENVIRONMENT ) . OTEL_RESOURCE_ATTRIBUTES =
30
- 'webengine.name="chromium",webengine.version="99",webengine.description="Chromium"' ;
31
+ 'webengine.name="chromium",webengine.version="99",webengine.description="Chromium",custom.key="custom%20value" ' ;
31
32
} ) ;
32
33
33
34
after ( ( ) => {
@@ -41,6 +42,38 @@ describeBrowser('envDetector() on web browser', () => {
41
42
[ SemanticResourceAttributes . WEBENGINE_VERSION ] : '99' ,
42
43
[ SemanticResourceAttributes . WEBENGINE_DESCRIPTION ] : 'Chromium' ,
43
44
} ) ;
45
+ assert . strictEqual ( resource . attributes [ 'custom.key' ] , 'custom value' ) ;
46
+ } ) ;
47
+ } ) ;
48
+
49
+
50
+ describe ( 'with invalid env' , ( ) => {
51
+ const values = [
52
+ 'webengine.description="with spaces"' ,
53
+ ] ;
54
+
55
+ for ( const value of values ) {
56
+ describe ( `value: '${ value } '` , ( ) => {
57
+ before ( ( ) => {
58
+ ( globalThis as typeof globalThis & RAW_ENVIRONMENT ) . OTEL_RESOURCE_ATTRIBUTES = value ;
59
+ } ) ;
60
+
61
+ after ( ( ) => {
62
+ delete ( globalThis as typeof globalThis & RAW_ENVIRONMENT ) . OTEL_RESOURCE_ATTRIBUTES ;
63
+ } ) ;
64
+
65
+ it ( 'should return empty resource' , async ( ) => {
66
+ const resource : Resource = await envDetector . detect ( ) ;
67
+ assertEmptyResource ( resource ) ;
68
+ } ) ;
69
+ } ) ;
70
+ }
71
+ } ) ;
72
+
73
+ describe ( 'with empty env' , ( ) => {
74
+ it ( 'should return empty resource' , async ( ) => {
75
+ const resource : Resource = await envDetector . detect ( ) ;
76
+ assertEmptyResource ( resource ) ;
44
77
} ) ;
45
78
} ) ;
46
79
0 commit comments