2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
import { Resource } from '@opentelemetry/resources' ;
5
- import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' ;
5
+ import { SEMRESATTRS_SERVICE_NAME , SEMRESATTRS_SERVICE_VERSION } from '@opentelemetry/semantic-conventions' ;
6
6
import { expect } from 'chai' ;
7
7
import Sinon from 'sinon' ;
8
8
import sinon from 'sinon' ;
@@ -57,11 +57,12 @@ describe('service name fallback', () => {
57
57
} ) ;
58
58
} ) ;
59
59
60
- it ( 'sets a service name based on package.json attributes' , async ( ) => {
60
+ it ( 'sets a service name and version based on package.json attributes' , async ( ) => {
61
61
givenAValidPackageJsonFile ( ) ;
62
62
const result = serviceNameFallback . detect ( ) ;
63
63
const attributes = await waitForAsyncDetection ( result ) ;
64
- expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/[email protected] ' ) ;
64
+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/app-under-test' ) ;
65
+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_VERSION , '2.13.47' ) ;
65
66
} ) ;
66
67
67
68
it ( 'does not set a service name if DASH0_AUTOMATIC_SERVICE_NAME is false' , async ( ) => {
@@ -85,7 +86,8 @@ describe('service name fallback', () => {
85
86
process . env . OTEL_SERVICE_NAME = ' ' ;
86
87
const result = serviceNameFallback . detect ( ) ;
87
88
const attributes = await waitForAsyncDetection ( result ) ;
88
- expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/[email protected] ' ) ;
89
+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/app-under-test' ) ;
90
+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_VERSION , '2.13.47' ) ;
89
91
} ) ;
90
92
91
93
it ( 'does not set a service name if OTEL_RESOURCE_ATTRIBUTES has the service.name key' , async ( ) => {
@@ -101,7 +103,8 @@ describe('service name fallback', () => {
101
103
process . env . OTEL_RESOURCE_ATTRIBUTES = 'key1=value,key2=value' ;
102
104
const result = serviceNameFallback . detect ( ) ;
103
105
const attributes = await waitForAsyncDetection ( result ) ;
104
- expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/[email protected] ' ) ;
106
+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_NAME , '@example/app-under-test' ) ;
107
+ expect ( attributes ) . to . have . property ( SEMRESATTRS_SERVICE_VERSION , '2.13.47' ) ;
105
108
} ) ;
106
109
107
110
it ( 'does not set a service name if no package.json can be found' , async ( ) => {
0 commit comments